From 7a494fc707db46019da2c6db8395b08788c9aee9 Mon Sep 17 00:00:00 2001 From: atolix <82761106+atolix@users.noreply.github.com> Date: Fri, 10 May 2024 01:20:33 +0900 Subject: [PATCH] add example 'when Rails::VERSION::MAJOR < 7' --- spec/controllers/controller_spec.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spec/controllers/controller_spec.rb b/spec/controllers/controller_spec.rb index 4465186a..44d3dd16 100644 --- a/spec/controllers/controller_spec.rb +++ b/spec/controllers/controller_spec.rb @@ -201,10 +201,18 @@ allow_any_instance_of(ActionController::TestRequest).to receive(:referer).and_return('http://test.host/referer_action') end - it 'uses Rails 7 redirect_back_or_to method' do - get :test_return_to + context 'when Rails::VERSION::MAJOR >= 7', skip: Rails::VERSION::MAJOR < 7 do + it 'uses Rails 7 redirect_back_or_to method' do + get :test_return_to + + expect(response).to redirect_to('http://test.host/referer_action') + end + end - expect(response).to redirect_to('http://test.host/referer_action') + context 'when Rails::VERSION::MAJOR < 7', skip: Rails::VERSION::MAJOR >= 7 do + it 'raise NoMethodError' do + expect { get :test_return_to }.to raise_error(NoMethodError) + end end end