Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Prepend controller path to lookup_context prefixes #2749

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rspec/rails/example/view_example_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _include_controller_helpers

before do
_include_controller_helpers
view.lookup_context.prefixes << _controller_path
view.lookup_context.prefixes.prepend(_controller_path)

controller.controller_path = _controller_path

Expand Down
20 changes: 20 additions & 0 deletions spec/rspec/rails/example/view_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,26 @@ def _view; end # Stub method
expect(failure_reporter.exceptions).to eq []
expect(run_count).to eq 1
end

# Rails expects the first prefix to be the controller path.
# @see ActionView::AbstractRenderer::ObjectRendering#initialize
# Regression test for rspec/rspec-rails#2729
it 'injects controller path as first prefix' do
prefixes = []
RSpec.describe "a view spec" do
include ::RSpec::Rails::ViewExampleGroup

def _controller_path
"example/path"
end

specify do
prefixes = view.lookup_context.prefixes
end
end.run

expect(prefixes).to start_with("example/path")
end
end

describe "#template" do
Expand Down