Harry Harry - 6 months ago 7
Ruby Question

Testing HTTP and HTTPS on Cucumber Ruby

I am trying to fix a bug and the impossibility to reproduce it on my local environment is becoming a problem.

Cucumber might be able to help, but I couldn't find a way to make cucumber work for me. It is specifically about HTTP and HTTPS.

I use 4 different environments. Only production and the one below are HTTPS ones and my bug only happens there exactly because of the protocol/URL generation.

Is there a way to make cucumber work under HTTPS for a specific feature?

I hope it was clear enough, although I think it is still a bit vague.


You can make capybara use HTTPS inside cucumber tag hooks. For instance:

Scenario: redirect to another location
  Given I am seeing something
  When I do some action
  Then I should be directed to another location

Now the way to make it work is to use cucumber hooks.

# Use HTTPS host for specific scenario
Before('@https') do
  Capybara.app_host = some_https_location

# Revert back to HTTP host for future scenarios
After('@https') do
  Capybara.app_host = some_regular_http_location