Introductory presentation with basic examples for the use of Cucumber and Rspec to do testing in Ruby.
http://github.com/jwthompson2/barcamp-nola-2009/
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. WHAT IS RSPEC
•Behavior driven development tool for Ruby
•Provides a DSL for talking about what code should do
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. 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
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. 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