Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment