Sha256: 2ecd97ce173e73ea83c44eef1d588beb2d1f7e2d13a6ce34fcee2760d6f71914

Contents?: true

Size: 870 Bytes

Versions: 4

Compression:

Stored size: 870 Bytes

Contents

module AnimalSpecHelper
  class Eat
    def initialize(food)
      @food = food
    end
    
    def matches?(animal)
      @animal = animal
      @animal.eats?(@food)
    end
    
    def failure_message
      "expected #{@animal} to eat #{@food}, but it does not"
    end
    
    def negative_failure_message
      "expected #{@animal} not to eat #{@food}, but it does"
    end
  end
    
  def eat(food)
    Eat.new(food)
  end
end

module Animals
  class Animal
    def eats?(food)
      return foods_i_eat.include?(food)
    end
  end
  
  class Mouse < Animal
    def foods_i_eat
      [:cheese]
    end
  end
end

context "A mouse" do
  include AnimalSpecHelper
  setup do
    @mouse = Animals::Mouse.new
  end
  
  specify "should eat cheese" do
    @mouse.should eat(:cheese)
  end
  
  specify "should not eat cat" do
    @mouse.should_not eat(:cat)
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
riess-0.0.8 vendor/rspec-0.8.2/examples/custom_expectation_matchers.rb
rspec-0.8.0 examples/custom_expectation_matchers.rb
rspec-0.8.1 examples/custom_expectation_matchers.rb
rspec-0.8.2 examples/custom_expectation_matchers.rb