失敗,這個問題可能已經問了十幾次上堆棧溢出(例如,(1),(2),(3),(4),(5)),但得到的答覆似乎是不同的,他們都沒有幫助我。我正在研究Rails引擎,我發現Rspec2獲取路由錯誤,但我可以在瀏覽器中訪問路由。這裏的情況:路線每次工作在瀏覽器中,在Rspec的
在發動機的
routes.rb
:resources :mw_interactives, :controller => 'mw_interactives', :constraints => { :id => /\d+/ }, :except => :show # This is so we can build the InteractiveItem at the same time as the Interactive resources :pages, :controller => 'interactive_pages', :constraints => { :id => /\d+/ }, :only => [:show] do resources :mw_interactives, :controller => 'mw_interactives', :constraints => { :id => /\d+/ }, :except => :show end
的
rake routes
摘自輸出:new_mw_interactive GET /mw_interactives/new(.:format) lightweight/mw_interactives#new {:id=>/\d+/} ... new_page_mw_interactive GET /pages/:page_id/mw_interactives/new(.:format) lightweight/mw_interactives#new {:id=>/\d+/, :page_id=>/\d+/}
而且我的測試,從控制器的規格之一(
describe Lightweight::MwInteractivesController do
) :it 'shows a form for a new interactive' do get :new end
...它得到這樣的結果:
Failure/Error: get :new
ActionController::RoutingError:
No route matches {:controller=>"lightweight/mw_interactives", :action=>"new"}
......可是當我去這條道路在瀏覽器中,它的工作原理完全按預期。
缺少什麼我在這裏?
ETA:要澄清一點安德烈亞斯提出:這是一個Rails引擎,在一個虛擬的應用程序,其中包括髮動機的命名空間中的路由,使rspec的運行:
mount Lightweight::Engine => "/lightweight"
...在如此顯示的路線rake routes
以/lightweight/
開頭。這就是爲什麼Rspec錯誤中顯示的路線似乎不符合rake routes
中的路線。但它確實使調試變得更加容易。
ETA2:回答賴恩·克拉克的評論,這是我測試的操作:
module Lightweight
class MwInteractivesController < ApplicationController
def new
create
end
...,就是這樣。
這是控制器規格嗎? – zetetic
@zetetic:是的。我想我應該這麼說 - 我現在要編輯添加。 – pjmorse
你能在控制器中顯示你的新定義嗎? –