0

Just realized if I call twice

#test.feature

When test abc cba
and test abc cba

#test_steps.rb

When(/^Test (.+)$/ do |arg|
  puts arg
  arg.remove! 'cba'
end

It will first return (puts)

#=> abc cba

and in the second call

#=> abc

...interesting. To be sure I checked arg.object_id in every call and its... the same

also checked same calls between difference scenarios and results didn't change at all.

My question is: How does cucumber saves same string between different When/Then calls ?

Jarno Lamberg
  • 1,530
  • 12
  • 12
Filip Bartuzi
  • 5,711
  • 7
  • 54
  • 102

1 Answers1

0

Cucumber steps are globally defined and it will reuse steps. When you call remove! on the args, you are altering the global step which is resulting on your second call happening with the altered args.

Put in a Before hook and a pry and you can insepct the state of things.

Before do |scenario|
  binding.pry
end

[3] pry(#<Object>)> scenario.steps
=> Cucumber::Ast::StepInvocation, 40034540, Cucumber::Ast::StepInvocation, 40034500
Jeff Price
  • 3,229
  • 22
  • 24