尽管能够通过浏览器成功加载控制器路由,但我在测试控制器路由时遇到错误。Rails4 + rspec。
有任何想法吗?
#controller spec
describe PublicSitesController do
describe "GET index" do
it "returns success" do
get :index #line 7 in the spec file
response.status.should == 200
end
end
end
#routes
get ":site_name/:page_name", to: "public_sites#show"
get ":site_name", to: 'public_sites#index'
get "/", to: 'public_sites#root'
#controller
class PublicSitesController < ApplicationController
def root
end
def index
end
def show
end
end
#the error:
Failures:
1) PublicSitesController GET index returns success
Failure/Error: get :index
ActionController::UrlGenerationError:
No route matches {:action=>"index", :controller=>"public_sites"}
# ./spec/controllers/public_sites_controller_spec.rb:7:in `block (3 levels) in <top (required)>'
以下是通过 rake 路线的相关路线:
GET /:site_name/:page_name(.:format) public_sites#show
POST /:site_name/:page_name(.:format) public_sites#receive_form
GET /:site_name(.:format) public_sites#index
GET / public_sites#root