class StackSpecifications //extends Specification { var account : NewSpec; function newStack() { stack = new Stack(); } /** A new empty stack **/ function EmptyStack() { Describe_as("an empty Stack"); beforeEach = newStack; afterEach = newStack; Uses(stack); It("should be empty"); The(stack.length).should.equal(0); It("should NOT remove the top item when sent #peek"); Calling("peek").withArgs().should.give(last_item_added); Calling("peek").withNoArgs.should.give(last_item_added); It("should return the top item when sent #pop"); Calling('pop').should.give(last_item_added); It("should throw an EmptyStack exception when popping with no more items left"); Calling('pop').should.raise(Error.EmptyStack); Should_behave_like(EmptyStack); // Infinite loop for the sake of example } } // Or the less dynamic way class StackSpecifications //extends Specification { var account : NewSpec; function begin() { var define = Mock.method; var m = Mock.begin(User, "a new account user"); define(m.delete).will_return. } function newStack() { stack = new Stack(); } /** A new empty stack **/ function EmptyStack() { Describe_as("an empty Stack"); beforeEach = newStack; afterEach = newStack; It("should be empty"); The(stack.length).should.equal(0); It("should NOT remove the top item when sent #peek"); Calling(stack.peek()).should.give(last_item_added); Calling(stack.peek()).should.give(last_item_added); It("should return the top item when sent #pop"); Calling(stack.pop).should.give(last_item_added); It("should throw an EmptyStack exception when popping with no more items left"); Calling(stack.pop).should.raise(Error.EmptyStack); Should_behave_like(EmptyStack); // Infinite loop for the sake of example } }