Sha256: c2e690ce99bd572b40945fe516e087139c3ac8a8677645519df651e46dd59b00

Contents?: true

Size: 1.51 KB

Versions: 55

Compression:

Stored size: 1.51 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'
require File.dirname(__FILE__) + "/stack"
require File.dirname(__FILE__) + '/shared_stack_examples'

describe Stack, " (empty)" do
  before(:each) do
    @stack = Stack.new
  end
  
  # This uses @stack (because the described class is Stack) auto-generates the
  # description "should be empty"
  it { should be_empty }
  
  it_should_behave_like "non-full Stack"
  
  it "should complain when sent #peek" do
    lambda { @stack.peek }.should raise_error(StackUnderflowError)
  end
  
  it "should complain when sent #pop" do
    lambda { @stack.pop }.should raise_error(StackUnderflowError)
  end
end

describe Stack, " (with one item)" do
  before(:each) do
    @stack = Stack.new
    @stack.push 3
    @last_item_added = 3
  end

  it_should_behave_like "non-empty Stack"
  it_should_behave_like "non-full Stack"

end

describe Stack, " (with one item less than capacity)" do
  before(:each) do
    @stack = Stack.new
    (1..9).each { |i| @stack.push i }
    @last_item_added = 9
  end
  
  it_should_behave_like "non-empty Stack"
  it_should_behave_like "non-full Stack"
end

describe Stack, " (full)" do
  before(:each) do
    @stack = Stack.new
    (1..10).each { |i| @stack.push i }
    @last_item_added = 10
  end

  # NOTE that this one auto-generates the description "should be full"
  it { @stack.should be_full }  

  it_should_behave_like "non-empty Stack"

  it "should complain on #push" do
    lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
  end
  
end

Version data entries

55 entries across 55 versions & 6 rubygems

Version Path
dchelimsky-rspec-1.1.11.1 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.11.2 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.11.3 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.11.4 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.11.5 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.11.6 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.11.7 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.11 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.12 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.1 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.13 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.2 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.3 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.4 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.5 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.6 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.7 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.8 examples/passing/stack_spec.rb
dchelimsky-rspec-1.1.99.9 examples/passing/stack_spec.rb
newbamboo-evented-rspec-1.1.12 examples/passing/stack_spec.rb