Ruby Testing: Cucumber and RSpec

7,920 views
7,726 views

Published on

Introductory presentation with basic examples for the use of Cucumber and Rspec to do testing in Ruby.

http://github.com/jwthompson2/barcamp-nola-2009/

Published in: Technology, Self Improvement
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,920
On SlideShare
0
From Embeds
0
Number of Embeds
49
Actions
Shares
0
Downloads
133
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Ruby Testing: Cucumber and RSpec

  1. 1. RUBY TESTING Cucumber and RSpec
  2. 2. WHO IS THIS GUY? James Thompson @plainprogrammer james@plainprograms.com Web Administrator & Student @ New Orleans Baptist Theological Seminary
  3. 3. WHY DO WE TEST?
  4. 4. WHAT DO WE TEST?
  5. 5. WHAT DON’T WE TEST?
  6. 6. HOW DO WE TEST?
  7. 7. WHAT DO WE TEST WITH?
  8. 8. WHAT IS CUCUMBER •Behavior driven development tool for Ruby •Focuses on higher level implementations such as acceptance tests •Focuses on story-style, plain English test descriptions •Follows the GWT (Given, When, Then) pattern for features
  9. 9. WHAT IS RSPEC •Behavior driven development tool for Ruby •Provides a DSL for talking about what code should do
  10. 10. A POSSIBLE PROCESS •Start with a feature •Define the steps for your feature •Write lower-level specs •Write code to pass specs •Rinse and Repeat until feature passes
  11. 11. WRITE A FEATURE # features/calculator.feature Feature: Addition In Order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers Scenario: Add two numbers Given I have entered 50 into the calculator And I have entered 70 into the calculator When I press add Then the result should be 120 on the screen
  12. 12. WRITE STEPS # features/step_definitions/calculator_steps.rb Given /I have entered (.*) into the calculator/ do |n| calculator = Calculator.new calculator.push(n.to_i) end
  13. 13. WRITE SPECS # spec/calculator.spec describe Calculator do before(:each) do @calculator = Calculator.new end it "should respond to push()" do @calculator.should respond_to(:push) end it "should respond to add()" do @calculator.should respond_to(:add) end end
  14. 14. CODE UNTIL YOU PASS class Calculator def push(n) @args ||= [] @args << n end def add result = 0 @args.each do |n| result += n end result end end
  15. 15. RINSE AND REPEAT
  16. 16. QUESTIONS?
  17. 17. MORE RESOURCES cukes.info rspec.info

×