Skip to content

Commit

Permalink
Fix WrongScopeError being thrown on Rails master:
Browse files Browse the repository at this point in the history
- ### Problem

  Rails made a change in rails/rails@d4367eb
  and TestFixtures don't make use of `method_name` anymore, but simply
  `name`.

  `name` on RSpec raises a `WrongScopeError` when called within an
  example.

  This patch overrides `name` to return the example name instead.
  • Loading branch information
Edouard-chin committed Dec 4, 2019
1 parent d0f81df commit 12b0e5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rspec/rails/fixture_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def self.proxy_method_warning_if_called_in_before_context_scope(method_name)
end
end

if ::ActiveRecord.version >= Gem::Version.new('6.1.0')
def name
@example
end
end

fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/rspec/rails/fixture_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@ module RSpec::Rails
expect(group).to respond_to(:fixture_path=)
end
end

it "doesn't raise a WrongScopeError on Rails 6.1" do
allow(ActiveRecord).to receive(:version) { Gem::Version.new('6.1.0') }

group = RSpec::Core::ExampleGroup.describe do
include FixtureSupport
end

expect { group.new.name }.to_not raise_error
end
end
end

0 comments on commit 12b0e5d

Please sign in to comment.