Sha256: 0506eff66ab3967fc0e32e802dcf7ccff985140028370d858da0e75e13d7683e

Contents?: true

Size: 869 Bytes

Versions: 3

Compression:

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

3 entries across 3 versions & 1 rubygems

Version Path
picolena-0.1.6 rails_plugins/rspec/examples/pure/custom_expectation_matchers.rb
picolena-0.1.7 rails_plugins/rspec/examples/pure/custom_expectation_matchers.rb
picolena-0.1.8 rails_plugins/rspec/examples/pure/custom_expectation_matchers.rb