Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions spec/stack_spec.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
require 'stack'

describe Stack do
let(:stack) { Stack.new }

context 'by default' do
it 'starts out empty' do
stack.empty?.should be_true
subject.should be_empty
end
end

context 'pushing elements' do
it 'can be pushed an element' do
stack.should be_empty
stack.push(1)
stack.size.should == 1
subject.push(1)
subject.size.should == 1
end

it 'can be pushed many elements at once' do
stack.should be_empty
stack.push(1, 2, 3, 4, 5)
stack.size.should == 5
subject.push(1, 2, 3, 4, 5)
subject.size.should == 5
end
end

context 'popping elements' do
it 'allows you to pop the last pushed element' do
stack.push(:foo, :bar)
stack.pop.should == :bar
stack.pop.should == :foo
stack.should be_empty
subject.push(:foo, :bar)
subject.pop.should == :bar
subject.pop.should == :foo
subject.should be_empty
end

it 'raises when popping an empty stack' do
stack.should be_empty
expect { stack.pop }.to raise_error(Stack::EmptyStackError)
subject.should be_empty
expect { subject.pop }.to raise_error(Stack::EmptyStackError)
end
end
end