Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rails 3测试用例错误。on(:field)与错误[:field]_Ruby On Rails_Unit Testing_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails rails 3测试用例错误。on(:field)与错误[:field]

Ruby on rails rails 3测试用例错误。on(:field)与错误[:field],ruby-on-rails,unit-testing,ruby-on-rails-3,Ruby On Rails,Unit Testing,Ruby On Rails 3,我正在研究Rails 3个测试用例。在写这个案例的时候,我遇到了如下的弃用错误 DEPRECATION WARNING: Errors#on have been deprecated, use Errors#[] instead. Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array. An empty Array is returned when there ar

我正在研究Rails 3个测试用例。在写这个案例的时候,我遇到了如下的弃用错误

DEPRECATION WARNING: Errors#on have been deprecated, use Errors#[] instead.
Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array. An empty Array is returned when there are no errors on the specified attribute. (called from on at /usr/local/lib/ruby/gems/1.9.1/gems/activemodel-3.0.0.rc/lib/active_model/deprecated_error_methods.rb:7)
为此,我使用了errors[:field]而不是errors.on(:field) 现在,弃用错误消失了,但案例并不像以前那样有效。它没有测试模型的任何验证


索尔

在搜索了如何做到这一点的示例后,没有找到我最终要做的事情:

errors[:field].present? /  errors[:field].blank?

不知道这是否是首选方法,但似乎可以做到这一点。

我正在将我的旧规范转换为类似的内容,以删除弃用警告:

  model.should have(1).error_on(:field)
  model.should have(:no).errors_on(:field)

我现在使用的是这样的东西:

@hamburger.errors[:ingredients].count.should == 1
@hamburger.errors[:ingredients].should include "Tomatoes are missing dude!"
希望它能帮助别人,现在它是我最干净的解决方案。

替换:

errors.on(:field)
与:

问题是错误。在rails单元测试中的(:field)上显示弃用错误和错误[:field]工作不正常。。有没有办法解决这个问题。
errors.include?(:field)