我正在尝试测试请求根路径 ( /
) 路由到我的 beta 控制器的:new
操作。当我手动(在我的浏览器中)执行此操作时,它工作正常。但是我的自动化测试失败了No route matches "/"
。
在config/routes.rb
我有
MyRailsApp::Application.routes.draw do
root to: 'beta#new' # Previously: `redirect('/beta/join')`
end
在我spec/routing/root_route_spec.rb
尝试过
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
并且也尝试过
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
但两人都抱怨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)>'
当我在浏览器中转到 时localhost:3000
,我已正确路由到该BetaController::new
操作。
什么解释了No route matches "/"
错误?
我正在使用 Rails 3.1.3 和 RSpec-2.10。
谢谢!