5
votes

With Rails 5 and RSpec 3.5, I'm getting the following error.

  1) User
     Failure/Error: it { should validate_uniqueness_of(:auth_token)}

     NoMethodError:
       undefined method `validate_uniqueness_of' for #<RSpec::ExampleGroups::User:0x007fab919f8cf
8>
     # ./spec/models/user_spec.rb:14:in `block (2 levels) in <top (required)>'

I've googled around for the right syntax but couldn't find the solution. Does anyone have an idea of what to use here? Thanks

2
I bet you don't have github.com/thoughtbot/shoulda-matchers gemfanta

2 Answers

4
votes

You have to add the gem to the Gemfile:

Gemfile

group :test do
  gem 'shoulda-matchers'
end

And include it:

spec/rails_helper.rb

RSpec.configure do |config|
  config.include(Shoulda::Matchers::ActiveModel, type: :model)
  config.include(Shoulda::Matchers::ActiveRecord, type: :model)
end
1
votes

I made it work by adding this:

Gemfile

group :test do
  gem 'shoulda-matchers'
end

rails_helper.rb

require 'shoulda/matchers'

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    with.test_framework :rspec
    with.library :rails
  end
end

.rspec

--color
--require spec_helper
--require rails_helper