Testing routes with subdomain restrictions using rspec

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

In particular, I have a route

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

and (among other things) a test

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

If I remove the subdomain restriction that this test passes, but with it it fails. I have to tell rspec to use a subdomain, but I don’t understand how

TIA

Andy

+8
ruby ruby-on-rails rspec rspec-rails
source share
1 answer

I usually do:

 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 
+25
source share

All Articles