Skip to content

Commit 94c43d9

Browse files
committed
Restore respond_to? check for default_url_options
Reverts part of d52a135. Feature example groups usually have a `default_url_options` class attribute, but it's not added if the method is already defined: https://github.com/rails/rails/blob/v6.0.2.1/actionpack/lib/action_dispatch/routing/url_for.rb#L92 Request example groups have a `default_url_options` instance method: https://github.com/rails/rails/blob/v6.0.2.1/actionpack/lib/action_dispatch/testing/integration.rb#L388 This means that when a feature example group is defined inside a request example group, it will only have the instance method, and trying to call `default_url_options` on the example group will fail.
1 parent e69be80 commit 94c43d9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/rspec/rails/example/feature_example_group.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ module FeatureExampleGroup
1515
include app.routes.url_helpers if app.routes.respond_to?(:url_helpers)
1616
include app.routes.mounted_helpers if app.routes.respond_to?(:mounted_helpers)
1717

18-
default_url_options[:host] ||= ::RSpec::Rails::FeatureExampleGroup::DEFAULT_HOST
18+
if respond_to?(:default_url_options)
19+
default_url_options[:host] ||= ::RSpec::Rails::FeatureExampleGroup::DEFAULT_HOST
20+
end
1921
end
2022
end
2123

spec/rspec/rails/example/feature_example_group_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ module RSpec::Rails
1818
expect(group.new.foo_url).to eq("http://www.example.com/foo")
1919
end
2020

21+
context "when nested inside a request example group" do
22+
it "includes Rails route helpers" do
23+
Rails.application.routes.draw do
24+
get "/foo", :as => :foo, :to => "foo#bar"
25+
end
26+
27+
group = RSpec::Core::ExampleGroup.describe do
28+
include RequestExampleGroup
29+
end.describe do
30+
include FeatureExampleGroup
31+
end
32+
33+
expect(group.new.foo_path).to eq("/foo")
34+
expect(group.new.foo_url).to eq("http://www.example.com/foo")
35+
end
36+
end
37+
2138
describe "#visit" do
2239
it "raises an error informing about missing Capybara" do
2340
group = RSpec::Core::ExampleGroup.describe do

0 commit comments

Comments
 (0)