Created
May 8, 2012 21:43
-
-
Save michel/2639612 to your computer and use it in GitHub Desktop.
grow a test suite
This file contains hidden or 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
class Walrus | |
attr_reader :energy | |
def initialize | |
@energy = 0 | |
end | |
def receive_gift!(gift) | |
if gift.edible? | |
@energy += gift.digest.energy | |
end | |
end | |
end | |
class LifeEvent | |
attr_reader :energy | |
def initialize(params) | |
@energy = params.fetch(:energy) | |
end | |
end | |
describe Walrus do | |
it "gains energy from eatable things" do | |
cheese = stub( :edible? => true , :digest => LifeEvent.new(:energy => 100)) | |
expect do | |
subject.receive_gift!(cheese) | |
end.to change {subject.energy }.by(100) | |
end | |
it "does not gain energy form non-foof" do | |
shoe = stub(:edibile? => false) | |
expect do | |
subject.receive_gift!(shoe) | |
end.not_to { subject.energy } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment