开发者

Adding a hook for object creation that only occurs once in Cucumber

开发者 https://www.devze.com 2023-03-26 17:20 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消