加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 如何使用rspec测试sinatra中的重定向?

发布时间:2020-12-16 20:37:25 所属栏目:百科 来源:网络整理
导读:我正在尝试在我的sinatra应用程序的主页(更具体地说,一个padrino应用程序),在rspec中测试重定向.我发现redirect_to,但它似乎只在rspec-rails.你如何在sinatra中测试它? 所以基本上,我会喜欢这样的: it "Homepage should redirect to locations#index" do g
我正在尝试在我的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

解决方法

尝试这个(未测试):
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读