我正在尝试添加一个功能,以允许快速测试未经身份验证的用户的重定向。这是我到目前为止所拥有的:
def unauthenticated_redirects_to redirect_path #yeild
context "when not signed in" do
it "redirects to #{redirect_path}" do
yield
expect(response).to redirect_to redirect_path
end
end
end
describe SomeController do
describe 'GET #show' do
unauthenticated_redirects_to('/some_path') { get :show }
context "when signed in" do
# One thing...
# Another thing...
end
end
describe 'GET #whatever' do
unauthenticated_redirects_to('/some_other_path') { get :whatever }
end
end
但是,这不起作用,因为主describe
块的范围和上下文对于传递给unauthenticated_redirects_to
. 这合理地导致了错误:undefined method `get' for RSpec::Core::ExampleGroup::Nested_1::Nested_2:Class
.
有没有办法解决这个问题,或者有没有更清洁的方法来完成我应该考虑的类似事情?