Skip to content

Commit 4d65bea

Browse files
committed
Rails removed unshift for view_paths, use their copy constructor instead
1 parent 0717183 commit 4d65bea

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lib/rspec/rails/example/view_example_group.rb

+20-8
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,26 @@ def view
8282
_view
8383
end
8484

85-
# Simulates the presence of a template on the file system by adding a
86-
# Rails' FixtureResolver to the front of the view_paths list. Designed to
87-
# help isolate view examples from partials rendered by the view template
88-
# that is the subject of the example.
89-
#
90-
# stub_template("widgets/_widget.html.erb" => "This content.")
91-
def stub_template(hash)
92-
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
85+
if ::Rails.version.to_f >= 7.1
86+
# Simulates the presence of a template on the file system by adding a
87+
# Rails' FixtureResolver to the front of the view_paths list. Designed to
88+
# help isolate view examples from partials rendered by the view template
89+
# that is the subject of the example.
90+
#
91+
# stub_template("widgets/_widget.html.erb" => "This content.")
92+
def stub_template(hash)
93+
view.view_paths.send(:initialize_copy, ActionView::PathSet.new([StubResolverCache.resolver_for(hash)] + view.view_paths.paths))
94+
end
95+
else
96+
# Simulates the presence of a template on the file system by adding a
97+
# Rails' FixtureResolver to the front of the view_paths list. Designed to
98+
# help isolate view examples from partials rendered by the view template
99+
# that is the subject of the example.
100+
#
101+
# stub_template("widgets/_widget.html.erb" => "This content.")
102+
def stub_template(hash)
103+
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
104+
end
93105
end
94106

95107
# Provides access to the params hash that will be available within the

spec/rspec/rails/example/view_example_group_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def _view; end
283283
Class.new do
284284
include ViewExampleGroup::ExampleMethods
285285
def _view
286-
@_view ||= Struct.new(:view_paths).new(['some-path'])
286+
@_view ||= Struct.new(:view_paths).new(ActionView::PathSet.new(['some-path']))
287287
end
288288
end
289289
end

0 commit comments

Comments
 (0)