Read more

How to find out if you are in Cucumber or in RSpec

Arne Hartherz
May 08, 2013Software engineer at makandra GmbH

Sometimes you need a piece of code to do something different for specs than for features. If you don't have separate environments, you can't check your Rails.env.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

I managed to distinguish between specs and features by asking Capybara.

Note that this only works when you do not use Capybara in specs.

if defined?(Capybara) and Capybara.respond_to?(:current_driver)
  # you're in a Cucumber scenario
else
  # you're probably in a spec
end

You could omit the defined?(Capybara) condition, if you are sure that Capybara is always defined when that code is being called.

Posted by Arne Hartherz to makandra dev (2013-05-08 15:59)