Adding a hook for object creation that only occurs once in Cucumber
I just need an object created once and only once in Cucumber. I added a file in support/ called object_setup.rb and load it from within env.rb. The file only contains:开发者_如何学C
@obj = SomeObj.new
But this object is not recognized within any of my steps. The same thing happens if I add this line to the top of the steps file.
Use constants. For example put this into your env.rb
MY_AWESOME_OBJECT = SomeObj.new
It would be instantiated only once for all tests.
P.S: Or consider using singleton if it fits into your architecture.
精彩评论