How can I test various environments (eg development | test | production) in Cucumber?

Take this script. I have a Google Analytics tracking code and I want it to display in Production mode. Therefore, I can have two scenarios:

Scenario: Don't embed tracking code in development or test mode
  Given the app is not in production mode
  When I go home
  Then I should really not see the tracking code

Scenario: Embed tracking code in production mode
  Given the app is in production mode
  When I go home
  Then I should really see the tracking code

So, although I know how to check what the current environment is, and I know how to set the current environment in Rails or Sinatra, I have no idea how to run a specific script in a specific environment. Is it possible?

+3
source share
2 answers

You should be able to force the environment in the test code itself, something like strings ENV['RACK_ENV'] = 'test' ENV['RACK_ENV'] = 'production'

I would think this is a pretty bad code smell.

(http://richardconroy.blogspot.com/2010/01/issues-testing-sinatra-datamapper-app.html), , . , .

, Google Analytics -? cookie // .

+1

, URL , ; , , , , - , ?

, Capybara (, - webrat, ).

Given /^the app is in production mode$/ do
  Capybara.current_driver = :selenium
  Capybara.app_host = 'http://www.joshcrews.com'
end

When /^I go home$/ do
  visit("http://www.joshcrews.com")
end

Then /^I should really see the tracking code$/ do
  page.body.should match /UA-7396376-1/
end
+3

Source: https://habr.com/ru/post/1757275/


All Articles