changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/examples/pure/custom_expectation_matchers.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1module 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
24end
25
26module 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
54end