I going to test the class method which get the integer as parameter:
def step(response)
if response < 10
I create cucumber scenario:
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 |
And the step difinitions:
When /^I response "([^"]*)"$/ do | response |
@result = @game.step(response)
end
When I’m running the test I get error, because the cucumber pass the parameter to my method as String.
How can I fix it?
I can fix the class method code:
def step(response)
response = response.to_i
if response < 10
but it will break all my existing code.
Cucumber always pass string parameters to your step definitions and it is step definition responsibility to convert parameter to appropriate type. You need to do this: