• Save
Outside-in Development with Cucumber and Rspec
Upcoming SlideShare
Loading in...5
×
 

Outside-in Development with Cucumber and Rspec

on

  • 18,602 views

Talk given by Joseph Wilk at Scotland on Rails 2009. Examines how Cucumber and Rspec fit together in the testing workflow, how and why Cucumber is useful and how it works. Walks through a simple ...

Talk given by Joseph Wilk at Scotland on Rails 2009. Examines how Cucumber and Rspec fit together in the testing workflow, how and why Cucumber is useful and how it works. Walks through a simple example based on renting DVDs showing how to use Cucumber and some of the best practices. Looks at how Webrat can drive Selenium to in-turn drive Cucumber features through the browser.

Statistics

Views

Total Views
18,602
Views on SlideShare
14,305
Embed Views
4,297

Actions

Likes
76
Downloads
1
Comments
2

14 Embeds 4,297

http://blog.josephwilk.net 2798
http://campusvirtual.ull.es 1282
http://please.dontrush.org 102
http://www.slideshare.net 79
http://www.ozmox.com 15
http://prezi.com 5
http://www.techgig.com 4
http://www.linkedin.com 4
http://www.joesniff.co.uk 2
http://webcache.googleusercontent.com 2
http://translate.googleusercontent.com 1
https://go2http.appspot.com 1
http://seekr-artemis.heroku.com 1
http://127.0.0.1 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

12 of 2

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • My thoughts about Cucumber and new Capybara DSL, checkout at http://inancgumus.com/66712574
    Are you sure you want to
    Your message goes here
    Processing…
  • - Value of cucumber: Slide 37
    - Root Cause Analysis (popping the WHY stack): Slide 46
    - Cucumber feature & scenario: Slide 63
    -Concrete vs Abstract scenarios: Slide 77
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Outside-in Development with Cucumber and Rspec Outside-in Development with Cucumber and Rspec Presentation Transcript

    • utside in Development Cucumber Rspec Joseph Wilk / http://blog.josephwilk.net
    • Why are you here?
    • Why are you here? In order to ...
    • Why are you here? In order to ... As a Scotland on Rails attendee
    • Why are you here? In order to ... As a Scotland on Rails attendee I want ...
    • What is your Acceptance Criteria?
    • Scenario: Happy SoR attendees Given people turned up When Joseph talks Then everyone should acquire some new knowledge And no-one should fall asleep And no rotten food should be thrown
    • Pass Fail
    • Outside-in User Browser Views Controllers Models
    • Cucumber “The feature you wished you had” Views Controllers Rspec Models “The components and the interactions you wish you had”
    • Cucumber “The feature you wished you had” Views Controllers Rspec Models “The components and the interactions you wish you had”
    • Cucumber “The feature you wished you had” Views Controllers Rspec Models “The components and the interactions you wish you had”
    • Cucumber / Scenario
    • Cucumber / Scenario
    • Cucumber / Scenario Rspec / code examples
    • Cucumber / Scenario Rspec / code examples
    • Cucumber / Scenario Rspec / code examples
    • Cucumber / Scenario Rspec / code examples
    • Cucumber / Scenario Rspec / code examples
    • :rspec => route finder :cucumber => destination London Edinburgh
    • Behaviour Driven Development with elegance and joy
    • Behaviour Driven Development with elegance and joy Just Cuke it!
    • Plaintext Ruby Features step definitions
    • Cucumber Feature Not executed Feature: Be awesome Narrative Scenario: title Example of Given <some context> behaviour And <yet more context> When <some action> And <more actions> Then <some outcome> And <more outcomes>
    • regexp match Step definition Given /^we like (.*)$/i do |fruit| fruit.should == 'cukes' Ruby tests #assert_equal(fruit, 'cukes') end Plaintext Given we like cukes Feature Cucumber
    • Plug and Pray Rspec Plaintext Ruby tests TestUnit Cucumber Ruby-Gnome2 Cucumber Sinatra Rails Merb iPhone
    • Cucumber English
    • огурец Russian Chinese concombre French Korean gurka Swedish Japanese German castravete Romanian Gurke ogórek Cucumber English Polish pepino Spanish Italian cetriolo Danish agurk ‫ﺍﳋﻴﺎﺭ‬ Arabic Indonisean ketimun
    • огурец Russian Chinese concombre French Korean gurka Swedish Japanese German castravete Romanian Gurke ogórek Cucumber English Polish pepino Spanish Treetop Rocks Italian cetriolo ANTLR Danish agurk could rock ‫ﺍﳋﻴﺎﺭ‬ Arabic Indonisean harder ketimun
    • Webrat Love visit home_path click_link quot;Webquot; fill_in quot;Emailquot;, :with => quot;Rat” click_button quot;Lovequot; Bansky
    • Return On Investment Cucumber Feature
    • Return On Investment Cucumber Feature • Token Conversation
    • Return On Investment Cucumber Feature • Token Conversation • Acceptance Criteria
    • Return On Investment Cucumber Feature • Token Conversation • Acceptance Criteria • Design
    • Return On Investment Cucumber Feature • Token Conversation • Acceptance Criteria • Design • Documentation
    • Return On Investment Cucumber Feature • Token Conversation • Acceptance Criteria • Design • Documentation • Functional test
    • Return On Investment Cucumber Feature • Token Conversation • Acceptance Criteria • Design • Documentation • Functional test • Integration test
    • Token for Conversation
    • Feature Request I want members to be able to rent a movie with a priority indicating how much they want to see the film
    • Show me the _ _ _ _ _
    • Show me the VA L U _ ____E
    • Root Cause Analysis
    • Root Cause Analysis Why? So we can maximise allocation of films
    • Root Cause Analysis Why? Keep customers happy Why? So we can maximise allocation of films
    • Root Cause Analysis Why? So they continue with their subscriptions Why? Keep customers happy Why? So we can maximise allocation of films
    • Root Cause Analysis Why? So they continue with their subscriptions Why? Keep customers happy Why? So we can maximise allocation of films
    • Lets write our Cucumber feature
    • Feature (terrible) Value Feature: select a movie to rent with priority In order to maximise allocation of films The website user Needs to be able to add movies to their rental list with a priority Role Feature
    • Feature (terrible) Value Feature: select a movie to rent with priority In order to maximise allocation of films Narrative The website user Needs to be able to add movies to their rental list with a priority Role Feature
    • Feature (terrible) Value Feature: select a movie to rent with priority In order to maximise allocation of films The website user Needs to be able to add movies to their rental list with a priority Role Feature
    • Feature (terrible) Feature: select a movie to rent with priority In order to maximise allocation of films The website user Needs to be able to add movies to their rental list with a priority
    • Feature (terrible) Feature: select a movie to rent with priority In order to maximise allocation of films The website user Needs to be able to add movies to their rental list with a priority Noise
    • Feature (terrible) Feature: select a movie to rent with priority In order to maximise allocation of films The website user Needs to be able to add movies to their rental list with a priority Too generic role
    • Feature (terrible) Feature: select a movie to rent with priority In order to maximise allocation of films The website user Film member Needs to be able to add movies to their rental list with a priority Too generic role
    • Feature (terrible) Role can change feature Feature: select a movie to rent with priority In order to maximise allocation of films The website user Film member Needs to be able to add movies to their rental list with a priority
    • Feature (terrible) Role can change feature Film Member selects a movie to rent with priority Feature: select a movie to rent with priority In order to maximise allocation of films The website user Film member Needs to be able to add movies to their rental list with a priority
    • Nice Feature (terrible) Film Member selects a movie to rent with priority Feature: select a movie to rent with priority In order to maximise allocation of films The website user Film member Needs to be able to add movies to their rental list with a priority
    • Acceptance Definition of Done.
    • Scenarios Feature: Film Member selects a movie to rent with priority In order to maximise allocation of films The Film member Needs to add movies to their rental list with a priority Scenario: High priority
    • Scenarios Feature: Film Member selects a movie to rent with priority In order to maximise allocation of films The Film member Needs to add movies to their rental list with a priority Scenario: High priority Then I should see quot;My rental listquot; And I should see quot;Casshernquot; in my rental list And quot;Casshernquot; should be marked as quot;High priorityquot;
    • Scenarios Feature: Film Member selects a movie to rent with priority In order to maximise allocation of films The Film member Needs to add movies to their rental list with a priority Scenario: High priority When I choose quot;High priorityquot; And I press quot;Rentquot; Then I should see quot;My rental listquot; And I should see quot;Casshernquot; in my rental list And quot;Casshernquot; should be marked as quot;High priorityquot;
    • Scenarios Feature: Film Member selects a movie to rent with priority In order to maximise allocation of films The Film member Needs to add movies to their rental list with a priority Scenario: High priority Given I'm logged in And I am viewing the movie quot;Casshernquot; When I choose quot;High priorityquot; And I press quot;Rentquot; Then I should see quot;My rental listquot; And I should see quot;Casshernquot; in my rental list And quot;Casshernquot; should be marked as quot;High priorityquot;
    • Let there be Cuking
    • Demo High Resolution: http://www.screencast.com/t/aG1sE4N3Zq Low Resolution: http://www.vimeo.com/3910617
    • Here’s one I Cuked earlier
    • Demo High Resolution: http://www.screencast.com/t/tlBYxkKci Low Resolution http://www.vimeo.com/3911104
    • Installing Cucumber $ sudo gem install cucumber $ script/plugin install git://github.com/aslakhellesoy/ cucumber.git $ gem sources -a http://gems.github.com $ sudo gem install aslakhellesoy-cucumber
    • Fixtures Scenario: search results found Given /^the Movies$/i do |movie_hash| Given the Movies #{:title => quot;The colour whitequot;}, | title | #{:title => quot;The colour redquot;}, | The colour white | #{:title => quot;Casshernquot;} | The colour red | movies.hashes.each do |values| | Casshern | Movie.create!(values) When I search for quot;colourquot; end Then I will see 2 results end Scenario: search results found Given 2 films with quot;colourquot; in the title When I search for quot;colourquot; Then I will see 2 results
    • Stick it to the World module NavigationHelpers def path_to(page_name) case page_name when /the homepage/ root_path else raise quot;Can't find mapping from quot;#{page_name}quot; to a path.quot; end end end World do |world| world.extend NavigationHelpers world end
    • Hooks Hooks are GLOBAL! Before do # do something before each scenario. end After do #do something after each scenario end
    • How many scenarios is enough? • Given/When/Then “Finite state machine” Uncle Bob • What’s the Return on Investment?
    • Cowcumbers (Bad smells) “fit only for consumption by cows”
    • Cowcumbers Given /^dirty state$/ do @movie = Movie.create! Relying on state (too much) end Given /^coupled by state$/ do @movie.title = quot;yuckyquot; end Given /^does a user care$/ do response.current_url == ‘silly’ end Tests without user value Given /^checking the db$/ do Movie.find(1).should_not == nil end
    • Building your DSL
    • Concrete vs Abstract Scenarios Given I'm logged in Given I go to the login page And I fill in quot;usernamequot; with quot;josephquot; And I fill in quot;passwordquot; with quot;cukerquot; And I click quot;loginquot; Domain understanding Concrete Abstract
    • Calling steps from steps Given /I’m logged in/ do User.create!(:user => 'josephwilk', :password => quot;passquot;) Given 'I fill in quot;passwordquot; with quot;josephwilkquot;' Given 'I fill in quot;passwordquot; with quot;passquot;' Given 'I click quot;loginquot;' end
    • Feature Request Can you add some of that funky AJAX stuff for the rent button
    • JavaScript kills Webrat
    • Watir, Selenium & Celerity Browser based Headless Browser • • Watir Celerity • • Selenium Culerity - http:// github.com/langalex/ culerity/tree/master
    • Webrat / Selenium # Sets up the Rails environment for Cucumber ENV[quot;RAILS_ENVquot;] ||= quot;seleniumquot; require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') require 'cucumber/rails/world' require 'cucumber/formatters/unicode' Turn off #Cucumber::Rails.use_transactional_fixtures require 'webrat' Webrat.configure do |config| Switch to Selenium config.mode = :selenium end require 'cucumber/rails/rspec' require 'webrat/core/matchers' Before do Movie.delete_all Manually cleanup RentalRequest.delete_all end
    • Organising @in-progress Feature: Verify billing Tag @js Scenario: Missing product description Scenario: Several products cucumber --profile rails --tags ~@js cucumber --profile browser --tags @js
    • Demo High Resolution: http://www.screencast.com/t/1jRSI6TvXWu Low Resolution: http://www.vimeo.com/3911241
    • Further reading • http://cukes.info • http://wiki.github.com/ aslakhellesoy/cucumber • http://rspec.info/ • http://blog.josephwilk.net
    • Thanks joe@josephwilk.net http://github.com/josephwilk