summaryrefslogtreecommitdiff
path: root/spec/stack_specs.rb
blob: 48e4b52a0e7c3d7fd6d887a27ae4819b45937f2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require "stack"

class StackTests < Test::Unit::TestCase
  def test_math
    assert_equal(2, 1+1)
  end
  def test_assertions
    # puts self.methods
  end
  def test_should_be_able_to_push_items_onto_the_stack
    stack = Stack.new
    stack.push "hello"
    assert_equal(1, stack.total_items)
    stack.push "yo"
    assert_equal(2, stack.total_items)
  end
  def test_should_be_able_to_pop_the_last_item_off_of_the_stack
    stack=Stack.new
    stack.push "hello"
    stack.push "goodbye"
    assert_equal("goodbye", stack.pop)
  end
  def test_should_remove_the_last_item_popped_off_of_the_stack
    stack=Stack.new
    stack.push "hello"
    stack.push "goodbye"
    assert_equal("goodbye", stack.pop)
    assert_equal(1, stack.total_items)
    assert_equal("hello", stack.pop)
    assert_equal(0, stack.total_items)
  end
  def test_should_return_nil_when_there_is_nothing_on_the_stack
    stack=Stack.new
    assert_equal(nil, stack.pop)
  end
end

describe Stack do 
  before do 
    @stack = Stack.new
  end
  describe "when there are no items on the stack" do 
    it "should_be_able_to_push_items_onto_the_stack" do
      @stack.push "hello"
      assert_equal(1, @stack.total_items)
      @stack.push "yo"
      assert_equal(2, @stack.total_items)
    end
  end
end