这是我试图通过的规范:
context "when validating format of attributes" do
it { should validate_numericality_of(:price).greater_than_or_equal_to(0.01) }
end
我安装了 rspec
和 shoulda-matchers
。但我得到未定义的方法
greater_than_or_equal_to'`
现在该方法不在文档中,但它确实存在于此处:
https://github.com/moffff/shoulda-matchers/commit/7da06487d25c27d59d11fb7f2962e7ff345e45c4
那么为什么这不起作用呢?我应该怎么做才能让它发挥作用?
最佳答案
您的应用中的原始 thoughtbot/shoulda-matchers
中不存在该方法。您所指的版本是原始 gem 的一个分支。
您可以使用这个 gem 代替原来的 gem,只需在 Gemfile 中将其设置为源
gem 'shoulda-matchers', :git => 'https://github.com/moffff/shoulda-matchers.git'
但您应该明白, fork 和修改版本可能工作不稳定,不包含最新更新和修复等。
关于ruby-on-rails-3 - 出现错误:Shoulda::Matchers 未定义方法 `greater_than_or_equal_to',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14383054/