2014-12-02 189 views
-1

我還是比較新的rails。目前卡在這一步:Rails黃瓜場景

And I should see "THX-1138" 

以前令人驚訝的通過。然而,我被困在快樂之路的最後一步。下面是我的錯誤的描述:

Then I should be on the Similar Movies page for "Star Wars" # features/step_definitions/web_steps.rb:230 
And I should see "THX-1138" # features/Search_movie_by_director.feature:25 

Ambiguous match of "I should see "THX-1138"": 
    features/step_definitions/movie_steps.rb:12:in `/^(?:|I)should see "([^"]*)"$/' 
    features/step_definitions/web_steps.rb:105:in `/^(?:|I)should see "([^"]*)"$/' 

    You can run again with --guess to make Cucumber be more smart about it 
    (Cucumber::Ambiguous) 
    features/Search_movie_by_director.feature:25:in `And I should see "THX-1138"' 

在我paths.rb我已經輸入:

When /the Similar Movies page for "(.*)"/ 

    "/movies/the_same_director/xxx%20XXX" 

在我的電影的步驟(懷疑這個相關的)我已經輸入:

Then /^(?:|I)should see "([^"]*)"$/ do |title| 
    if page.respond_to? :should 
     page.should have_content(title) 
    else 
     assert page.has_content?(title) 
    end 
end 

最後,在我的movie_controller.rb

def the_same_director 
    #left it empty for I think its relevant to the happy scenerio 
end 

願有人請指點我正確的方向?

回答

1

您有不明確的步驟名稱。 將步驟開始時的Given,When,AndThen視爲一般佔位符。所以:

And I should see " " 

Then I should see " " 

實際上是同一個步驟(Cucumber會看到所有的step_function文件夾中的文件,無論其功能文件美其名曰)

如果他們應該做同樣的事情寫下這些步驟,使它們在功能文件中相同(將它們切換爲:

Then I should see " " 

然後將步驟定義分解出來(將其置於general_steps.rb文件中)。

如果他們的行爲不同,則更改步驟的名稱以免它們含糊不清。例如:

Then I should see the movie title " " 

Then I should see the web site " " 

否則,你可以只用--guess標籤調用它,當您啓動黃瓜用黃瓜--guess。這應該可以工作,但你仍然應該解決模糊問題。

+0

感謝凱爾及時的反饋! – user3435842 2014-12-03 17:13:05