Easy way to detect whether rspec or cucumber is running?

感情迁移 提交于 2019-12-11 11:09:47

问题


I'm currently checking in some places whether code is being executed in test mode, by

Rails.env.test?

I would like to go one step further, and check whether it is Cucumber or Rspec executing the code, in order to finetune some methods for i18n (which I do want to run differently in a Cucumber context, but not in an Rspec context)

Is there any way to do this?


回答1:


You can set RAILS_ENV=cucumber and then ask:

Rails.env.cucumber?



回答2:


I'm using the cucumber-rails gem, and with that at least you can do defined?(Cucumber). That will return "constant" if you're running a cuke or nil if you're running a spec.



来源:https://stackoverflow.com/questions/22193573/easy-way-to-detect-whether-rspec-or-cucumber-is-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!