SlideShare a Scribd company logo
Behavior Driven Development
                     with elegance and joy




Getting Up and Running
  with BDD on Rails

  Nicholas Cancelliere
    email: ncancelliere@gmail.com
  twitter: ozmox
Overview

Behavior Driven Development Basic Concepts
Cucumber from 10,000 ft
Cucumber in the Rails Environment
Writing your first Feature / Scenario
Additional Resources
Behavior Driven
“the next step” from Test-Driven Development
tests what an object does rather than what it is
intention more important than implementation
outside-in approach
offers all the benefits of TDD
it is not Test-After Development
Benefits of TDD/BDD

more productive (less debugging, fewer prod defects)
helps drive programming design (KISS/YAGNI)
delays implementation decisions
greater level of code trust
code more modularized, flexible and extensible
Outside-In
   User

  Client
                        Value is in the views!
  Views        Often html but can also be programmatic
                  interfaces (such as XML or JSON),
Controllers         remember valuable to the user.


  Model
Red Green Refactor
 write enough
test code to fail          write just
                         enough code to
                              pass




     review your
      work and
       refactor
Red Green Refactor
 write enough
test code to fail          write just
                         enough code to
                              pass




     review your
      work and
       refactor
Red Green Refactor
 write enough
test code to fail          write just
                         enough code to
                              pass




     review your
      work and
       refactor
Red Green Refactor
 write enough
test code to fail          write just
                         enough code to
                              pass




     review your
      work and
       refactor
User Stories
 concept popular in Agile practices like Scrum and XP
 define the user’s role, what it is they need/want to do,
 and why they need/want (the value)

                                          As a us e r
                                                          w i t h an a
                                           c o n t ac t s                ddre s s b o
                                                          so I c an e                     o k , I ne e d
                      As a u s e r                                       a s i l y re t r                t o a dd
                                     w i t h an a                                         ie ve t h e m
                    e di t/de le t                   ddre s s b o                                        l ate r.
                                   e c o n t ac t                  o k , I ne e d
                                                   s so I c an
                                   d a te a n d                  ke e p i t up to
                                                   m a n ag e a                    -to-
As a us e r                                                      ble .
            w i t h an a
  my c on t a             ddre s s b o
              c ts to o t h              o k , I ne e d
                             e r us e rs t                to se nd
                                             o be sh a r
                                                           e d.
Pop the Why Stack

Ask “Why” up to 5 times
Stop when you find the money
  Protect revenue
  Increase revenue
  Manage cost
Example Pop’in
c: ‘People need to log in.’
d: ‘Why?’
c: ‘Um, identify users?’
d: ‘Why do you need to identify users?’
c: ‘So we know who’s publishing what.’
d: ‘Why would you need to know who publishes what?’
c: ‘If content belongs to someone it seems trustworthy.’
d: ‘Why does content need to be trustworthy?’
c: ‘People will be more interested in the content if so.’
d: ‘Why do you need people interested in the content?’
c: ‘So people come back and visit the site?’
d: ‘Why do you want people to come back and revisit?’
c: ‘More visits will increase our ad revenue.’
The Story

As an author, I need to log into the site
so that articles I create are associated to me
and seem trustworthy, driving more traffic to the site.
The Story

So that articles I create are associated to me, seem
trustworthy and drive more traffic to the site,
as an author, I need to log in.
Enter Cucumber
Dan North ported JBehave to Ruby as RBehave
RSpec merged RBehave in as the Story Runner
  First only supported Ruby for scenarios
  Later supported plain text, but still limited
Aslak Hellesøy in 2008 rewrote Story Runner as
Cucumber (named so by his fiancée)
Cucumber has since taken to a life of it’s own
Cucumber
written in Ruby itself and best matched with Ruby
projects, but can be used for Java, .NET or Flex
supports web apps in any language:
  integrates with Webrat, Watir, Selenium, et. al.
  Gherkin customization edit /cucumber/languages.yml
minimum knowledge of Ruby required, you can pick it
up and get going in a few days
Gherkin: the ‘unpickle’ variety
 a business readable, domain specific language that
 Cucumber understands
 two-stage parser for input file (plain text):
 1. divides the file into sections (eg. feature, scenarios)
 2. sections are divided into steps
 step-definitions are always matched by Ruby methods
 line-oriented (like YAML); line endings terminate
 statements (steps) and spaces or tabs to indent
Given When Then
Used extensively in scenario definitions (Gherkin)
Use “And” to chain together

Given an invalid user
When I go to the sign-in page
And I fill in "userlogin" with "baduser"
And I fill in "password" with "badpassword"
And I submit "new_user_session"
Then I should see "Sorry, we could not sign you in."
And I should see "Login"
Installing in Rails
gem install cucumber rspec-rails webrat

/config/environments/test.rb
config.gem 'rspec-rails', :lib => false
config.gem 'rspec', :lib => false
config.gem 'cucumber'
config.gem 'webrat'

rake gems:install RAILS_ENV=test
script/generate cucumber
script/generate rspec
Test::Unit Shoulda
http://giantrobots.thoughtbot.com/2009/2/20/mixing-
cucumber-with-test-unit


/features/support/env.rb
# require ‘cucumber/rails/rspec’
# require ‘webrat/rspec-rails’


/features/step_definitions/webrat_steps.rb
# replace any matchers that use RSpec syntax

Then /^I should see "(.*)"$/ do |text|
  # response.body.should =~ /#{text}/m
  assert_match /#{text}/m, @response.body
end
Out of the Box
Webrat comes with a bunch of handy helpers out of the
box to make life easy for web application scenarios
rake features - task to run all Cucumber tests

/features
  review_past_events.feature
  /step_definitions
    event_steps.rb
    webrat_steps.rb
  /support
    env.rb
    paths.rb
Features
Features
Step Definition
Step Definition
Cukeing
Cukeing
Cukeing
Cukeing
Cukeing
Cukeing
Backgrounds
Backgrounds
Backgrounds
Scenario Outlines
Scenario Outlines
Remember...

Cucumber defines the features you wish you had.
RSpec (or Test::Unit) defines the interactions and
objects you wish you had.


You’re building a business domain language!
A Good Investment

Conversation
Acceptance Criteria
Design
Documentation
Automated Functional and Integration Tests
What do I use?
               Speed
 Selenium                  +


  Webrat


Unit Testing     +
                       Integration
Cucumber Smells
Relying too much on state in your step-definitions
Tests with no user value
Too much concrete, less abstract
Cucumber Smells
Relying too much on state in your step-definitions
Tests with no user value
Too much concrete, less abstract

    Given /^state$/ do
      @article = Article.create!
    end
    Given /^coupled by state/ do
      @article.title = ‘Bad’
    end
Cucumber Smells
Relying too much on state in your step-definitions
Tests with no user value
Too much concrete, less abstract


     Given /^check the db/ do
       Article.find(1).should_not == nil
     end
Cucumber Smells
Relying too much on state in your step-definitions
Tests with no user value
Too much concrete, less abstract


       Given   I go to the login page
       And I   fill in “username” with “john”
       And I   fill in “password” with “testpass”
       And I   click “login”
Cucumber Smells
Relying too much on state in your step-definitions
Tests with no user value
Too much concrete, less abstract



                Given I’m logged in
Cucumber Smells
Relying too much on state in your step-definitions
Tests with no user value
Too much concrete, less abstract

 Given /I am logged in/ do
   @user = User.create!(:login =>    ‘john’,
                         :password   => ‘testpass’)
   And ‘I fill in “username” with    “john”’
   And ‘I fill in “password” with    “testpass”’
   And ‘I click “login”’
 end
Additional Resources /
          Topics
http://cukes.info
The RSpec Book (beta @ PragProg.com)
Textmate Bundles are available!


Extending Cucumber with World
Using Hooks (careful they’re global)
Ad

More Related Content

Similar to Getting Up and Running with BDD on Rails (20)

How to develop Alexa Skill Kit based on Serverless Architecture
How to develop Alexa Skill Kit based on Serverless ArchitectureHow to develop Alexa Skill Kit based on Serverless Architecture
How to develop Alexa Skill Kit based on Serverless Architecture
Hidetaka Okamoto
 
DDD/CQRS - I must learn to repeat myself
DDD/CQRS - I must learn to repeat myselfDDD/CQRS - I must learn to repeat myself
DDD/CQRS - I must learn to repeat myself
Douglas Reith
 
Code Quality Makes Your Job Easier
Code Quality Makes Your Job EasierCode Quality Makes Your Job Easier
Code Quality Makes Your Job Easier
Tonya Mork
 
Goodparts
GoodpartsGoodparts
Goodparts
damonjablons
 
Behaviour Driven Development
Behaviour Driven DevelopmentBehaviour Driven Development
Behaviour Driven Development
Andy Kelk
 
Cucumber Presentation Kiev Meet Up
Cucumber Presentation Kiev Meet UpCucumber Presentation Kiev Meet Up
Cucumber Presentation Kiev Meet Up
dimakovalenko
 
Selenium and Cucumber Selenium Conf 2011
Selenium and Cucumber Selenium Conf 2011Selenium and Cucumber Selenium Conf 2011
Selenium and Cucumber Selenium Conf 2011
dimakovalenko
 
Continuous (Production) Integration: Ruby on Rails Application Monitoring wit...
Continuous (Production) Integration: Ruby on Rails Application Monitoring wit...Continuous (Production) Integration: Ruby on Rails Application Monitoring wit...
Continuous (Production) Integration: Ruby on Rails Application Monitoring wit...
jnewland
 
BDD in my team: how we do it
BDD in my team: how we do itBDD in my team: how we do it
BDD in my team: how we do it
Darius Kasperavicius
 
Cucumber & gherkin language
Cucumber & gherkin languageCucumber & gherkin language
Cucumber & gherkin language
selvanathankapilan
 
NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020
Milad Heydari
 
Spring, CDI, Jakarta EE good parts
Spring, CDI, Jakarta EE good partsSpring, CDI, Jakarta EE good parts
Spring, CDI, Jakarta EE good parts
Jarek Ratajski
 
OOScss Architecture For Rails Apps
OOScss Architecture For Rails AppsOOScss Architecture For Rails Apps
OOScss Architecture For Rails Apps
Netguru
 
Rails OO views
Rails OO viewsRails OO views
Rails OO views
Elia Schito
 
Upgrade Your Website to HTML5 - VSLive Conference New York @iRajLal
Upgrade Your Website to HTML5 - VSLive Conference New York  @iRajLalUpgrade Your Website to HTML5 - VSLive Conference New York  @iRajLal
Upgrade Your Website to HTML5 - VSLive Conference New York @iRajLal
Raj Lal
 
An Introduction to React -- FED Date -- IBM Design
An Introduction to React -- FED Date -- IBM DesignAn Introduction to React -- FED Date -- IBM Design
An Introduction to React -- FED Date -- IBM Design
Josh Black
 
Behaviour driven infrastructure
Behaviour driven infrastructureBehaviour driven infrastructure
Behaviour driven infrastructure
Lindsay Holmwood
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of Speed
Ilia Idakiev
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with Cucumber
Brandon Keepers
 
Behat - human-readable automated testing
Behat - human-readable automated testingBehat - human-readable automated testing
Behat - human-readable automated testing
nyccamp
 
How to develop Alexa Skill Kit based on Serverless Architecture
How to develop Alexa Skill Kit based on Serverless ArchitectureHow to develop Alexa Skill Kit based on Serverless Architecture
How to develop Alexa Skill Kit based on Serverless Architecture
Hidetaka Okamoto
 
DDD/CQRS - I must learn to repeat myself
DDD/CQRS - I must learn to repeat myselfDDD/CQRS - I must learn to repeat myself
DDD/CQRS - I must learn to repeat myself
Douglas Reith
 
Code Quality Makes Your Job Easier
Code Quality Makes Your Job EasierCode Quality Makes Your Job Easier
Code Quality Makes Your Job Easier
Tonya Mork
 
Behaviour Driven Development
Behaviour Driven DevelopmentBehaviour Driven Development
Behaviour Driven Development
Andy Kelk
 
Cucumber Presentation Kiev Meet Up
Cucumber Presentation Kiev Meet UpCucumber Presentation Kiev Meet Up
Cucumber Presentation Kiev Meet Up
dimakovalenko
 
Selenium and Cucumber Selenium Conf 2011
Selenium and Cucumber Selenium Conf 2011Selenium and Cucumber Selenium Conf 2011
Selenium and Cucumber Selenium Conf 2011
dimakovalenko
 
Continuous (Production) Integration: Ruby on Rails Application Monitoring wit...
Continuous (Production) Integration: Ruby on Rails Application Monitoring wit...Continuous (Production) Integration: Ruby on Rails Application Monitoring wit...
Continuous (Production) Integration: Ruby on Rails Application Monitoring wit...
jnewland
 
NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020NextJS - Online Summit for Frontend Developers September 2020
NextJS - Online Summit for Frontend Developers September 2020
Milad Heydari
 
Spring, CDI, Jakarta EE good parts
Spring, CDI, Jakarta EE good partsSpring, CDI, Jakarta EE good parts
Spring, CDI, Jakarta EE good parts
Jarek Ratajski
 
OOScss Architecture For Rails Apps
OOScss Architecture For Rails AppsOOScss Architecture For Rails Apps
OOScss Architecture For Rails Apps
Netguru
 
Upgrade Your Website to HTML5 - VSLive Conference New York @iRajLal
Upgrade Your Website to HTML5 - VSLive Conference New York  @iRajLalUpgrade Your Website to HTML5 - VSLive Conference New York  @iRajLal
Upgrade Your Website to HTML5 - VSLive Conference New York @iRajLal
Raj Lal
 
An Introduction to React -- FED Date -- IBM Design
An Introduction to React -- FED Date -- IBM DesignAn Introduction to React -- FED Date -- IBM Design
An Introduction to React -- FED Date -- IBM Design
Josh Black
 
Behaviour driven infrastructure
Behaviour driven infrastructureBehaviour driven infrastructure
Behaviour driven infrastructure
Lindsay Holmwood
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of Speed
Ilia Idakiev
 
Behavior Driven Development with Cucumber
Behavior Driven Development with CucumberBehavior Driven Development with Cucumber
Behavior Driven Development with Cucumber
Brandon Keepers
 
Behat - human-readable automated testing
Behat - human-readable automated testingBehat - human-readable automated testing
Behat - human-readable automated testing
nyccamp
 

More from elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
elliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
elliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
Ragel talk
Ragel talkRagel talk
Ragel talk
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
elliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias
 
Rango
RangoRango
Rango
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
elliando dias
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 
Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
elliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
elliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 
Ad

Recently uploaded (20)

Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Vaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without HallucinationsVaibhav Gupta BAML: AI work flows without Hallucinations
Vaibhav Gupta BAML: AI work flows without Hallucinations
john409870
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
MINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PRMINDCTI revenue release Quarter 1 2025 PR
MINDCTI revenue release Quarter 1 2025 PR
MIND CTI
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
Build 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHSBuild 3D Animated Safety Induction - Tech EHS
Build 3D Animated Safety Induction - Tech EHS
TECH EHS Solution
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Ad

Getting Up and Running with BDD on Rails

  • 1. Behavior Driven Development with elegance and joy Getting Up and Running with BDD on Rails Nicholas Cancelliere email: [email protected] twitter: ozmox
  • 2. Overview Behavior Driven Development Basic Concepts Cucumber from 10,000 ft Cucumber in the Rails Environment Writing your first Feature / Scenario Additional Resources
  • 3. Behavior Driven “the next step” from Test-Driven Development tests what an object does rather than what it is intention more important than implementation outside-in approach offers all the benefits of TDD it is not Test-After Development
  • 4. Benefits of TDD/BDD more productive (less debugging, fewer prod defects) helps drive programming design (KISS/YAGNI) delays implementation decisions greater level of code trust code more modularized, flexible and extensible
  • 5. Outside-In User Client Value is in the views! Views Often html but can also be programmatic interfaces (such as XML or JSON), Controllers remember valuable to the user. Model
  • 6. Red Green Refactor write enough test code to fail write just enough code to pass review your work and refactor
  • 7. Red Green Refactor write enough test code to fail write just enough code to pass review your work and refactor
  • 8. Red Green Refactor write enough test code to fail write just enough code to pass review your work and refactor
  • 9. Red Green Refactor write enough test code to fail write just enough code to pass review your work and refactor
  • 10. User Stories concept popular in Agile practices like Scrum and XP define the user’s role, what it is they need/want to do, and why they need/want (the value) As a us e r w i t h an a c o n t ac t s ddre s s b o so I c an e o k , I ne e d As a u s e r a s i l y re t r t o a dd w i t h an a ie ve t h e m e di t/de le t ddre s s b o l ate r. e c o n t ac t o k , I ne e d s so I c an d a te a n d ke e p i t up to m a n ag e a -to- As a us e r ble . w i t h an a my c on t a ddre s s b o c ts to o t h o k , I ne e d e r us e rs t to se nd o be sh a r e d.
  • 11. Pop the Why Stack Ask “Why” up to 5 times Stop when you find the money Protect revenue Increase revenue Manage cost
  • 12. Example Pop’in c: ‘People need to log in.’ d: ‘Why?’ c: ‘Um, identify users?’ d: ‘Why do you need to identify users?’ c: ‘So we know who’s publishing what.’ d: ‘Why would you need to know who publishes what?’ c: ‘If content belongs to someone it seems trustworthy.’ d: ‘Why does content need to be trustworthy?’ c: ‘People will be more interested in the content if so.’ d: ‘Why do you need people interested in the content?’ c: ‘So people come back and visit the site?’ d: ‘Why do you want people to come back and revisit?’ c: ‘More visits will increase our ad revenue.’
  • 13. The Story As an author, I need to log into the site so that articles I create are associated to me and seem trustworthy, driving more traffic to the site.
  • 14. The Story So that articles I create are associated to me, seem trustworthy and drive more traffic to the site, as an author, I need to log in.
  • 15. Enter Cucumber Dan North ported JBehave to Ruby as RBehave RSpec merged RBehave in as the Story Runner First only supported Ruby for scenarios Later supported plain text, but still limited Aslak Hellesøy in 2008 rewrote Story Runner as Cucumber (named so by his fiancée) Cucumber has since taken to a life of it’s own
  • 16. Cucumber written in Ruby itself and best matched with Ruby projects, but can be used for Java, .NET or Flex supports web apps in any language: integrates with Webrat, Watir, Selenium, et. al. Gherkin customization edit /cucumber/languages.yml minimum knowledge of Ruby required, you can pick it up and get going in a few days
  • 17. Gherkin: the ‘unpickle’ variety a business readable, domain specific language that Cucumber understands two-stage parser for input file (plain text): 1. divides the file into sections (eg. feature, scenarios) 2. sections are divided into steps step-definitions are always matched by Ruby methods line-oriented (like YAML); line endings terminate statements (steps) and spaces or tabs to indent
  • 18. Given When Then Used extensively in scenario definitions (Gherkin) Use “And” to chain together Given an invalid user When I go to the sign-in page And I fill in "userlogin" with "baduser" And I fill in "password" with "badpassword" And I submit "new_user_session" Then I should see "Sorry, we could not sign you in." And I should see "Login"
  • 19. Installing in Rails gem install cucumber rspec-rails webrat /config/environments/test.rb config.gem 'rspec-rails', :lib => false config.gem 'rspec', :lib => false config.gem 'cucumber' config.gem 'webrat' rake gems:install RAILS_ENV=test script/generate cucumber script/generate rspec
  • 20. Test::Unit Shoulda http://giantrobots.thoughtbot.com/2009/2/20/mixing- cucumber-with-test-unit /features/support/env.rb # require ‘cucumber/rails/rspec’ # require ‘webrat/rspec-rails’ /features/step_definitions/webrat_steps.rb # replace any matchers that use RSpec syntax Then /^I should see "(.*)"$/ do |text| # response.body.should =~ /#{text}/m assert_match /#{text}/m, @response.body end
  • 21. Out of the Box Webrat comes with a bunch of handy helpers out of the box to make life easy for web application scenarios rake features - task to run all Cucumber tests /features review_past_events.feature /step_definitions event_steps.rb webrat_steps.rb /support env.rb paths.rb
  • 37. Remember... Cucumber defines the features you wish you had. RSpec (or Test::Unit) defines the interactions and objects you wish you had. You’re building a business domain language!
  • 38. A Good Investment Conversation Acceptance Criteria Design Documentation Automated Functional and Integration Tests
  • 39. What do I use? Speed Selenium + Webrat Unit Testing + Integration
  • 40. Cucumber Smells Relying too much on state in your step-definitions Tests with no user value Too much concrete, less abstract
  • 41. Cucumber Smells Relying too much on state in your step-definitions Tests with no user value Too much concrete, less abstract Given /^state$/ do @article = Article.create! end Given /^coupled by state/ do @article.title = ‘Bad’ end
  • 42. Cucumber Smells Relying too much on state in your step-definitions Tests with no user value Too much concrete, less abstract Given /^check the db/ do Article.find(1).should_not == nil end
  • 43. Cucumber Smells Relying too much on state in your step-definitions Tests with no user value Too much concrete, less abstract Given I go to the login page And I fill in “username” with “john” And I fill in “password” with “testpass” And I click “login”
  • 44. Cucumber Smells Relying too much on state in your step-definitions Tests with no user value Too much concrete, less abstract Given I’m logged in
  • 45. Cucumber Smells Relying too much on state in your step-definitions Tests with no user value Too much concrete, less abstract Given /I am logged in/ do @user = User.create!(:login => ‘john’, :password => ‘testpass’) And ‘I fill in “username” with “john”’ And ‘I fill in “password” with “testpass”’ And ‘I click “login”’ end
  • 46. Additional Resources / Topics http://cukes.info The RSpec Book (beta @ PragProg.com) Textmate Bundles are available! Extending Cucumber with World Using Hooks (careful they’re global)