Skip to content

Instantly share code, notes, and snippets.

@bmabey
Forked from josephwilk/background.feature
Created January 16, 2009 17:46
Show Gist options
  • Save bmabey/48030 to your computer and use it in GitHub Desktop.
Save bmabey/48030 to your computer and use it in GitHub Desktop.
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 pass 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: passing
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
"""
Scenario: run a feature with two scenarios both relying on the given background state
When I run cucumber -q features/background_multiple_scenarios_sample.feature
Then it should pass with
"""
Feature: sample
Background:
Given '10' cukes
Scenario: eating cukes
When I eat '2' cukes
Then I should have '8' cukes
Scenario: saving cukes
When I save all my cukes
Then I should have '10' cukes
2 scenarios
4 step passed
"""
Feature: sample
Background:
Given '10' cukes
Scenario: eating cukes
When I eat '2' cukes
Then I should have '8' cukes
Scenario: saving cukes
When I save all my cukes
Then I should have '10' cukes
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