Skip to content

Commit 921e67d

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 921e67d

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
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 ::Rails.version.to_f >= 6.1
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/configuration_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ def in_inferring_type_from_location_environment
196196

197197
it "metadata `type: :request` sets up request example groups" do
198198
a_rails_app = double("Rails application")
199-
the_rails_module = Module.new
199+
the_rails_module = Module.new {
200+
def self.version; end;
201+
}
200202
allow(the_rails_module).to receive(:application) { a_rails_app }
201203
version = ::Rails::VERSION
202204
stub_const "Rails", the_rails_module
@@ -230,7 +232,9 @@ def in_inferring_type_from_location_environment
230232

231233
it "metadata `type: :feature` sets up feature example groups" do
232234
a_rails_app = double("Rails application")
233-
the_rails_module = Module.new
235+
the_rails_module = Module.new {
236+
def self.version; end;
237+
}
234238
allow(the_rails_module).to receive(:application) { a_rails_app }
235239
version = ::Rails::VERSION
236240
stub_const "Rails", the_rails_module

spec/rspec/rails/fixture_support_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,16 @@ module RSpec::Rails
1313
expect(group).to respond_to(:fixture_path=)
1414
end
1515
end
16+
17+
it "will allow #setup_fixture to run successfully", if: Rails.version.to_f > 6.0 do
18+
19+
group = RSpec::Core::ExampleGroup.describe do
20+
include FixtureSupport
21+
22+
self.use_transactional_tests = false
23+
end
24+
25+
expect { group.new.setup_fixtures }.to_not raise_error
26+
end
1627
end
1728
end

0 commit comments

Comments
 (0)