I came across an issue in cucumber and I am not able to understand the underlying behaviour. It will be really great if some one can help me to understand this.
Issue: Cucumber-ruby (also Cucumber-Jruby) step definition, while matching a parameter containing new line, behaves one way when the parameter is specified in the Scenario's step and in a different way if it is in the example section of a Scenario outline. Please refer to the Scenario Outline and Scenario provided below.
Scenario Outline: new line in scenario outline
Given this is also a new line test <line>
Examples:
| line |
| this has\ntest\n |
Scenario: new line in scenario
Given this is also a new line test this has\ntest\nStep Definition for both the above scenarios:
Given(/^this is also a new line test ([^"]*)$/) do |line|
a = <<'EOC'
this has
test
EOC
puts line
puts assert_equal(line, a)
endWhile the first scenario passes the second one fails with the below message:
this has\ntest\n
MiniTest::Assertion: <"this has\\ntest\\n"> expected but was
<"this has\ntest\n">.
./features/step_definitions/my_steps.rb:61:in `/^this is also a new line test ([^"]*)$/'
./features/myTest.feature:25:in `Given this is also a new line test this has\ntest\n'
1 scenario (1 failed)
1 step (1 failed)
0m0.090sFrom what I observed, when the parameter in a cucumber step has \n, then it is converted to '\\n'. This doesn't seem to be the case if the same string is in the Examples section of a Scenario Outline.
Is there a reason, why cucumber (or is it ruby?) interprets newline character differently depending upon the location of the parameter? Am I missing something very obvious here? Any inputs on this is appreciated.
Note: I have found out that using doc string will resolve this issue. But I would like to understand why \n in Scenario Steps behaves differently from Scenario Examples.
Ruby Version: 2.1.1 Cucumber Version : 1.3.15