我无法让我的rspec路由测试使用子域约束。
具体来说,我有一条路线
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使用子域名,但我不知道如何
TIA
安迪
答案 0 :(得分:26)
我通常会这样做:
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