user3002273
user3002273

Reputation:

Using environment variables in my cucumber step definitions

I want to change a step definition from something like,

Scenario: eat 5 out of 12
  Given there are 12 cucumbers
  When I eat 5 cucumbers
  Then I should have 7 cucumbers

To,

Scenario: eat 5 out of 12
  Given there are 12 $(FOOD)
  When I eat 5 $(FOOD)
  Then I should have 7 $(FOOD)

So that I can run my cucumber like,

FOOD=cucumbers ./cucumber-launch-script.sh

And everything works as expected.

Upvotes: 2

Views: 4189

Answers (1)

diabolist
diabolist

Reputation: 4099

You can sort of do this but the environment variable can only be used in code, i.e. step definitions and helper methods.

This means that your output will only be talking about FOOD whilst your steps would be talking about oranges and apples.

This would work something like

Given there are 12 food

implemented by

Given 'there are 12 food' do 12.times {create_food) end

and a helper method

def create_food type_of_food = get food from ENV ... end

The only way to get environment variables into features is to preprocess them before you run cucumber, I can't see Cucumber ever supporting this sort of functionality.

Upvotes: 1

Related Questions