I’m trying to test that requesting the root path (/) routes to my beta controller’s :new action. When I do this manually (in my browser), it works fine. But my automated test is failing with No route matches "/".
In config/routes.rb I have
MyRailsApp::Application.routes.draw do
root to: 'beta#new' # Previously: `redirect('/beta/join')`
end
In my spec/routing/root_route_spec.rb I have tried
require 'spec_helper'
describe "the root route" do
it "should route to beta signups" do
get('/').should route_to(controller: :beta, action: :new)
end
end
and have also tried
require 'spec_helper'
describe "the root route" do
it "should route to beta signups" do
assert_routing({ method: :get, path: '/' }, { controller: :beta, action: :new })
end
end
but both complain that No route matches "/"
1) the root route should route to the beta signups
Failure/Error: get('/').should route_to "beta#new"
No route matches "/"
# ./spec/routing/root_route_spec.rb:5:in `block (2 levels) in <top (required)>'
When I go, in my browser, to localhost:3000, I’m correctly routed to the BetaController::new action.
What explains the No route matches "/" error?
I’m using Rails 3.1.3 and RSpec-2.10.
Thanks!
You should test that
/redirects to/beta/joinand then as a separate issue test that/beta/joinroutes to the:newaction of the:betacontroller.Redirection is tested in
requests, notrouting.and