• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
473
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
6
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Athens Ruby 16/3/2012meetup #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.comAthens 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 CucumberAthens ruby meetup #8 16/3/2012
  • 5. Cucumber ● Higher level ● Closer to natural language (any language, even LOLspeak!) ● Tests application behaviorAthens ruby meetup #8 16/3/2012
  • 6. Cucumber – FeaturesFeature: 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 definitionsGiven /^I have uploaded a picture$/ do @first = Submission.new(title: “My 1337 cat!”, image: File.open Rails.root + “tmp/sample1.jpg”)endWhen /^I upload another picture$/ do @another = Submission.new(title: “My cat again”, image: File.open Rails.root + “tmp/sample2.jpg”)endThen /^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 behaviourAthens ruby meetup #8 16/3/2012
  • 9. RSpecdescribe “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 endend Athens ruby meetup #8 16/3/2012
  • 10. Demo appAthens ruby meetup #8 16/3/2012
  • 11. Related libraries and tools ● FactoryGirl ● Capybara ● Selenium ● Guard ● SporkAthens ruby meetup #8 16/3/2012
  • 12. Thanks!Athens ruby meetup #8 16/3/2012