SlideShare a Scribd company logo
How green is my cucumber?

Monday, 2 November 2009
Refactoring the Cuke

            Latest version is 0.4.x

                  Breaks things

                  Fixes things

                  Adds new things

                  Different approach

            We need to refactor our Cucumber setup and usage


Monday, 2 November 2009
Breakages


            Cucumber::Rails.bypass_rescue

            Cucumber::Rails.use_transactional_fixtures




Monday, 2 November 2009
New - Tags

            @no-txn tag

                  used to turn off normal transactions for scenarios

                  we can use with database cleaner via tagged hooks

            @allow-rescue tag

                  allows errors to be caught be Rails (not Cucumber)



Monday, 2 November 2009
New - Multiline Tables


            allows tables as arguments for steps

            not the same as scenario outlines




Monday, 2 November 2009
Given the          following people exist:
         | name           | email           | phone   |
         | Aslak          | aslak@email.com | 123     |
         | Joe            | joe@email.com   | 234     |
         | Bryan          | bryan@email.org | 456     |

       Given /the following people exist:/ do |people_table|
         people_table.hashes.each do |hash|
           # The first time the +hash+ will contain:
           #   {'name' => 'Aslak', 'email' => 'aslak@email.com', 'phone' => '123'}
           # The second time:
           #   {'name' => 'Joe', 'email' => 'joe@email.com', 'phone' => '234'}
           # etc.
         end
       end




Monday, 2 November 2009
New - Diff’ing Tables

            can compare a table argument to another table

            typically done in a Then step

            new convenience Webrat method that turns a HTML table
            into an Array of Array:

                          expected_cukes_table.diff!(table_at('#cuke_table').to_a)




Monday, 2 November 2009
Then I should see the   following cukes:
         | Latin           |   English      |
         | Cucumis sativus |   Cucumber     |
         | Cucumis anguria |   Burr Gherkin |

       Then /^I should see the following cukes:$/ do |expected_cukes_table|
         actual_table = [
           ['Latin', 'English'],
           ['Cucumis sativus', 'Concombre'],
           ['Cucumis anguria', 'Burr Gherkin']
         ] # In practice you'd pull this out of a web page or database

         expected_cukes_table.diff!(actual_table)
       end




Monday, 2 November 2009
New - Multiline Strings


            uses PyString syntax of three double-quote marks

            text automatically yielded as last parameter of step definition




Monday, 2 November 2009
Given a blog post named "Random" with Markdown body
         """
         Some Title, Eh?
         ==============
         Here is the first paragraph of my blog post. Lorem ipsum dolor sit amet,
         consectetur adipiscing elit.
         """

       Given /^a blog post named "([^"]*)" with Markdown body$/ do |title,
       markdown|
         Post.create!(:title => title, :body => markdown)
       end




Monday, 2 November 2009
New - Webrat Steps

            extra default webrat steps including:

                  “Then show me the page”

                  see within eg Then I should see “text” within “selector”

                  see regex eg Then I should see /regex/

                  Given I am on, When I go to, Then I should be on ...

                  When I fill in the following (table of form values)


Monday, 2 November 2009
New - Step Transforms
            Step argument transforms

                  helps DRY up step definitions

                  see for more info:
                  http://wiki.github.com/aslakhellesoy/cucumber/step-
                  argument-transforms

                  and:
                  http://www.engineyard.com/blog/2009/cucumber-step-
                  argument-transforms/

Monday, 2 November 2009
New - PDF Formatter


            use --format pdf --out filename.pdf

            requires prawn




Monday, 2 November 2009
New - Screenshots


            selenium only

            webrat method:

                  save_and_open_screengrab




Monday, 2 November 2009
The New Cucumber Way


            env.rb is expected to be managed by Cucumber

            custom code should be put into separate files




Monday, 2 November 2009
env.rb

            big warning message

            transactional fixtures

            allow rescue

            cucumber settings

            webrat settings



Monday, 2 November 2009
#   IMPORTANT: This file was generated by Cucumber 0.4.0
       #   Edit at your own peril - it's recommended to regenerate this file
       #   in the future when you upgrade to a newer version of Cucumber.
       #   Consider adding your own code to a new file instead of editing this one.




Monday, 2 November 2009
ENV["RAILS_ENV"] ||= "cucumber"
       require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
       require 'cucumber/rails/world'




Monday, 2 November 2009
Cucumber::Rails::World.use_transactional_fixtures = true




Monday, 2 November 2009
ActionController::Base.allow_rescue = false




Monday, 2 November 2009
require            'cucumber'
       require            'cucumber/formatter/unicode'
       require            'cucumber/webrat/element_locator'
       require            'cucumber/rails/rspec'




Monday, 2 November 2009
require 'webrat'
       require 'webrat/core/matchers'
       Webrat.configure do |config|
         config.mode = :rails
         config.open_error_files = false
       end




Monday, 2 November 2009
New AMC Cuking Way

            cucumber.yml can now exist in config directory

            pickle, machinist, webrat, sphinx, db cleaner, and stubbing all
            separate files

            env.rb is now pristine

                  no more manual updating

                  to update cucumber simply script/generate cucumber



Monday, 2 November 2009
cucumber.yml

            moved to config directory

            profiles simplfied

                  default

                  selenium

                  no more sphinx profile

            Textmate shell variable TM_CUCUMBER_OPTS changed


Monday, 2 November 2009
default:
             -t ~@selenium
             -r features
             RAILS_ENV=test




Monday, 2 November 2009
selenium:
             -t @selenium
             -r features
             RAILS_ENV=test
             WEBRAT_MODE=selenium



Monday, 2 November 2009
$         cucumber
       $         cucumber -t ~@no-txn
       $         cucumber -p selenium
       $         cucumber -t @sphinx




Monday, 2 November 2009
TM_CUCUMBER_OPTS:
           -t ~@selenium,~@sphinx
           -r features
           --format html




Monday, 2 November 2009
Pickle & Machinst

            Pickle

                  moved to features/support/pickle.rb

                  but script/generate pickle automatically appends to env.rb

            Machinist

                  moved to features/support/machinist.rb



Monday, 2 November 2009
Database Cleaner


            separated out to features/support/db_cleaner.rb

            used by all non-transactional scenarios eg sphinx & selenium

            uses tagged before and after hooks (@no-txn) to clean the
            database




Monday, 2 November 2009
Sphinx
            remains at features/support/sphinx.rb

            scenarios that use sphinx must be tagged with @sphinx AND
            @no-txn so that these features are not run in a transaction

            database cleaning pulled out into database_cleaner.rb

            still use tagged before hook to reindex

            uses at_exit to stop searchd

            searchd runs on its own port specified in sphinx.yml

Monday, 2 November 2009
Webrat & Selenium
            remains in features/support/webrat.rb

            webrat can only run in rails or selenium mode (not both at the
            same time)

            we use ENV[‘WEBRAT_MODE’] in profiles in set selenium
            mode

            defaults to rails mode

            selenium scenarios tagged with @selenium AND @no-txn


Monday, 2 November 2009
Extras


            moved to features/support/env_extra.rb

            enable RSpec's stubbing support, specifically for stubbing
            Time.now

            with RSpec 1.2.8, enabling stubbing is now a single require




Monday, 2 November 2009
require 'spec/stubs/cucumber'




Monday, 2 November 2009
Using Multiple Cukes

            unpacked cucumber gem into /vendor/gems

            cuke bash function

                  selectively uses vendored of system cucumber binary

                  overcomes problems with using different cucumbers on
                  different projects and having new versions of cucumber
                  breaking your project’s features



Monday, 2 November 2009
function cuke {
         vendor_cuke_path="vendor/gems/cucumber*/bin/cucumber"
         if [ -x $vendor_cuke_path ]; then
            eval $vendor_cuke_path $@
         else
            cucumber $@
         fi
       }




Monday, 2 November 2009
http://www.flickr.com/photos/knittingskwerlgurl/3731055596/


Monday, 2 November 2009

More Related Content

PDF
A tour of Ansible
PDF
AnsibleFest 2014 - Role Tips and Tricks
PDF
Chef or how to make computers do the work for us
PDF
Ansible ハンズオン on AWS - DevelopersIO 2017
PPTX
Stack kicker devopsdays-london-2013
PPTX
Chef advance
PDF
V2 and beyond
PDF
Ansible leveraging 2.0
A tour of Ansible
AnsibleFest 2014 - Role Tips and Tricks
Chef or how to make computers do the work for us
Ansible ハンズオン on AWS - DevelopersIO 2017
Stack kicker devopsdays-london-2013
Chef advance
V2 and beyond
Ansible leveraging 2.0

What's hot (20)

KEY
CakePHP + PostgreSQL
PDF
More tips n tricks
PDF
Intro to Rails
PDF
Getting Started with PoolParty and EC2
PDF
Fixing Growing Pains With Puppet Data Patterns
PDF
Getting started with Ansible
PPTX
Herd your chickens: Ansible for DB2 configuration management
PDF
Ansible roles done right
PPTX
Introduction to Ansible - (dev ops for people who hate devops)
PDF
Introduction to Rails - presented by Arman Ortega
ODP
Pfm technical-inside
PDF
Automation and Ansible
TXT
Httpd.conf
PDF
PDF
Automating with ansible (Part B)
KEY
Rails web api 开发
PDF
Ansible 202
PDF
Phoenix for Rails Devs
PDF
Automating with ansible (part a)
PDF
Scaling Mapufacture on Amazon Web Services
CakePHP + PostgreSQL
More tips n tricks
Intro to Rails
Getting Started with PoolParty and EC2
Fixing Growing Pains With Puppet Data Patterns
Getting started with Ansible
Herd your chickens: Ansible for DB2 configuration management
Ansible roles done right
Introduction to Ansible - (dev ops for people who hate devops)
Introduction to Rails - presented by Arman Ortega
Pfm technical-inside
Automation and Ansible
Httpd.conf
Automating with ansible (Part B)
Rails web api 开发
Ansible 202
Phoenix for Rails Devs
Automating with ansible (part a)
Scaling Mapufacture on Amazon Web Services
Ad

Viewers also liked (7)

PDF
Concept ontwikkelingsplan kazerneterreinen
PPSX
Adwize Profile
PPTX
That thing lara croft
PDF
Usability Testing
PPTX
Audience feedback
PPT
Pozyskane środki przez Miasto Radomsko
PPTX
Scheduling
Concept ontwikkelingsplan kazerneterreinen
Adwize Profile
That thing lara croft
Usability Testing
Audience feedback
Pozyskane środki przez Miasto Radomsko
Scheduling
Ad

Similar to Cucumber Upgrade (20)

PDF
Btree Nosql Oak
PDF
Game Changing Dependency Management
PDF
Testing Drupal with Ghosts and Gherkin
PDF
RubyConf 2009
PDF
Getting Started with (Distributed) Version Control
PDF
How to make DSL
PDF
Kubernetes: Wie Chefkoch.de mit Containern arbeitet
PDF
Aplicacoes dinamicas gurusc
PDF
Building Sencha Themes
PDF
App Lego
PDF
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
PDF
JRubyConf 2009
PDF
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
PDF
Welcome to the Symfony2 World - FOSDEM 2013
PDF
The State of the Social Desktop 2009
PPT
Learn basic ansible using docker
PDF
Introduction to Ruby & Ruby on Rails
PDF
What to do when things go wrong
PDF
MySQL Sandbox 3
PDF
Active Record Introduction - 3
Btree Nosql Oak
Game Changing Dependency Management
Testing Drupal with Ghosts and Gherkin
RubyConf 2009
Getting Started with (Distributed) Version Control
How to make DSL
Kubernetes: Wie Chefkoch.de mit Containern arbeitet
Aplicacoes dinamicas gurusc
Building Sencha Themes
App Lego
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
JRubyConf 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
Welcome to the Symfony2 World - FOSDEM 2013
The State of the Social Desktop 2009
Learn basic ansible using docker
Introduction to Ruby & Ruby on Rails
What to do when things go wrong
MySQL Sandbox 3
Active Record Introduction - 3

Cucumber Upgrade

  • 1. How green is my cucumber? Monday, 2 November 2009
  • 2. Refactoring the Cuke Latest version is 0.4.x Breaks things Fixes things Adds new things Different approach We need to refactor our Cucumber setup and usage Monday, 2 November 2009
  • 3. Breakages Cucumber::Rails.bypass_rescue Cucumber::Rails.use_transactional_fixtures Monday, 2 November 2009
  • 4. New - Tags @no-txn tag used to turn off normal transactions for scenarios we can use with database cleaner via tagged hooks @allow-rescue tag allows errors to be caught be Rails (not Cucumber) Monday, 2 November 2009
  • 5. New - Multiline Tables allows tables as arguments for steps not the same as scenario outlines Monday, 2 November 2009
  • 6. Given the following people exist: | name | email | phone | | Aslak | aslak@email.com | 123 | | Joe | joe@email.com | 234 | | Bryan | bryan@email.org | 456 | Given /the following people exist:/ do |people_table| people_table.hashes.each do |hash| # The first time the +hash+ will contain: # {'name' => 'Aslak', 'email' => 'aslak@email.com', 'phone' => '123'} # The second time: # {'name' => 'Joe', 'email' => 'joe@email.com', 'phone' => '234'} # etc. end end Monday, 2 November 2009
  • 7. New - Diff’ing Tables can compare a table argument to another table typically done in a Then step new convenience Webrat method that turns a HTML table into an Array of Array: expected_cukes_table.diff!(table_at('#cuke_table').to_a) Monday, 2 November 2009
  • 8. Then I should see the following cukes: | Latin | English | | Cucumis sativus | Cucumber | | Cucumis anguria | Burr Gherkin | Then /^I should see the following cukes:$/ do |expected_cukes_table| actual_table = [ ['Latin', 'English'], ['Cucumis sativus', 'Concombre'], ['Cucumis anguria', 'Burr Gherkin'] ] # In practice you'd pull this out of a web page or database expected_cukes_table.diff!(actual_table) end Monday, 2 November 2009
  • 9. New - Multiline Strings uses PyString syntax of three double-quote marks text automatically yielded as last parameter of step definition Monday, 2 November 2009
  • 10. Given a blog post named "Random" with Markdown body """ Some Title, Eh? ============== Here is the first paragraph of my blog post. Lorem ipsum dolor sit amet, consectetur adipiscing elit. """ Given /^a blog post named "([^"]*)" with Markdown body$/ do |title, markdown| Post.create!(:title => title, :body => markdown) end Monday, 2 November 2009
  • 11. New - Webrat Steps extra default webrat steps including: “Then show me the page” see within eg Then I should see “text” within “selector” see regex eg Then I should see /regex/ Given I am on, When I go to, Then I should be on ... When I fill in the following (table of form values) Monday, 2 November 2009
  • 12. New - Step Transforms Step argument transforms helps DRY up step definitions see for more info: http://wiki.github.com/aslakhellesoy/cucumber/step- argument-transforms and: http://www.engineyard.com/blog/2009/cucumber-step- argument-transforms/ Monday, 2 November 2009
  • 13. New - PDF Formatter use --format pdf --out filename.pdf requires prawn Monday, 2 November 2009
  • 14. New - Screenshots selenium only webrat method: save_and_open_screengrab Monday, 2 November 2009
  • 15. The New Cucumber Way env.rb is expected to be managed by Cucumber custom code should be put into separate files Monday, 2 November 2009
  • 16. env.rb big warning message transactional fixtures allow rescue cucumber settings webrat settings Monday, 2 November 2009
  • 17. # IMPORTANT: This file was generated by Cucumber 0.4.0 # Edit at your own peril - it's recommended to regenerate this file # in the future when you upgrade to a newer version of Cucumber. # Consider adding your own code to a new file instead of editing this one. Monday, 2 November 2009
  • 18. ENV["RAILS_ENV"] ||= "cucumber" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'cucumber/rails/world' Monday, 2 November 2009
  • 21. require 'cucumber' require 'cucumber/formatter/unicode' require 'cucumber/webrat/element_locator' require 'cucumber/rails/rspec' Monday, 2 November 2009
  • 22. require 'webrat' require 'webrat/core/matchers' Webrat.configure do |config| config.mode = :rails config.open_error_files = false end Monday, 2 November 2009
  • 23. New AMC Cuking Way cucumber.yml can now exist in config directory pickle, machinist, webrat, sphinx, db cleaner, and stubbing all separate files env.rb is now pristine no more manual updating to update cucumber simply script/generate cucumber Monday, 2 November 2009
  • 24. cucumber.yml moved to config directory profiles simplfied default selenium no more sphinx profile Textmate shell variable TM_CUCUMBER_OPTS changed Monday, 2 November 2009
  • 25. default: -t ~@selenium -r features RAILS_ENV=test Monday, 2 November 2009
  • 26. selenium: -t @selenium -r features RAILS_ENV=test WEBRAT_MODE=selenium Monday, 2 November 2009
  • 27. $ cucumber $ cucumber -t ~@no-txn $ cucumber -p selenium $ cucumber -t @sphinx Monday, 2 November 2009
  • 28. TM_CUCUMBER_OPTS: -t ~@selenium,~@sphinx -r features --format html Monday, 2 November 2009
  • 29. Pickle & Machinst Pickle moved to features/support/pickle.rb but script/generate pickle automatically appends to env.rb Machinist moved to features/support/machinist.rb Monday, 2 November 2009
  • 30. Database Cleaner separated out to features/support/db_cleaner.rb used by all non-transactional scenarios eg sphinx & selenium uses tagged before and after hooks (@no-txn) to clean the database Monday, 2 November 2009
  • 31. Sphinx remains at features/support/sphinx.rb scenarios that use sphinx must be tagged with @sphinx AND @no-txn so that these features are not run in a transaction database cleaning pulled out into database_cleaner.rb still use tagged before hook to reindex uses at_exit to stop searchd searchd runs on its own port specified in sphinx.yml Monday, 2 November 2009
  • 32. Webrat & Selenium remains in features/support/webrat.rb webrat can only run in rails or selenium mode (not both at the same time) we use ENV[‘WEBRAT_MODE’] in profiles in set selenium mode defaults to rails mode selenium scenarios tagged with @selenium AND @no-txn Monday, 2 November 2009
  • 33. Extras moved to features/support/env_extra.rb enable RSpec's stubbing support, specifically for stubbing Time.now with RSpec 1.2.8, enabling stubbing is now a single require Monday, 2 November 2009
  • 35. Using Multiple Cukes unpacked cucumber gem into /vendor/gems cuke bash function selectively uses vendored of system cucumber binary overcomes problems with using different cucumbers on different projects and having new versions of cucumber breaking your project’s features Monday, 2 November 2009
  • 36. function cuke { vendor_cuke_path="vendor/gems/cucumber*/bin/cucumber" if [ -x $vendor_cuke_path ]; then eval $vendor_cuke_path $@ else cucumber $@ fi } Monday, 2 November 2009