New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uninitialized constant ActiveSupport::TestCase #763
Comments
This seems odd to me... is there anything special about your setup? It shouldn't be looking for ActiveSupport::TestCase, but it shouldn't be failing to find it, either... |
This is a pretty boilerplate rails app. Was making it for a tutorial I'm doing at a beginners meetup. I since deleted the project and just required Might not be worth keeping open? I can try to replicate and send you a repository if you think it is actionable, though. 😖 |
@mcmire I have done some research on this and put together a sample repository. So this is the exact setup I have in each situation:
Specific to these tests. The tests can be found in # list_spec.rb
describe List do
it { is_expected.to validate_presence_of :name }
it { is_expected.to have_many :tasks }
end
# task_spec.rb
describe Task do
it { is_expected.to validate_presence_of :description }
it { is_expected.to belong_to :list }
end In this repository I have 2 commits. One with shoulda Here the specific, full trace is:
Commit With Working Current Version of Gem and running specs goes fine:
The source is is pointing to in ...
def integrate_with(test_framework)
Shoulda::Matchers.assertion_exception_class =
ActiveSupport::TestCase::Assertion
SUB_LIBRARIES.each do |name|
library = Integrations.find_library!(name)
library.integrate_with(test_framework)
end
end
... Let me know if there is anything I can do. |
You shouldn't be requiring shoulda-matchers in your spec_helper. The gem relies on Rails to have been loaded. That hasn't happened yet when spec_helper is loaded. You need to require and configure the gem in rails_helper instead. |
Ah, got it. Thanks. 👍 |
I'm using shoulda-matchers outside of Rails, in a standalone ActiveRecord environment. I need to configure the test environment before loading my application code. Here's what worked for me:
|
Yup! shoulda-matchers makes the assumption you've already required ActiveRecord. It doesn't make that require on its own anymore. That would be a good error message to have. |
Thanks @betesh! I'm using shoulda-matchers outside of rails as well, using only ActiveModel. Based on your feedback, I have this which worked: require "shoulda/matchers"
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
# This require statement solves the uninitialized constant / NameError issue
require "active_model"
with.library :active_model
end
end @mcmire Is this the recommended way? |
@serixscorpio Yup, that would work. You could put the require at the top so it doesn't get lost, but that's just a suggestion. (Also, FYI, you don't need to explicitly require shoulda-matchers anymore.) |
I'm running with shoulda-matchers 3.1.1 and also getting this reference. require 'spec_helper'
require 'shoulda/matchers'
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
with.library :rails
end
end I am getting
which comes from code: def integrate_with(test_framework)
Shoulda::Matchers.assertion_exception_class =
ActiveSupport::TestCase::Assertion
SUB_LIBRARIES.each do |name|
library = Integrations.find_library!(name)
library.integrate_with(test_framework)
end
end I'm running Rails 4.2.5 and apparently I don't have this part of active support loaded. Not sure why, except that I generated the app using rspec and not test:unit. Any idea on what I can do to resolve this dependency, or why I need it in the first place? My gemfile has gem 'minitest'
gem 'shoulda-matchers', '~> 3.1' Thanks! |
@dchersey I'm getting the exact same thing. |
I went back to 3.1.1 and added require: false to my gemfile and it resolved My gemfile now has: gem "shoulda", require: false This gives me
|
When configuring shoulda-matchers in a small project I have, I have been unable to get things running at all. I am pointing to
3.0.0.rc1
.This is my configuration:
It is a typical rails project, and this is included in
spec/rails_helper.rb
.When guard runs (or if I run manually its identical) my specs I get:
(broke the lines and shortened path for readability)
I know its a release candidate but couldn't find another issue. For reference, I am on rails 4.2.3 and rspec 3.3.2. I can gladly provide any other information you would want or need.
The text was updated successfully, but these errors were encountered: