ruby-on-rails-3 - 出现错误:Shoulda::Matchers 未定义方法 `greater_than_or_equal_to'

标签 ruby-on-rails-3 unit-testing activerecord rspec2 shoulda

这是我试图通过的规范:

context "when validating format of attributes" do
    it { should validate_numericality_of(:price).greater_than_or_equal_to(0.01) }
end

我安装了 rspecshoulda-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/

相关文章:

mysql - 尝试部署 Rails 应用程序时获取 ActiveRecord::AdapterNotSpecified: 'old_production' 数据库未配置

ruby - 使用嵌入文档时的 ActiveRecord 嵌套验证 : Mongoid

ruby-on-rails - ActiveRecord,按嵌套属性的值查找

android - 如何使用 Koin 对 MVVM 进行单元测试?

scala - Akka:在集成测试中模拟组件的策略

java - 如何在 Spring Batch Junit 测试中模拟编写器?

mysql - ActiveRecord 格式的电话号码

ruby-on-rails-3 - Carrierwave + s3 + 雾 (Excon::Errors::SocketError)

ruby-on-rails - Ruby on Rails 中的 JSON 格式显示

ruby - 使用 Ruby On Rails 3 复制对象属性