Skip to content

Instantly share code, notes, and snippets.

@michel
Created May 8, 2012 21:43
Show Gist options
  • Save michel/2639612 to your computer and use it in GitHub Desktop.
Save michel/2639612 to your computer and use it in GitHub Desktop.
grow a test suite
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