RSpec redirect: Allow specifying a location through a block

This commit is contained in:
Sebastian Serth
2023-11-16 13:41:12 +01:00
committed by Sebastian Serth
parent 7f30fbe221
commit 740fc85bce

View File

@ -37,8 +37,12 @@ def expect_json
expect_content_type('application/json') expect_content_type('application/json')
end end
def expect_redirect(path = nil) def expect_redirect(path = nil, &)
if path if block_given?
it 'performs a redirect to the location given' do
expect(controller).to redirect_to(instance_eval(&))
end
elsif path
it "redirects to #{path}" do it "redirects to #{path}" do
expect(controller).to redirect_to(path) expect(controller).to redirect_to(path)
end end