2012-03-16 9 views
0

アウトラインタイプの会話は:キュウリ私は、パラメータとして整数を取得するクラスメソッドをテストしようとして

Scenario Outline: submit guess 
    Given the code "<code>" 
    When I response "<answer>" 
    Then the result should be "<result>" 

    Scenarios: level one 
    | code | answer | result | 
    | 1 | 2 | 3 | 
    | 5 | 4 | 9 | 

そして、ステップdifinitions:

When /^I response "([^"]*)"$/ do | response | 
    @result = @game.step(response) 
end 

def step(response) 
    if response < 10 

私はキュウリのシナリオを作成します

私は、キュウリが私のメソッドにパラメータとしてStringを渡すので、私はエラーを取得するテストを実行しています。

どうすれば修正できますか?

私は、クラスメソッドのコードを修正することができます。

def step(response) 
    response = response.to_i 
    if response < 10 

を、それはすべての私の既存のコードを中断します。

+0

う - http://www.engineyard.com/blog/2009/cucumber-step-argument-transforms/ – iafonov

答えて

1

キュウリは常に文字列パラメータをステップ定義に渡し、パラメータを適切なタイプに変換するのはステップ定義の責任です。あなたはこれを実行する必要があります。

When /^I response "([^"]*)"$/ do | response | 
    @result = @game.step(response.to_i) 
end 
+0

ありがとう。私のために恥ずべき。 – demas

関連する問題