Skip to content

Commit 8465725

Browse files
committed
Don't raise test helper setup error when inertia: true is set but the renderer is never called
1 parent 5c71d77 commit 8465725

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

lib/inertia_rails/rspec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def inertia_wrap_render(render)
4949
protected
5050

5151
def inertia_tests_setup?
52-
@_inertia_render_wrapper.present?
52+
::RSpec.current_example.metadata.fetch(:inertia, false)
5353
end
5454
end
5555
end

spec/dummy/app/controllers/inertia_test_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def inertia_partial_request_test
2323
end
2424
end
2525

26+
def non_inertiafied
27+
render plain: 'hey'
28+
end
29+
2630
# Calling it my_location to avoid this in Rails 5.0
2731
# https://github.com/rails/rails/issues/28033
2832
def my_location

spec/dummy/config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
get 'error_500' => 'inertia_test#error_500'
2525
get 'content_type_test' => 'inertia_test#content_type_test'
2626
get 'lazy_props' => 'inertia_render_test#lazy_props'
27+
get 'non_inertiafied' => 'inertia_test#non_inertiafied'
2728

2829
inertia 'inertia_route' => 'TestComponent'
2930
end

spec/inertia/rspec_helper_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,12 @@
5454
expect { expect_inertia }.to raise_error(/inertia: true/)
5555
end
5656
end
57+
58+
describe 'expecting inertia on a non inertia route', inertia: true do
59+
before { get non_inertiafied_path }
60+
61+
it 'does not complain about test helpers' do
62+
expect { expect_inertia }.not_to raise_error
63+
end
64+
end
5765
end

0 commit comments

Comments
 (0)