Skip to content

Instantly share code, notes, and snippets.

@chelseakomlo
Created February 26, 2013 04:16
Show Gist options
  • Save chelseakomlo/5035826 to your computer and use it in GitHub Desktop.
Save chelseakomlo/5035826 to your computer and use it in GitHub Desktop.
For some reason, the stub to work for remaining slices wouldn't stick, and it kept coming back as a random number.
describe "#slice" do
context "when given no parameters" do
it "returns removes one slice of the apple" do
apple = Fruit::Apple.new
apple.stub(:remaining_slices).and_return(5)
expect(apple.slice).to eq 1
end
it "reports the correct number of remaining slices" do
apple = Fruit::Apple.new
apple.stub(:remaining_slices).and_return(5)
apple.slice
expect(apple.remaining_slices).to eq 4
end
end
context "when given a number of slices parameter" do
it "returns the correct number of slices" do
apple = Fruit::Apple.new
apple.stub(:remaining_slices).and_return(5)
expect(apple.slice(2)).to eq 2
end
it "reports the correct number of remaining slices" do
apple = Fruit::Apple.new
apple.stub(:remaining_slices).and_return(5)
apple.slice(2)
expect(apple.remaining_slices).to eq 3
end
end
context "when given a number of slices parameter greater than the remaining slices" do
it "returns the number of remaining slices" do
apple = Fruit::Apple.new
apple.stub(:remaining_slices).and_return(5)
expect(apple.slice(9)).to eq 5
end
it "returns the correct number of remaining slices" do
apple = Fruit::Apple.new
apple.stub(:remaining_slices).and_return(5)
apple.slice(9)
expect(apple.remaining_slices).to eq 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment