require 'stack' describe Stack do before do @stack = Stack.new end it 'should be empty' do @stack.should be_empty end it 'should have no element on top' do lambda { @stack.top }.should raise_error(Test::Unit::AssertionFailedError) end it 'should not be possible to pop an element' do lambda { @stack.pop }.should raise_error(Stack::NoPopForEmptyStack) end it 'a pushed element should be on the top' do element = 0 @stack.push(element) @stack.should_not be_empty @stack.top.should be_equal(element) @stack.pop.should be_equal(element) @stack.should be_empty end end