2012-03-11 85 views
2

我在Rails 3.2上使用Capybara/Cucumber,並且我面臨一個奇怪的路由錯誤。水豚/黃瓜:命名空間中嵌套資源的RoutingError

我有以下途徑定義:

#routes.rb 
    namespace :super_user do 
    ... 
    resources :events do 
     resources :invites 
    end 
    end 
    ... 
    resources :invites 

和下面的黃瓜功能:

@in_progress @current 
Scenario: I can invite a USER by email 
    Given the following event exists: 
    | Name   | 
    | The Event  | 
    And I go to the event page for "The Event" 
    And I follow "Invite new user" 
    And I fill in "invite_email" with "[email protected]" 
    ... 

活動頁面(EventsController#show)包含一個鏈接到invites#new行動:

#app/views/super_user/events/show.html.erb 
... 
<%= content_for :button_bar do %> 
    <%= link_to('Invite new user', new_super_user_event_invite_path(@event)) %> 
<% end %> 

一切工作正常,當我測試手動/super_user/events/1行爲,但每當我跑黃瓜,我得到:

And I follow "Invite new user" # features/step_definitions/web_steps.rb:45 
    uninitialized constant SuperUser::InvitesController (ActionController::RoutingError) 
    (eval):2:in `click_link' 
    ./features/step_definitions/web_steps.rb:46:in `/^(?:|I)follow "([^"]*)"$/' 
    features/create_casino_super_user.feature:24:in `And I follow "Invite new user"' 

爲什麼路由不同的表現用黃瓜/水豚是什麼時候?我怎樣才能解決這個功能?

bundle list相關部分:

* cucumber (1.0.6) 
* cucumber-rails (1.0.2) 
* capybara (1.0.1) 
* capybara-webkit (0.6.1 dfa0624) 
* rails (3.2.1) 

編輯

邊注:該InvitesController類不是超級用戶模塊中,但正如我以前說過它手動測試時的作品。

回答

1

我來自Rails 3(不是3.2),來自2.3,只是跳到新的路由DSL。我遇到了一個非常類似的問題,那就是我們的名稱空間資源路徑直接命中而不是從Cucumber/Capybara內部運行。

最後,我把從Rails的2.3的缺省路由,使他們積極裏面只有黃瓜,這似乎工作:

# Cucumber doesn't understand the Rails 3 default route, above, so use the old way to make that work 
# TODO remove this when we can/must, and hope that Cucumber is smarter by then 
if File.basename($0) == "cucumber" 
    map.connect ':controller/:action/:id.:format' 
    map.connect ':controller/:action/:id' 
end 

不知道這是一個選擇(map.connect是老的一部分API,我認爲它在3.1中消失了),但是我想把它放在網絡上的某個地方供那些來看看。

+0

感謝您的回答(+1)。正如你所說'map.connect'現在已被棄用。我找到的唯一解決方案是創建一個基本控制器('InvitesControllerBase')並將其擴展到名稱空間的'SuperUser :: InvitesController'類中。 – Jef 2012-04-15 14:49:46