Daniel Esponda
Daniel Esponda

Reputation: 1397

Cucumber step definition local variables being re-used?

I have been doing quite some research on cucumber step definitions local variables but I can't find anywhere how cucumber handles local variables and I am encountering some weird behavior with them, as if they were not local variables. The variables are using the same memory address and maintaining state, for example:

Then(/^the password is "(.?*)"$/) do |password|
  puts password
  puts password.object_id
  password.concat("s")
end

The inputs for the variable password would be the same - password1234, password1234, password1234 but the output would be:

password1234
32607252

password1234
32607240

password1234s
32607252

password1234ss
32607252

password1234s
32607240

Note how object address -32607252- is being reused, I ran this with multiple scenario examples and a lot of times the object address would be duplicate in different test case scenarios and the concatenation of the "s" would show up even though password is supposed to be a local variable.

Am I doing something wrong? Is this a cucumber bug?

Upvotes: 2

Views: 382

Answers (1)

Daniel Esponda
Daniel Esponda

Reputation: 1397

I e-mailed the cucumber developer team and they have opened an issue to discuss this

https://github.com/cucumber/cucumber/issues/760

Upvotes: 1

Related Questions