使用 rspec 测试具有子域约束的​​路由 [英] testing routes with subdomain constraints using rspec

查看:47
本文介绍了使用 rspec 测试具有子域约束的​​路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用子域约束进行 rspec 路由测试时遇到问题.

I'm having trouble getting my rspec routing tests working with a subdomain constraint.

特别是我有一条路线

constraints :subdomain => "api" do
  resources :sign_ups, :only => [:create]
end

和(除其他外)测试

it "does allow creation of sign ups" do
  {:post => "/sign_ups"}.should route_to(
    :controller => "sign_ups",
    :action => "create",
  )
end

如果我删除子域约束,则此测试通过,但失败了.我必须告诉 rspec 使用子域,但我不知道如何

If I remove the subdomain constraint this test passes, but with it it fails. I have to tell rspec to use the subdomain but I'm at a loss as to how

TIA

安迪

推荐答案

我通常这样做:

let(:url)     { "http://api.domain.com"     }
let(:bad_url) { "http://bad_url.domain.com" }

it "does allow creation of sign ups" do
  {:post => "#{url}/sign_ups"}.should route_to(
   :controller => "sign_ups",
   :action => "create",
  )
end

it "should not route" do
  {:post => "#{bad_url}/sign_ups"}.should_not route_to(
   :controller => "sign_ups",
   :action => "create",
  )
end

这篇关于使用 rspec 测试具有子域约束的​​路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆