diff --git a/lib/rspec/rails/example/view_example_group.rb b/lib/rspec/rails/example/view_example_group.rb index a03b19958..dcd34a6ac 100644 --- a/lib/rspec/rails/example/view_example_group.rb +++ b/lib/rspec/rails/example/view_example_group.rb @@ -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 diff --git a/spec/rspec/rails/example/view_example_group_spec.rb b/spec/rspec/rails/example/view_example_group_spec.rb index 7f6629c7c..9c89468cf 100644 --- a/spec/rspec/rails/example/view_example_group_spec.rb +++ b/spec/rspec/rails/example/view_example_group_spec.rb @@ -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