【发布时间】:2014-06-19 00:44:45
【问题描述】:
我正在尝试做一个简单的验证,主要问题是 Rails 版本(我一直在使用 RSpec 和 Rails 4),因为我在 Rails 3.2 和 Ruby 1.9.3 中使用它。
这是我模型中的代码
expect(section).to have(1).errors_on(:name)
并返回此错误
1) Admin::Section is invalid without name
Failure/Error: expect(section).to have(1).errors_on(:name)
NoMethodError:
undefined method `have' for #<RSpec::ExampleGroups::AdminSection:0x007f81cf6e72d0>
我的宝石清单是这样的
* rspec-core (3.0.1)
* rspec-expectations (3.0.1)
* rspec-mocks (3.0.1)
* rspec-rails (3.0.1)
* rspec-support (3.0.0)
我可以通过 should be_valid 让它通过,但它已被弃用。
如果我使用 have_at_least,则错误出现在 errors_on
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 rspec ruby-on-rails-3.2