Skip to content

Commit a428956

Browse files
committed
Fix WrongScopeError being thrown on Rails master:
- ### 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.
1 parent c642aec commit a428956

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/rspec/rails/fixture_support.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ def self.proxy_method_warning_if_called_in_before_context_scope(method_name)
5050
end
5151
end
5252

53+
if ::ActiveRecord.version >= Gem::Version.new('6.1.0.alpha')
54+
def name
55+
@example
56+
end
57+
end
58+
5359
fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
5460
end
5561
end

spec/rspec/rails/fixture_support_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,13 @@ module RSpec::Rails
1313
expect(group).to respond_to(:fixture_path=)
1414
end
1515
end
16+
17+
it "doesn't raise a WrongScopeError", skip: ::ActiveRecord.version < Gem::Version.new('6.1.0.alpha') do
18+
group = RSpec::Core::ExampleGroup.describe do
19+
include FixtureSupport
20+
end
21+
22+
expect { group.new.name }.to_not raise_error
23+
end
1624
end
1725
end

0 commit comments

Comments
 (0)