require 'a_more_declarative_rspec'
context "empty" do
@stack = Stack.new :limit => 10
end
context "one item" => "empty" do
@stack.push 10
end
context "almost full" => "empty" do
(2..10).each{ |i| @stack.push i }
end
context "full" => "empty" do
(1..10).each{ |i| @stack.push i }
end
context_group "not empty" => [ "one item", "almost full", "full" ]
context_group "not full" => [ "empty", "one item", "almost full" ]
behavior "should accept an item when sent push" => "not full" do
lambda{ @stack.push Object.new }.should.not.raise
end
behavior "should complain when sent top" => "empty" do
lambda{ @stack.top }.should.raise StackUnderflowError
end
behavior "should complain when sent pop" => "empty" do
lambda{ @stack.pop }.should.raise StackUnderflowError
end
behavior "should return top when sent top" => "not empty" do
@stack.top.should.be 10
end
behavior "should not remove top when sent top" => "not empty" do
@stack.top.should.be 10
@stack.top.should.be 10
end
behavior "should return top when sent pop" => "not empty" do
@stack.pop.should.be 10
end
behavior "should remove top when sent pop" => "not empty" do
@stack.pop.should.be 10
contexts "almost full", "full" do
@stack.top.should.be 9
end
contexts "one item" do
lambda{ @stack.top }.should.raise StackUnderflowError
end
end
behavior "should remove top when sent pop" => "one item" do
@stack.pop.should.be 10
end
behavior "should complain on push" => "full" do
lambda{ @stack.push Object.new }.should.raise StackOverflowError
end
What I like: