Created
December 23, 2008 02:40
-
-
Save jonathanpenn/39230 to your computer and use it in GitHub Desktop.
Some examples on how RDingus might be used.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__)+"/spec_helper.rb" | |
class Person | |
def initialize(name) | |
@name = name | |
end | |
def name | |
@name | |
end | |
def eat(food) | |
case food.kind | |
when "Sandwich" | |
food.bite | |
if food.has_cheese? | |
"yum!" | |
else | |
"yuck!" | |
end | |
when "Cookie" | |
food.bite | |
food.bite(:all) | |
"yum!" | |
else | |
food.spit_out | |
end | |
end | |
def clean(room, opts={}) | |
tool = opts[:with] | |
room.sink.rinse if room.has_sink? | |
room.tub.rinse if room.has_tub? | |
tool.sweep room.floor if tool && tool.instance_of?(Broom) | |
end | |
end | |
class Broom; end | |
describe "A Person" do | |
before :each do | |
@person = Person.new "Clyde" | |
end | |
it "should have a name" do | |
@person.name.should == "Clyde" | |
end | |
describe "when eating" do | |
describe "a sandwich" do | |
before :each do | |
@sandwich = RDingus.new | |
@sandwich._define.kind { "Sandwich" } | |
end | |
it "should take a bite" do | |
@response = @person.eat(@sandwich) | |
@sandwich._calls.should include(:bite) | |
end | |
describe "with cheese" do | |
before :each do | |
@sandwich._define.has_cheese? { true } | |
@response = @person.eat(@sandwich) | |
end | |
it "should say 'yum!'" do | |
@response.should == "yum!" | |
end | |
end | |
describe "without cheese" do | |
before :each do | |
@sandwich._define.has_cheese? { false } | |
@response = @person.eat(@sandwich) | |
end | |
it "should say 'yuck!'" do | |
@response.should == "yuck!" | |
end | |
end | |
end | |
describe "a cookie" do | |
before :each do | |
@cookie = RDingus.new | |
@cookie._define.kind { "Cookie" } | |
@response = @person.eat(@cookie) | |
end | |
it "should take a bite" do | |
@cookie._calls.should include(:bite) | |
end | |
it "should bite again" do | |
@cookie._calls.filter(:bite)[1].method.should == :bite | |
end | |
it "should bite the rest of the cookie" do | |
@cookie._calls.filter(:bite)[1].args.should == [:all] | |
end | |
it "should say 'yum!'" do | |
@response.should == "yum!" | |
end | |
end | |
describe "a squid" do | |
it "should spit it out" do | |
@squid = RDingus.new | |
@person.eat(@squid) | |
@squid._calls.should include(:spit_out) | |
end | |
end | |
end | |
describe "when cleaning" do | |
before :each do | |
@room = RDingus.new | |
end | |
describe "the kitchen" do | |
before :each do | |
@room._define.has_sink? { true } | |
@person.clean(@room) | |
end | |
it "should access the sink" do | |
@room._calls.should include(:sink) | |
end | |
it "should rinse the sink" do | |
@room._calls[:sink]._calls.should include(:rinse) | |
end | |
end | |
describe "the bathroom" do | |
before :each do | |
@room._define do |d| | |
d.has_sink? { true } | |
d.has_tub? { true } | |
end | |
@person.clean(@room) | |
end | |
it "should access the sink" do | |
@room._calls.should include(:sink) | |
end | |
it "should rinse the sink" do | |
@room._calls[:sink]._calls.should include(:rinse) | |
end | |
it "should access the tub" do | |
@room._calls.should include(:tub) | |
end | |
it "should rinse the tub" do | |
@room._calls[:tub]._calls.should include(:rinse) | |
end | |
end | |
describe "when given a broom" do | |
before :each do | |
@broom = RDingus.new | |
@person.clean(@room, :with => @broom) | |
end | |
it "should sweep with the broom" do | |
@broom._calls.should include(:sweep) | |
end | |
it "should sweep the floor" do | |
@room._calls.should include(:floor) | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment