Shoulda-matchers: undefined method `validate_*' with 3.1.0

Created on 26 Jan 2016  路  2Comments  路  Source: thoughtbot/shoulda-matchers

Hi, I recently updated to rails 4.2.5.1 and shoulda-matchers to 3.1.0 (from 2.8.0). My tests which use:

  • validate_presence_of
  • validate_length_of

have started failing. I suspect failure is more general than just those two methods. Error log doesn't really say much:

Failure/Error: should validate_length_of(:username)

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

If you help you investigate this I can send PR. This issue doesn't exist on shoulda-matchers 2.8.0.
I have pushed an example app at here. Its model is:

#app/models/user.rb
class User < ActiveRecord::Base
    validates_length_of :username, minimum: 10
end

test (with rspec-rails 3.4.0):

#spec/models/user_spec.rb
require 'rails_helper'

describe User do
  it do
    should validate_length_of(:username)
  end
end

Most helpful comment

Thanks @mcmire :heart:

All 2 comments

shoulda-matchers no longer automatically mixes itself into your test framework -- you need to use a configuration block to manually tell the gem which test framework you're using. See the relevant part of the README for more.

Thanks @mcmire :heart:

Was this page helpful?
0 / 5 - 0 ratings