一种简单的方法来检测rspec或Cucumber是否正在运行? [英] Easy way to detect whether rspec or cucumber is running?
问题描述
我目前正在某些地方通过
I'm currently checking in some places whether code is being executed in test mode, by
Rails.env.test?
我想更进一步,检查执行代码的是Cucumber还是Rspec,为了微调i18n的某些方法(我确实希望在Cucumber上下文中以不同的方式运行,但在Rspec上下文中不是这样)
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?
推荐答案
我正在使用黄瓜导轨
gem,这样至少可以做到 defined?(黄瓜)
。如果您正在运行库克,则将返回常数
,如果您正在运行规范,则将返回 nil
。
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.
这篇关于一种简单的方法来检测rspec或Cucumber是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!