Question

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?

Was it helpful?

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.

OTHER TIPS

It must be is_greater_than_or_equal_to (with a is_ prefix), not greater_than_or_equal_to.

See the docs: https://matchers.shoulda.io/docs/v4.1.2/Shoulda/Matchers/ActiveModel.html#validate_numericality_of-instance_method

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top