我正在尝试在 rspec 中测试我的 sinatra 应用程序(更具体地说,padrino 应用程序)主页上的重定向。我找到了 redirect_to
,但它似乎只在 rspec-rails 中。你如何在 sinatra 中测试它?
所以基本上,我想要这样的东西:
it "Homepage should redirect to locations#index" do
get "/"
last_response.should be_redirect # This works, but I want it to be more specific
# last_response.should redirect_to('/locations') # Only works for rspec-rails
end
最佳答案
试试这个(未测试):
it "Homepage should redirect to locations#index" do
get "/"
last_response.should be_redirect # This works, but I want it to be more specific
follow_redirect!
last_request.url.should == 'http://example.org/locations'
end
关于ruby - 如何使用 rspec 在 sinatra 中测试重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7424443/