Cucumber Upgrade

1,857 views

Published on

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

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,857
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
12
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Cucumber Upgrade

  1. 1. How green is my cucumber? Monday, 2 November 2009
  2. 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. 3. Breakages Cucumber::Rails.bypass_rescue Cucumber::Rails.use_transactional_fixtures Monday, 2 November 2009
  4. 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. 5. New - Multiline Tables allows tables as arguments for steps not the same as scenario outlines Monday, 2 November 2009
  6. 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. 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. 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. 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. 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. 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. 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. 13. New - PDF Formatter use --format pdf --out filename.pdf requires prawn Monday, 2 November 2009
  14. 14. New - Screenshots selenium only webrat method: save_and_open_screengrab Monday, 2 November 2009
  15. 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. 16. env.rb big warning message transactional fixtures allow rescue cucumber settings webrat settings Monday, 2 November 2009
  17. 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. 18. ENV["RAILS_ENV"] ||= "cucumber" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'cucumber/rails/world' Monday, 2 November 2009
  19. 19. Cucumber::Rails::World.use_transactional_fixtures = true Monday, 2 November 2009
  20. 20. ActionController::Base.allow_rescue = false Monday, 2 November 2009
  21. 21. require 'cucumber' require 'cucumber/formatter/unicode' require 'cucumber/webrat/element_locator' require 'cucumber/rails/rspec' Monday, 2 November 2009
  22. 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. 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. 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. 25. default: -t ~@selenium -r features RAILS_ENV=test Monday, 2 November 2009
  26. 26. selenium: -t @selenium -r features RAILS_ENV=test WEBRAT_MODE=selenium Monday, 2 November 2009
  27. 27. $ cucumber $ cucumber -t ~@no-txn $ cucumber -p selenium $ cucumber -t @sphinx Monday, 2 November 2009
  28. 28. TM_CUCUMBER_OPTS: -t ~@selenium,~@sphinx -r features --format html Monday, 2 November 2009
  29. 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. 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. 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. 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. 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
  34. 34. require 'spec/stubs/cucumber' Monday, 2 November 2009
  35. 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. 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
  37. 37. http://www.flickr.com/photos/knittingskwerlgurl/3731055596/ Monday, 2 November 2009

×