Created
March 12, 2013 07:14
-
-
Save woodie/5140893 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# jruby -S rspec -fs spec/g_stack_spec.rb | |
require 'java' | |
import 'cis.GStack' | |
import 'cis.StackException' | |
describe GStack, 'once created' do | |
# create a GStack | |
before(:each) do | |
@stack = GStack.new | |
end | |
# public boolean isEmpty() | |
it 'should be empty' do | |
@stack.should be_empty | |
end | |
# public void push(T newItem) | |
it 'should accept an item with push' do | |
%w{foo bar baz}.each {|s| @stack.push(s)} | |
@stack.should_not be_empty | |
end | |
# public void push(T newItem) throws StackException | |
it 'should raise an error on push' | |
# public void popAll() | |
it 'should clear the stack' do | |
%w{foo bar baz}.each {|s| @stack.push(s)} | |
@stack.pop_all | |
@stack.should be_empty | |
end | |
# public T pop() | |
it 'should pop off top item' do | |
%w{foo bar baz}.each {|s| @stack.push(s)} | |
@stack.pop.should eq "baz" | |
@stack.to_string.should eq "[foo, bar]" | |
end | |
# public T pop() throws StackException | |
it 'should throw a StackException on pop when empty' do | |
expect { @stack.pop }.to raise_error(StackException) | |
end | |
# public T peek() | |
it 'should peek at top item' do | |
%w{foo bar baz}.each {|s| @stack.push(s)} | |
@stack.peek.should eq "baz" | |
@stack.to_string.should eq "[foo, bar, baz]" | |
end | |
# public T peek() throws StackException | |
it 'should throw a StackException on peek when empty' do | |
expect { @stack.peek }.to raise_error(StackException) | |
end | |
# public String toString() | |
it 'should print something useful' do | |
%w{foo bar baz}.each {|s| @stack.push(s)} | |
@stack.to_string.should eq "[foo, bar, baz]" | |
end | |
end | |
__END__ | |
$ jruby -S rspec -fs spec/g_stack_spec.rb | |
Java::Cis::GStack once created | |
should be empty | |
should accept an item | |
should raise an error on push (PENDING: Not yet implemented) | |
should clear the stack | |
should pop off top item | |
should throw a StackException on pop when empty | |
should peek at top item | |
should throw a StackException on peek when empty | |
should print something useful | |
Pending: | |
Java::Cis::GStack once created should raise an error on push | |
# Not yet implemented | |
# ./spec/g_stack_spec.rb:26 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment