]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/examples/pure/custom_expectation_matchers.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / examples / pure / custom_expectation_matchers.rb
1 module AnimalSpecHelper
2   class Eat
3     def initialize(food)
4       @food = food
5     end
6     
7     def matches?(animal)
8       @animal = animal
9       @animal.eats?(@food)
10     end
11     
12     def failure_message
13       "expected #{@animal} to eat #{@food}, but it does not"
14     end
15     
16     def negative_failure_message
17       "expected #{@animal} not to eat #{@food}, but it does"
18     end
19   end
20     
21   def eat(food)
22     Eat.new(food)
23   end
24 end
25
26 module Animals
27   class Animal
28     def eats?(food)
29       return foods_i_eat.include?(food)
30     end
31   end
32   
33   class Mouse < Animal
34     def foods_i_eat
35       [:cheese]
36     end
37   end
38
39   describe Mouse do
40     include AnimalSpecHelper
41     before(:each) do
42       @mouse = Animals::Mouse.new
43     end
44   
45     it "should eat cheese" do
46       @mouse.should eat(:cheese)
47     end
48   
49     it "should not eat cat" do
50       @mouse.should_not eat(:cat)
51     end
52   end
53
54 end