On Github zroger / bdd-tools-presentation
Dan North, "What's in a Story"
Dan North, "Introducing BDD"
Given: put the system in a known state.
When: describe the key action.
Then: observe outcomes.
Feature: Some terse yet descriptive text of what is desired Textual description of the business value of this feature Business rules that govern the scope of the feature Any additional information that will make the feature easier to understand Scenario: Some determinable business situation Given some precondition And some other precondition When some action by the actor And some other action And yet another action Then some testable outcome is achieved And something else we can check happens too Scenario: A different situation ...
Feature: Division In order to avoid silly mistakes Cashiers must be able to calculate a fraction Scenario: Regular numbers Given I have entered 3 into the calculator And I have entered 2 into the calculator When I press divide Then the result should be 1.5 on the screen
Feature: Addition In order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers Scenario Outline: Add two numbers Given I have entered <input_1> into the calculator And I have entered <input_2> into the calculator When I press <button> Then the result should be <output> on the screen Examples: | input_1 | input_2 | button | output | | 20 | 30 | add | 50 | | 2 | 5 | add | 7 | | 0 | 40 | add | 40 |
Scenario: Blenders Given I put "apples" in a blender When I switch the blender on Then it should transform into "apple juice"
Given /I put "([^"]*)" in a blender/ do |thing| blender = Blender.new blender.add(thing) end
Scenario: Blenders Given I put "apples" in a blender When I switch the blender on Then it should transform into "apple juice"
/** * @Given /^I put "([^"]*)" in a blender$/ */ public function iPutSomethingInABlender($thing) { $this->blender = new Blender() $blender->add($thing) }
Scenario: Blenders Given I put "apples" in a blender When I switch the blender on Then it should transform into "apple juice"
@given('I put "{thing}" in a blender') def step_given_put_thing_into_blender(context, thing): context.blender = Blender() context.blender.add(thing) @when('I switch the blender on') def step_when_switch_blender_on(context): context.blender.switch_on() @then('it should transform into "{other_thing}"') def step_then_should_transform_into(context, other_thing): assert_that(context.blender.result, equal_to(other_thing))
Feature: Google Search Background: Given a browser Scenario: Search for Warby Parker Given I go to "http://google.com" When I fill in "q" with "warby parker" And I press "I'm Feeling Lucky" Then the browser's url should be "http://www.warbyparker.com"
Given a browser Given brand as the default browser Given browser "name" When I reload When I go back When I go forward When I visit "url" When I go to "url" Then the browsers url should be "url" When I click the link with text that contains "text" Then I should see an element with the css selector "selector"
Feature: exit statuses Scenario: exit status of 0 When I run "ruby -h" Then the exit status should be 0 Scenario: non-zero exit status When I run "ruby -e 'exit 56'" Then the exit status should be 56
Given I am using a clean gemset "gemset" Given a directory named "dir" Given a file named "file" with: Given an empty file named "file" When I cd to "dir" When I run `command` When I successfully run `command` When I type "string" Then the output should contain "text" Then the output should not contain "text" Then the exit status should be code Then the exit status should not be code
Feature: Testing demo Scenario: Visit the user login page Given I am not logged in When I visit "/user" Then I should see the link "request a new password" @api Scenario: As a logged in user Given I am logged in as a user with the "administrator" role When I visit "/admin" Then I should see the link "Content"