6

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

1

2 Answers 2

5

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
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.