Skip to content

Instantly share code, notes, and snippets.

@meara
Created November 19, 2013 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meara/7551834 to your computer and use it in GitHub Desktop.
Save meara/7551834 to your computer and use it in GitHub Desktop.
Cookies in Ovens
require 'rspec'
describe Cookie do
let(:cookie) { Cookie.new("oatmeal", 10) }
context '#initialize' do
it 'creates a Cookie object' do
cookie.should be_an_instance_of Cookie
end
it 'requires two parameters' do
expect { Cookie.new }.to raise_error
end
it 'has a valid type' do
expect { Cookie.new(10, 10) }.to raise_error
end
it 'has a numeric baketime' do
expect { Cookie.new('chocolate', 'chip') }.to raise_error
end
end
end
describe Batch do
let(:batch) { Batch.new(24, "oatmeal", 10) }
context '#initialize' do
it 'creates an Batch object' do
batch.should be_an_instance_of Batch
end
it 'requires four parameters' do
expect { Batch.new }.to raise_error
end
end
context '#cookies' do
it 'returns an array' do
batch.cookies.should be_an_instance_of Array
end
it 'has a cookie object in the array' do
batch.cookies[0].should be_an_instance_of Cookie
end
it 'has correct number of cookies' do
batch.cookies.length.should eq 24
end
end
context '#baketime' do
it 'has correct baketime' do
batch.baketime.should eq 10
end
end
context '#done' do
it "requires a parameter" do
expect { Batch.new(10, "good", 10).done }.to raise_error
end
it 'returns true if batch is done' do
expect { Batch.new(10, "good", 10).done(10) }.to be_true
end
it 'returns true if batch is done' do
expect { Batch.new(10, "good", 10).done(8) }.to be_false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment