2012-01-23 33 views
2

factory_girl黃瓜幫手很酷。我喜歡這個作品:黃瓜:在步驟定義中使用「step」方法的多行參數

Given the following users exist: 
    | Name | Email   | 
    | Alan | [email protected] | 
    | Bob | [email protected] | 

但我不能解決如何在步驟定義中調用它們。例如:

Given /the usual users exist/ do 
    step "the following users exist: 
    | Name | Email   | 
    | Alan | [email protected] | 
    | Bob | [email protected] |" 
end 

...拋出Your block takes 1 argument, but the Regexp matched 0 arguments. (Cucumber::ArityMismatchError)

在步驟定義中使用step將多行參數傳遞到另一個步驟的正確方法是什麼?

編輯: 源代碼總是得心應手。我發現step的簽名是def step(name, multiline_argument=nil)。暗示。然而,令人遺憾的是,

step "the following users exist", " 
    | Name | Email   | 
    | Alan | [email protected] | 
    | Bob | [email protected] |" 

也與undefined method 'hashes' for #<Cucumber::Ast::DocString:0xa9bf6f4> (NoMethodError)失敗。我仍然很想知道這應該如何工作。

然而,這裏有一線希望。我發現另一個功能steps,這是def steps(steps_text),並且工作。見答案。

回答

-1

這並不完全符合我一直在尋找,但閱讀源代碼,揭示了以下工作:這似乎

Given /the usual users exist/ do 
    steps "Given the following users exist: 
    | Name | Email   | 
    | Alan | [email protected] | 
    | Bob | [email protected] |" 
end 
+0

不工作 –

+0

@JustinSearls - 完全爲我工作,並已做了過去的一年。 – Chowlett