Sha256: 0d61e363d7c17bbb63f58b502d9cd80b65086973bae6df58c28d797d421584d7

Contents?: true

Size: 1.26 KB

Versions: 33

Compression:

Stored size: 1.26 KB

Contents

$:.push File.join(File.dirname(__FILE__), *%w[.. .. lib])
require 'spec'

class AdditionMatchers < Spec::Story::StepGroup
  steps do |add|
    add.given("an addend of $addend") do |addend|
      @adder ||= Adder.new
      @adder << addend.to_i
    end
  end
end

steps = AdditionMatchers.new do |add|  
  add.then("the sum should be $sum") do |sum|
    @sum.should == sum.to_i
  end
end

steps.when("they are added") do
  @sum = @adder.sum
end

# This Story uses steps (see above) instead of blocks
# passed to Given, When and Then

Story "addition", %{
  As an accountant
  I want to add numbers
  So that I can count some beans
}, :steps_for => steps do
  Scenario "2 + 3" do
    Given "an addend of 2"
    And "an addend of 3"
    When "they are added"
    Then "the sum should be 5"
  end
  
  # This scenario uses GivenScenario, which silently runs
  # all the steps in a previous scenario.
  
  Scenario "add 4 more" do
    GivenScenario "2 + 3"
    Given "an addend of 4"
    When "they are added"
    Then "the sum should be 9"
  end
end

# And the class that makes the story pass

class Adder
  def << addend
    addends << addend
  end
  
  def sum
    @addends.inject(0) do |result, addend|
      result + addend.to_i
    end
  end
  
  def addends
    @addends ||= []
  end
end

Version data entries

33 entries across 33 versions & 8 rubygems

Version Path
dchelimsky-rspec-1.1.10 examples/stories/calculator.rb
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec/examples/stories/calculator.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/examples/stories/calculator.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/examples/stories/calculator.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/examples/stories/calculator.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/calculator.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/calculator.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/calculator.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/calculator.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/calculator.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/examples/stories/calculator.rb
pictrails-0.5.0 vendor/plugins/rspec/examples/stories/calculator.rb
radiant-0.6.5.1 vendor/plugins/rspec/examples/stories/calculator.rb
radiant-0.6.5 vendor/plugins/rspec/examples/stories/calculator.rb
radiant-0.6.7 vendor/plugins/rspec/examples/stories/calculator.rb
radiant-0.6.6 vendor/plugins/rspec/examples/stories/calculator.rb
radiant-0.6.9 vendor/plugins/rspec/examples/stories/calculator.rb
radiant-0.6.8 vendor/plugins/rspec/examples/stories/calculator.rb
rspec-0.0.10 examples/stories/calculator.rb
rspec-1.1.10 examples/stories/calculator.rb