faithfulgeek (owner)

Forks

Revisions

gist: 34994 Download_button fork
public
Public Clone URL: git://gist.github.com/34994.git
Embed All Files: show embed
rdingus.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'rubygems'
require 'spec'
 
class Person
  attr_accessor :name
  attr_accessor :shoe_size
 
  def eat(sandwich)
    sandwich.cut_in_half
    sandwich.eaten = true
  end
 
end
 
class RDingus
 
  def initialize
    @list = []
  end
 
  def method_missing(name, *args)
    @list << "something"
  end
 
  def calls(name)
    @list
  end
 
  def calls?(name)
    true
  end
end
 
describe "A person" do
    describe "when specifying a shoe size" do
 
      it "should save the shoe size" do
        p = Person.new
        p.shoe_size = 4
        p.shoe_size.should == 4
      end
 
  end
 
  it "should be able to eat a sandwich" do
    sandwich = RDingus.new
    person = Person.new
    person.eat(sandwich)
    sandwich.calls?(:eaten=).should be_true
  end
 
end
 
describe "RDingus" do
  describe "when asserting calls" do
    before(:each) do
      @sandwich = RDingus.new
    end
    it "should return a list of methods called" do
      @sandwich.eaten = true
      @sandwich.calls(:eaten=).length.should == 1
    end
 
    it "should record multiple identical calls" do
      2.times do
        @sandwich.eaten = true
      end
      @sandwich.calls(:eaten=).length.should == 2
    end
  end
end