Skip to content

Instantly share code, notes, and snippets.

@FsDevNinja
Last active October 25, 2016 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FsDevNinja/b88322a75f74e2dacdc16b735b9cd8df to your computer and use it in GitHub Desktop.
Save FsDevNinja/b88322a75f74e2dacdc16b735b9cd8df to your computer and use it in GitHub Desktop.
RSpec.describe Stack do
before :each do
@node3 = Node.new(57, nil)
@node2 = Node.new(21, @node3)
@node1 = Node.new(34, @node2)
@stack = Stack.new
end
describe "initialize a stack" do
it "stack.top should eq nil" do
expect(@stack.top).to eq nil
end
end
describe "#push method" do
it "should set @top to value passed" do
@stack.push(@node1)
expect(@stack.top).to eq @node1
end
end
describe "#pop method" do
it "should return last pushed node" do
@stack.push(@node1)
expect(@stack.pop).to eq @node1
end
end
end
@montague
Copy link

nice work. now look up a "before" block in rspec and use a @stack instance variable in that before block to DRY up your tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment