Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Impersonator Pattern

The Impersonator Pattern

Writing cukes describing the real business value a feature is providing is hard. We end up having an horrendous amount of step definitions that muddle the real value the feature is providing; cluttered with interactions with the UI.

This talk describes a different approach to writing cukes following a pattern that has evolved from working on several customer projects, The Impersonator Pattern.

You can find the recording of this talk here: http://skillsmatter.com/podcast/agile-testing/the-impersonator-pattern

Tweet

More Decks by Enrique Comba Riepenhausen

Other Decks in Programming

Transcript

  1. impersonate |ɪmˈpəәːs(əә)neɪt| verb [ with obj. ] pretend to be

    (another person) for entertainment or fraud: it's a very serious offence to impersonate a police officer. DERIVATIVES impersonator noun ORIGIN early 17th cent. (in the sense ‘personify’): from in-2‘into’ + Latin persona ‘person’, on the pattern of incorporate . The Impersonator Pattern
  2. impersonate |ɪmˈpəәːs(əә)neɪt| verb [ with obj. ] pretend to be

    (another person) for entertainment or fraud: it's a very serious offence to impersonate a police officer. DERIVATIVES impersonator noun ORIGIN early 17th cent. (in the sense ‘personify’): from in-2‘into’ + Latin persona ‘person’, on the pattern of incorporate . The Impersonator Pattern
  3. @login_as_bank_manager Scenario: Create new business account Given I am on

    POS Screen And I follow "Add" Then I should see "New Business Account" When I fill in "Code" with "PA11" And I fill in "Name" with "Enrique" And I check "Depository" And I select "GBP" from "RYA" And I fill in "Residence" with "UK" And I press "Create" Then I should see "Business Account - One"
  4. When /^I make an adjustment of (\d+) EUR from "([^\"]*)"

    to "([^\"]*)"$/ do |amo target_account| within('table tr', :text => account) do click_on 'Adjust' end select 'Account', :from => 'adjustment_cash_adjustment_type' select target_account, :from => 'adjustment_cash_target_account_id' fill_in 'adjustment_cash_quantity', :with => amount fill_in 'adjustment_cash_comment', :with => 'Required Comment Text' click_on 'Book' wait_until { page.has_content?('Cash Adjustment successfully created') } end Yes,
  5. Given /^a (?:business|current) account$/ do bank = FactoryBoy.create(:bank) the_account_owner =

    the(:account_owner, name: 'Clark Cuke') account = create_account_for(the_account_owner, location: Country.find_by_name( 'United Kingdom'), currency: 'GBP', bank: bank) create_transactions_for_account( account: account, transaction_types: 'payments') end
  6. Recognizing the relevant @login_as_bank_manager Scenario: Create new business account Given

    I am on POS Screen And I follow "Add" Then I should see "New Business Account" When I fill in "Code" with "PA11" And I fill in "Name" with "Enrique" And I check "Depository" And I select "GBP" from "RYA" And I fill in "Residence" with "UK" And I press "Create" Then I should see "Business Account - One"
  7. Recognizing the relevant @login_as_bank_manager Scenario: Create new business account Given

    I am on POS Screen And I follow "Add" Then I should see "New Business Account" When I fill in "Code" with "PA11" And I fill in "Name" with "Enrique" And I check "Depository" And I select "GBP" from "RYA" And I fill in "Residence" with "UK" And I press "Create" Then I should see "Business Account - One" Looks
  8. Recognizing the relevant @login_as_bank_manager Scenario: Create new business account Given

    I am on POS Screen And I follow "Add" Then I should see "New Business Account" When I fill in "Code" with "PA11" And I fill in "Name" with "Enrique" And I check "Depository" And I select "GBP" from "RYA" And I fill in "Residence" with "UK" And I press "Create" Then I should see "Business Account - One" Looks
  9. Recognizing the relevant @login_as_bank_manager Scenario: Create new business account Given

    I am on POS Screen And I follow "Add" Then I should see "New Business Account" When I fill in "Code" with "PA11" And I fill in "Name" with "Enrique" And I check "Depository" And I select "GBP" from "RYA" And I fill in "Residence" with "UK" And I press "Create" Then I should see "Business Account - One" Looks
  10. What’s the real value Scenario: Creating a new business account

    Given a bank manager is logged in And he creates a business account with: | code| name | currency| country of residence | | PA11| Enrique | GBP | UK | Then that business account should be available
  11. Extracting steps Given(/^a bank manager is logged in$/) do visit

    ‘/login’ fill_in ‘username’, with: ‘me’ fill_in ‘password’, with: ‘s3cr3t’ click_on ‘Login’ end Then(/^he creates a business account with$/) do |data| # all the creation logic here end Then(/^that business account should be available $/do # and the logic to check that that account is there # here end
  12. What if? We could pretend to be someone and act

    like her? impersonate |ɪmˈpəәːs(əә)neɪt| verb [ with obj. ] pretend to be (another person) for entertainment or fraud: it's a very serious offence to impersonate a police officer. DERIVATIVES impersonator noun ORIGIN early 17th cent. (in the sense ‘personify’): from in-2‘into’ + Latin persona ‘person’, on the pattern of incorporate . http://www.flickr.com/photos/95012874@N00/8274759702
  13. The environment #... require_relative 'impersonators' #... class ApplicationWorld include Capybara::DSL

    # include all other things you want/need include Cucumber::Impersonators end World do ApplicationWorld.new end this
  14. The environment #... require_relative 'impersonators' #... class ApplicationWorld include Capybara::DSL

    # include all other things you want/need include Cucumber::Impersonators end World do ApplicationWorld.new end I
  15. Impersonator module module Cucumber module Impersonators def a_bank_manager @bank_manager ||=

    BankManager.new self end end end ./features/support/impersonators.rb
  16. Impersonator class Given(/^a bank manager is logged in$/) do end

    visit ‘/login’ fill_in ‘username’, with: ‘me’ fill_in ‘password’, with: ‘s3cr3t’ click_on ‘Login’
  17. Impersonator class module Cucumber module Impersonators class BankManager def initialize(world)

    @world = world end def login @world.visit ‘/login’ @world.fill_in ‘username’, with: ‘me’ @world.fill_in ‘password’, with: ‘s3cr3t’ @world.click_on ‘Login’ end end end end visit ‘/login’ fill_in ‘username’, with: ‘me’ fill_in ‘password’, with: ‘s3cr3t’ click_on ‘Login’ same
  18. Wiring it up! Given(/^a bank manager is logged in$/) do

    visit ‘/login’ fill_in ‘username’, with: ‘me’ fill_in ‘password’, with: ‘s3cr3t’ click_on ‘Login’ end
  19. What can be impersonated? Your system/app The data layer Anonymous

    users “I” or the narrator elvis? http://www.flickr.com/photos/27261720@N00/2715725134
  20. Example Scenario: Creating a new business account Given a bank

    manager is logged in And he creates a business account with: | code| name | currency| country of residence | | PA11| Enrique | GBP | UK | Then that business account should be available
  21. Example Scenario: Creating a new business account Given a bank

    manager is logged in And he creates a business account with: | code| name | currency| country of residence | | PA11| Enrique | GBP | UK | Then that business account should be available Where
  22. Example Background: Given there is a bank manager in the

    system Scenario: Creating a new business account Given a bank manager is logged in And he creates a business account with: | code| name | currency| country of residence | | PA11| Enrique | GBP | UK | Then that business account should be available
  23. Example Background: Given there is a bank manager in the

    system Scenario: Creating a new business account Given a bank manager is logged in And he creates a business account with: | code| name | currency| country of residence | | PA11| Enrique | GBP | UK | Then that business account should be available That’s
  24. Benefits Impersonators tell a story We know who can do

    what in one glimpse Clean step definitions You need more?