儘管能夠通過瀏覽器成功加載,但我仍然收到錯誤的測試控制器路由。 Rails4 + rspec。儘管路由器在瀏覽器中加載OK,但自定義Rails路由測試失敗
任何想法?
#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)>'
以下是通過耙路線相關的路線:
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
複製「耙路線」的輸出稱它爲 – arieljuod
添加的耙路輸出的要求 – aaandre
也許 :M調用控制器的動作
編輯2嘗試'get'/ public_sites/index''來查看路由中的site_name符號是否可以被「解析」爲測試範圍內的值 – Iralution