SlideShare a Scribd company logo
1 of 12
Download to read offline
Athens Ruby                    16/3/2012
meetup #8




    Testing and BDD with
    RSpec and Cucumber

         Theodoros Orfanidis
              (aka @teoulas)
About me


     ●
         Web developer
     ●
         Ruby lover
     ●
         Cat lover �
     ●
         Tech lead at incrediblue.com



Athens ruby meetup #8                   16/3/2012
BDD concepts


     ●
         Describe what your system does
         (Given, When, Then)
     ●
         Write features/specs first, code later
     ●
         Red-Green-Refactor cycle (just like TDD)



Athens ruby meetup #8                               16/3/2012
BDD cycle

                                     1



                                     2




                            4               3


                                  RSpec

                        6                       5

                                 Cucumber


Athens ruby meetup #8                               16/3/2012
Cucumber


     ●
         Higher level
     ●
         Closer to natural language
         (any language, even LOLspeak!)
     ●
         Tests application behavior



Athens ruby meetup #8                     16/3/2012
Cucumber – Features

Feature: LOLcat competition submission
  In order to win the competition
  As a cat owner
  I want to submit a cat picture
  Scenario: Cat owner submits picture
    Given I have a cat
    And I have a funny picture of her
    When I upload the picture
    Then I should see “KTHX! Bai!”
  Scenario: Cat owner submits a second picture
    Given I have already uploaded a picture
    When I upload another picture
    Then I should see “Oh noes, naughty boi!”
    And I should see my previous submission


 Athens ruby meetup #8                           16/3/2012
Cucumber – Step definitions

Given /^I have uploaded a picture$/ do
  @first = Submission.new(title: “My 1337 cat!”,
    image: File.open Rails.root + “tmp/sample1.jpg”)
end
When /^I upload another picture$/ do
  @another = Submission.new(title: “My cat again”,
    image: File.open Rails.root + “tmp/sample2.jpg”)
end

Then /^I should see “([^”]*)”$/ do |msg|
  page.should have_content(msg)
end




 Athens ruby meetup #8                                 16/3/2012
RSpec



     ●
         Lower level
     ●
         Closer to code
     ●
         Tests object behaviour




Athens ruby meetup #8             16/3/2012
RSpec

describe “submission” do
  it “should allow jpg images” do
    sub = Submission.new(title: “Cat”,
      image: File.open Rails.root + “tmp/sample.jpg”)
    sub.should be_valid
  end
  it “should not allow gif images” do
    sub = Submission.new(title: “Cat”,
      image: File.open Rails.root + “tmp/animated.gif”)
    sub.should_not be_valid
  end
end




 Athens ruby meetup #8                                    16/3/2012
Demo app




Athens ruby meetup #8              16/3/2012
Related libraries and tools


     ●
         FactoryGirl
     ●
         Capybara
     ●
         Selenium
     ●
         Guard
     ●
         Spork


Athens ruby meetup #8                  16/3/2012
Thanks!




Athens ruby meetup #8             16/3/2012

More Related Content

Similar to Athens Ruby meetup #8

Rapid RIA development with Netzke
Rapid RIA development with NetzkeRapid RIA development with Netzke
Rapid RIA development with Netzke
netzke
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
Manoj Kumar
 
Enjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProfEnjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProf
mametter
 
How to discover the Ruby's defects with web application
How to discover the Ruby's defects with web applicationHow to discover the Ruby's defects with web application
How to discover the Ruby's defects with web application
Hiroshi SHIBATA
 

Similar to Athens Ruby meetup #8 (20)

Merb The Super Bike Of Frameworks
Merb The Super Bike Of FrameworksMerb The Super Bike Of Frameworks
Merb The Super Bike Of Frameworks
 
Fukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - OpalFukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - Opal
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Rapid RIA development with Netzke
Rapid RIA development with NetzkeRapid RIA development with Netzke
Rapid RIA development with Netzke
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Enjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProfEnjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProf
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
rubyonrails
rubyonrailsrubyonrails
rubyonrails
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
How to discover the Ruby's defects with web application
How to discover the Ruby's defects with web applicationHow to discover the Ruby's defects with web application
How to discover the Ruby's defects with web application
 
The Future of Dependency Management for Ruby
The Future of Dependency Management for RubyThe Future of Dependency Management for Ruby
The Future of Dependency Management for Ruby
 
Go at Skroutz
Go at SkroutzGo at Skroutz
Go at Skroutz
 
Rails Development That Doesn't Hurt
Rails Development That Doesn't HurtRails Development That Doesn't Hurt
Rails Development That Doesn't Hurt
 
2016-05-12 DCRUG React.rb
2016-05-12 DCRUG React.rb2016-05-12 DCRUG React.rb
2016-05-12 DCRUG React.rb
 
Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013Rspec and Capybara Intro Tutorial at RailsConf 2013
Rspec and Capybara Intro Tutorial at RailsConf 2013
 
Introduction to RDoc
Introduction to RDocIntroduction to RDoc
Introduction to RDoc
 
Introduction to RDoc
Introduction to RDocIntroduction to RDoc
Introduction to RDoc
 
Puppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven Development
 
20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris
 
Ruby on Rails: a brief introduction
Ruby on Rails: a brief introductionRuby on Rails: a brief introduction
Ruby on Rails: a brief introduction
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Athens Ruby meetup #8

  • 1. Athens Ruby 16/3/2012 meetup #8 Testing and BDD with RSpec and Cucumber Theodoros Orfanidis (aka @teoulas)
  • 2. About me ● Web developer ● Ruby lover ● Cat lover � ● Tech lead at incrediblue.com Athens ruby meetup #8 16/3/2012
  • 3. BDD concepts ● Describe what your system does (Given, When, Then) ● Write features/specs first, code later ● Red-Green-Refactor cycle (just like TDD) Athens ruby meetup #8 16/3/2012
  • 4. BDD cycle 1 2 4 3 RSpec 6 5 Cucumber Athens ruby meetup #8 16/3/2012
  • 5. Cucumber ● Higher level ● Closer to natural language (any language, even LOLspeak!) ● Tests application behavior Athens ruby meetup #8 16/3/2012
  • 6. Cucumber – Features Feature: LOLcat competition submission In order to win the competition As a cat owner I want to submit a cat picture Scenario: Cat owner submits picture Given I have a cat And I have a funny picture of her When I upload the picture Then I should see “KTHX! Bai!” Scenario: Cat owner submits a second picture Given I have already uploaded a picture When I upload another picture Then I should see “Oh noes, naughty boi!” And I should see my previous submission Athens ruby meetup #8 16/3/2012
  • 7. Cucumber – Step definitions Given /^I have uploaded a picture$/ do @first = Submission.new(title: “My 1337 cat!”, image: File.open Rails.root + “tmp/sample1.jpg”) end When /^I upload another picture$/ do @another = Submission.new(title: “My cat again”, image: File.open Rails.root + “tmp/sample2.jpg”) end Then /^I should see “([^”]*)”$/ do |msg| page.should have_content(msg) end Athens ruby meetup #8 16/3/2012
  • 8. RSpec ● Lower level ● Closer to code ● Tests object behaviour Athens ruby meetup #8 16/3/2012
  • 9. RSpec describe “submission” do it “should allow jpg images” do sub = Submission.new(title: “Cat”, image: File.open Rails.root + “tmp/sample.jpg”) sub.should be_valid end it “should not allow gif images” do sub = Submission.new(title: “Cat”, image: File.open Rails.root + “tmp/animated.gif”) sub.should_not be_valid end end Athens ruby meetup #8 16/3/2012
  • 10. Demo app Athens ruby meetup #8 16/3/2012
  • 11. Related libraries and tools ● FactoryGirl ● Capybara ● Selenium ● Guard ● Spork Athens ruby meetup #8 16/3/2012