zlo*_*log 15 ruby rspec sinatra padrino
我试图在我的sinatra应用程序(更具体地说,一个padrino应用程序)的主页上测试重定向,在rspec中.我发现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
Run Code Online (Sandbox Code Playgroud)
小智 22
试试这个(未经测试):
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
Run Code Online (Sandbox Code Playgroud)
小智 15
更直接地,您可以使用last_response.location.
it "Homepage should redirect to locations#index" do
get "/"
last_response.should be_redirect
last_response.location.should include '/locations'
end
Run Code Online (Sandbox Code Playgroud)