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 24, 2019
1 parent a769a4d commit 82241e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 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 @@ -39,6 +39,12 @@ def self.proxy_method_warning_if_called_in_before_context_scope(method_name)
end
end

if ::Rails.version.to_f >= 6.1
def name
@example
end
end

fixtures RSpec.configuration.global_fixtures if RSpec.configuration.global_fixtures
end
end
Expand Down
8 changes: 6 additions & 2 deletions spec/rspec/rails/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ def in_inferring_type_from_location_environment

it "metadata `type: :request` sets up request example groups" do
a_rails_app = double("Rails application")
the_rails_module = Module.new
the_rails_module = Module.new {
def self.version; end;
}
allow(the_rails_module).to receive(:application) { a_rails_app }
version = ::Rails::VERSION
stub_const "Rails", the_rails_module
Expand Down Expand Up @@ -230,7 +232,9 @@ def in_inferring_type_from_location_environment

it "metadata `type: :feature` sets up feature example groups" do
a_rails_app = double("Rails application")
the_rails_module = Module.new
the_rails_module = Module.new {
def self.version; end;
}
allow(the_rails_module).to receive(:application) { a_rails_app }
version = ::Rails::VERSION
stub_const "Rails", the_rails_module
Expand Down
11 changes: 11 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,16 @@ module RSpec::Rails
expect(group).to respond_to(:fixture_path=)
end
end

it "will allow #setup_fixture to run successfully", if: Rails.version.to_f > 6.0 do

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

self.use_transactional_tests = false
end

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

0 comments on commit 82241e9

Please sign in to comment.