Skip to content

Commit

Permalink
Rails removed unshift for view_paths, use their copy constructor instead
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Jun 28, 2023
1 parent b3f4ed5 commit 4ec3765
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions lib/rspec/rails/example/view_example_group.rb
Expand Up @@ -82,14 +82,26 @@ def view
_view
end

# Simulates the presence of a template on the file system by adding a
# Rails' FixtureResolver to the front of the view_paths list. Designed to
# help isolate view examples from partials rendered by the view template
# that is the subject of the example.
#
# stub_template("widgets/_widget.html.erb" => "This content.")
def stub_template(hash)
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
if ::Rails.version.to_f >= 7.1
# Simulates the presence of a template on the file system by adding a
# Rails' FixtureResolver to the front of the view_paths list. Designed to
# help isolate view examples from partials rendered by the view template
# that is the subject of the example.
#
# stub_template("widgets/_widget.html.erb" => "This content.")
def stub_template(hash)
view.view_paths.send(:initialize_copy, ActionView::PathSet.new([StubResolverCache.resolver_for(hash)] + view.view_paths.paths))
end
else
# Simulates the presence of a template on the file system by adding a
# Rails' FixtureResolver to the front of the view_paths list. Designed to
# help isolate view examples from partials rendered by the view template
# that is the subject of the example.
#
# stub_template("widgets/_widget.html.erb" => "This content.")
def stub_template(hash)
view.view_paths.unshift(StubResolverCache.resolver_for(hash))
end
end

# Provides access to the params hash that will be available within the
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/rails/example/view_example_group_spec.rb
Expand Up @@ -283,7 +283,7 @@ def _view; end
Class.new do
include ViewExampleGroup::ExampleMethods
def _view
@_view ||= Struct.new(:view_paths).new(['some-path'])
@_view ||= Struct.new(:view_paths).new(ActionView::PathSet.new(['some-path']))
end
end
end
Expand Down

0 comments on commit 4ec3765

Please sign in to comment.