问题
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