It’s a simple question. I have Cucumber steps, for example:
Given /We have the test environment/ do
@user = # Create User model instance
@post = # Create Post model instance
# etc...
end
In the Then step I’m using my own classes, they simplify the process of testing:
Then /all should be fine/ do
# MyValidatorClass has been defined somwhere in features/support dir
validator = MyValidatorClass.new
validator.valid?.should be_true
end
Inside the MyValidatorClass instance, I deal with the above instance variables @user, @post, etc.
What is the best and simpliest way to access Cucumber variables from MyValidatorClass class instance?
class MyValidatorClass
def valid?
@post
@user
end
end
Now I have manually passed all arguments to MyValidatorClass instance:
validator = MyValidatorClass.new @user, @post
But I think this purpose is bad. I need something more transparent, because we are using Ruby, that why!
What is the best way to do this?
I have found the posible soultion. You just should migrate from instance variables to class variables: