How do I spec rails3 routing constraints?
My Cucumber features pass whatever subdomain I pass in. Not sure where
or how to spec the subdomain. Any help would be appreciated.
I have something like the following:
#features/create_account.feature
Scenario:
Given I visit subdomain “www”
And I go to the new account page
#accounts_controller_spec.rb
describe AccountsController do
describe “GET new” do
before(:each) do
get :new
end
it "should render new.html.haml" do
response.should render_template(:new)
end
end
end
#routes.rb
constraints Promotional do
resource :account, :only => :new
end
#lib/promotional.rb
class Promotional
def self.matches?(request)
request.subdomain.empty? || request.subdomain == “www”
end
end
end
request.subdomain.empty? || request.subdomain == “www”
end
end
There was a commit to rails [1] that got in a day or two before the rc2
release that lets you pass a full URL to routing assertions. This means
you can do this in RSpec: