Skip to content

Instantly share code, notes, and snippets.

@louis-wu
Created May 23, 2010 04:21
Show Gist options
  • Save louis-wu/410631 to your computer and use it in GitHub Desktop.
Save louis-wu/410631 to your computer and use it in GitHub Desktop.
class Stack
attr_reader :stack
def initialize
@stack = []
end
def peek(obj)
@stack.push(obj)
end
def pop
@stack.pop
end
end
describe Stack do
before(:each) do
@stack = Stack.new
@stack.push :item
end
describe "#peek" do
it "should return the top element" do
@stack.peek.should == :item
end
it "should not remove the top element" do
@stack.peek
@stack.size.should == 1
end
end
describe "#pop" do
it "should return the top element" do
@stack.pop.should == :item
end
it "should remove the top element" do
@stack.pop
@stack.size.should == 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment