diff --git a/spec/stack_spec.rb b/spec/stack_spec.rb index 07a5f25..d0cafb8 100644 --- a/spec/stack_spec.rb +++ b/spec/stack_spec.rb @@ -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