]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/examples/pure/stack_spec_with_nested_example_groups.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / examples / pure / stack_spec_with_nested_example_groups.rb
1 require File.dirname(__FILE__) + '/spec_helper'
2 require File.dirname(__FILE__) + '/stack'
3 require File.dirname(__FILE__) + '/shared_stack_examples'
4
5 describe Stack do
6   
7   before(:each) do
8     @stack = Stack.new
9   end
10
11   describe "(empty)" do
12
13     it { @stack.should be_empty }
14   
15     it_should_behave_like "non-full Stack"
16   
17     it "should complain when sent #peek" do
18       lambda { @stack.peek }.should raise_error(StackUnderflowError)
19     end
20   
21     it "should complain when sent #pop" do
22       lambda { @stack.pop }.should raise_error(StackUnderflowError)
23     end
24
25   end
26
27   describe "(with one item)" do
28     
29     before(:each) do
30       @stack.push 3
31       @last_item_added = 3
32     end
33
34     it_should_behave_like "non-empty Stack"
35     it_should_behave_like "non-full Stack"
36
37   end
38
39   describe "(with one item less than capacity)" do
40     
41     before(:each) do
42       (1..9).each { |i| @stack.push i }
43       @last_item_added = 9
44     end
45   
46     it_should_behave_like "non-empty Stack"
47     it_should_behave_like "non-full Stack"
48   end
49
50   describe "(full)" do
51     
52     before(:each) do
53       (1..10).each { |i| @stack.push i }
54       @last_item_added = 10
55     end
56
57     it { @stack.should be_full }  
58
59     it_should_behave_like "non-empty Stack"
60
61     it "should complain on #push" do
62       lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
63     end
64   
65   end
66
67 end