Skip to content

Instantly share code, notes, and snippets.

@joefiorini
Created December 12, 2008 02:23
Show Gist options
  • Save joefiorini/34994 to your computer and use it in GitHub Desktop.
Save joefiorini/34994 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment