From 740fc85bcef2f1e1471e45c69645c543e0495401 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 16 Nov 2023 13:41:12 +0100 Subject: [PATCH] RSpec redirect: Allow specifying a location through a block --- spec/support/controllers.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/support/controllers.rb b/spec/support/controllers.rb index 6688a4b7..6101e91c 100644 --- a/spec/support/controllers.rb +++ b/spec/support/controllers.rb @@ -37,8 +37,12 @@ def expect_json expect_content_type('application/json') end -def expect_redirect(path = nil) - if path +def expect_redirect(path = nil, &) + 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 expect(controller).to redirect_to(path) end