【发布时间】:2015-12-12 13:37:16
【问题描述】:
看起来你曾经能够使用以下语法编写 RSpec 测试
it { should validate_presence_of :privacy }
但是我收到以下错误
error undefined method `validate_presence_of' for #<RSpec::ExampleGroups::Review:0x007fd819c1bdc8>
我可以通过以下方式编写测试,但上面的语法要简单得多
it "should require privacy" do
expect(FactoryGirl.build(:review, privacy: "")).to_not be_valid
end
是否有 1 行来测试使用 Rails 4.2 和 rspec-rails 3.0 的验证?我觉得我错过了什么......
【问题讨论】:
-
确保您的
Gemfile中有shouldagem。 -
您使用的是哪个版本的 shoulda-matchers?如果是 3.0,请检查 this post。他们在新版本中更改了一些内容。
标签: ruby-on-rails rspec