Skip to content

Instantly share code, notes, and snippets.

@josephwilk
Created January 16, 2009 17:25
Show Gist options
  • Save josephwilk/48018 to your computer and use it in GitHub Desktop.
Save josephwilk/48018 to your computer and use it in GitHub Desktop.
Background feature for Cucumber
Feature: Backgrounds
In order to provide a context to my scenarios within a feature
As a feature editor
I want to write a background section in my features.
Scenario: run a scenario with a background with a passing step
When I run cucumber -q features/passing_background_sample.feature:6
Then it should pass with
"""
Feature: sample
Background:
Given '10' cukes
Scenario: passing background
Then I have '10' cukes
1 scenario
1 step passed
"""
Scenario: run a scenario with a background with a failing step
When I run cucumber -q features/failing_background_sample.feature:6
Then it should fail with
"""
Feature: sample
Background:
Given -1 cukes
FAIL (RuntimeError)
./features/step_definitions/sample_steps.rb:7:in `Given /^'(.+)' cukes$/'
features/sample.feature:12:in `Given -1 cukes'
Scenario: failing background
FAIL (RuntimeError)
./features/step_definitions/sample_steps.rb:7:in `Given /^'(.+)' cukes$/'
features/sample.feature:12:in `Given -1 cukes'
Then I have '10' cukes
1 scenario
1 step failed
"""
Scenario: run a scenario showing explicit background steps --explicit-background
When I run cucumber -q features/passing_background_sample.feature:6 --explicit-background
Then it should pass with
"""
Feature: sample
Background:
Given '10' cukes
Scenario: passing
(Given '10' cukes)
Then I have '10' cukes
1 scenario
1 step passed
"""
Feature: sample
Background:
Given '-1' cukes
Scenario: failing background
Then I have '10' cukes
Feature: sample
Background:
Given '10' cukes
Scenario: passing background
Then I have '10' cukes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment