ruby - 如何使用 rspec 在 sinatra 中测试重定向?

标签 ruby rspec sinatra padrino

我正在尝试在 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/

相关文章:

ruby - gem 中的 Sinatra 应用程序

ruby - 动态生成代码

ruby-on-rails - ruby /rails : get elements from array where indices are divisible by x

ruby - x 大于、小于还是等于值 y?

ruby-on-rails - 使用 webkit 测试失败,使用 selenium 通过

ruby-on-rails - rspec spec 自动逻辑分组(按 "tags")

testing - Sinatra Rspec - 测试 View 是否已呈现

ruby-on-rails - 消除 Rails 3 中的弃用警告

testing - 学习小 cucumber 的推荐阅读

ruby - 测试 padrino post 方法被 csrf 停止