rails_example_group: don't include RSpec::Rails::FixtureSupport if it's not defined #1407
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If ActiveRecord::Fixtures isn't defined, then the line
include RSpec::Rails::FixtureSupport
inrspec/rails/example/rails_example_group
throws an error.I found this when I started to use the ammeter gem to help me write a spec for a generator.
The ammeter gem
requires 'rspec/rails/example/rails_example_group'
which has the lineinclude RSpec::Rails::FixtureSupport
.#1372 introduced a conditional around the definition for RSpec::Rails::FixtureSupport (in
rspec/rails/fixture_support.rb
) so that the class is not defined if ActiveRecord::TestFixtures isn't defined. So when theinclude RSpec::Rails::FixtureSupport
line inrspec/rails/example/rails_example_group
is evaluated, an error is thrown since RSpec::Rails::FixtureSupport was never defined. This include line needs a conditional to check for this situation. I tested this correction:include RSpec::Rails::FixtureSupport if RSpec::Rails::FixtureSupport rescue false
and it works.Here's the environment and generator spec test file that shows the error:
Ruby 2.1.5p273
Rails 4.2.1
rspec (3.3.0)
rspec-rails (3.3.2) [I also tested master; same error occurs, same fix works]
ammeter (1.1.2)
spec_helper.rb and rails_helper.rb have defaults. No modifications were made to the originally installed files.
Generator spec test file:
Stack trace with the error:
(I'm using RubyMine so a bit of that cruft is in the trace output.)