Reputation: 372
I have defined a variable as userid in env.rb.
userid='1234'
In my Cucumber testing, Scenario, I wish to confirm that my response contains the correct userid. However, I do not wish to hard code the same in my Senario or step definition. Is it possible to do so?
Upvotes: 2
Views: 4098
Reputation: 25767
I would place an additional file, let's say test_constanst.rb
in the features/ dir. There, I would define a module like this:
module TestConstants
def self.user_id
1234
end
end
Like this, you have it separated from test configuration and code. You would just have to requrire the file from env.rb
.
Upvotes: 3
Reputation: 21
Variable scope in Ruby is controlled by sigils to some degree. Variables starting with $ are global, variables with @ are instance variables, @@ means class variables, and names starting with a capital letter are constants. Make the variable global and it will be available everywhere, i.e
$userid='1234'
Upvotes: 2