SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
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
 

Kürzlich hochgeladen (20)

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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
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
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

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