Sha256: ee6ae84a0b5220b30392a0c9f9ec5576bf5e2e680612d00dd8f53443a3e17656

Contents?: true

Size: 891 Bytes

Versions: 154

Compression:

Stored size: 891 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

  describe Mouse do
    include AnimalSpecHelper
    before(:each) do
      @mouse = Animals::Mouse.new
    end
  
    it "should eat cheese" do
      @mouse.should eat(:cheese)
    end
  
    it "should not eat cat" do
      @mouse.should_not eat(:cat)
    end
  end

end

Version data entries

154 entries across 154 versions & 22 rubygems

Version Path
dchelimsky-rspec-1.1.10 examples/pure/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.11.1 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.11.2 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.11.3 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.11.4 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.11.5 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.11.6 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.11.7 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.11 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.12 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.1 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.13 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.2 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.3 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.4 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.5 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.6 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.7 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.8 examples/passing/custom_expectation_matchers.rb
dchelimsky-rspec-1.1.99.9 examples/passing/custom_expectation_matchers.rb