ruby-on-rails-3unit-testingactiverecordrspec2shoulda

Getting error: undefined method `greater_than_or_equal_to' for Shoulda::Matchers


Here is the spec I am trying to get to pass:

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

I have rspec and shoulda-matchers installed. But I am getting undefined methodgreater_than_or_equal_to'`

Now that method isn't in the documentation but it does exist here:

https://github.com/moffff/shoulda-matchers/commit/7da06487d25c27d59d11fb7f2962e7ff345e45c4

So why is this not working? What should I do to get it to work?


Solution

  • The method does not exists in original thoughtbot/shoulda-matchers that is in you app. The version you're referring is a fork of original gem.

    You can use this gem instead of original one, just set it source in Gemfile

    gem 'shoulda-matchers', :git => 'https://github.com/moffff/shoulda-matchers.git'
    

    But you should understand that forked and modified version can work unstable, does not include latest updates and fixes, and so on.