Cucumber Upgrade

Post on 24-Apr-2015

2.034 views 4 download

description

A short summary of the new things in the Cucumber testing framework

Transcript of Cucumber Upgrade

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. endend

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 - 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 = falseend

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

Sphinxremains 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