This happens when ActiveRecord is not defined so it's matchers are not required but ActiveSupport::TestCase is defined and tries to include them
I think this is referred to by this https://github.com/thoughtbot/shoulda-matchers/issues/408#issuecomment-40191487 too
:+1: to this, pointing at master to get the Rails 4.1 compatibility fix breaks this for me too as my project only uses ActiveModel, not ActiveRecord.
Sorry, this is my fault. There's not great testing around this right now. I'll get this fixed shortly.
@mcmire cool, no worries! let me know if I can help test
@eirc I just released 2.6.1.rc1, can you update your Gemfile and see if this bug is still present?
Upgrading to 2.6.1.rc1 works for me!
Yeah, works like a charm. Thanks!
if anyone else comes across this. I used to just do:
require "shoulda/matchers/integrations/rspec"
in spec_helper.rb. After upgrading to 2.6.1.rc1 and rc2 I still get this error. The fix was :
require "shoulda/matchers"
require "shoulda/matchers/integrations/rspec"
@subelsky Thank you very much! It helped me!
@Loremaster oh cool! glad to help
@subelsky Can you make an example Rails app / setup that reproduces this for me? I haven't run into this personally since 2.6.1. (Alternatively, have you tried upgrading to 2.6.1?)
I had the same issue uninitialized constant Shoulda while running on circle CI. My problem was the Gemfile. I had the shoulda gem in the development environment on my local machine and test on circle and so the shoulda-matchers gem was not loading in cirlcle ci. If you run in to this, make sure you have the gem in the right environment.
group :test do
gem 'factory_bot_rails', '~> 4.0'
gem 'shoulda-matchers', '~> 3.1' # make sure it's in the right environment, test? development?
gem 'faker'
gem 'database_cleaner'
gem 'rubocop-rspec'
gem 'rspec_junit_formatter'
end
Most helpful comment
I had the same issue
uninitialized constant Shouldawhile running on circle CI. My problem was theGemfile. I had the shoulda gem in the development environment on my local machine and test on circle and so theshoulda-matchersgem was not loading in cirlcle ci. If you run in to this, make sure you have the gem in the right environment.