changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/examples/pure/stack_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/spec_helper'
2require File.dirname(__FILE__) + "/stack"
3require File.dirname(__FILE__) + '/shared_stack_examples'
4
5describe Stack, " (empty)" do
6 before(:each) do
7 @stack = Stack.new
8 end
9
10 # NOTE that this one auto-generates the description "should be empty"
11 it { @stack.should be_empty }
12
13 it_should_behave_like "non-full Stack"
14
15 it "should complain when sent #peek" do
16 lambda { @stack.peek }.should raise_error(StackUnderflowError)
17 end
18
19 it "should complain when sent #pop" do
20 lambda { @stack.pop }.should raise_error(StackUnderflowError)
21 end
22end
23
24describe Stack, " (with one item)" do
25 before(:each) do
26 @stack = Stack.new
27 @stack.push 3
28 @last_item_added = 3
29 end
30
31 it_should_behave_like "non-empty Stack"
32 it_should_behave_like "non-full Stack"
33
34end
35
36describe Stack, " (with one item less than capacity)" do
37 before(:each) do
38 @stack = Stack.new
39 (1..9).each { |i| @stack.push i }
40 @last_item_added = 9
41 end
42
43 it_should_behave_like "non-empty Stack"
44 it_should_behave_like "non-full Stack"
45end
46
47describe Stack, " (full)" do
48 before(:each) do
49 @stack = Stack.new
50 (1..10).each { |i| @stack.push i }
51 @last_item_added = 10
52 end
53
54 # NOTE that this one auto-generates the description "should be full"
55 it { @stack.should be_full }
56
57 it_should_behave_like "non-empty Stack"
58
59 it "should complain on #push" do
60 lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
61 end
62
63end