~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/minitest/test_mini_mock.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
############################################################
2
 
# This file is imported from a different project.
3
 
# DO NOT make modifications in this repo.
4
 
# File a patch instead and assign it to Ryan Davis
5
 
############################################################
6
 
 
7
 
require 'minitest/mock'
8
 
require 'minitest/unit'
9
 
 
10
 
MiniTest::Unit.autorun
11
 
 
12
 
class TestMiniMock < MiniTest::Unit::TestCase
13
 
  def setup
14
 
    @mock = MiniTest::Mock.new.expect(:foo, nil)
15
 
    @mock.expect(:meaning_of_life, 42)
16
 
  end
17
 
 
18
 
  def test_should_create_stub_method
19
 
    assert_nil @mock.foo
20
 
  end
21
 
 
22
 
  def test_should_allow_return_value_specification
23
 
    assert_equal 42, @mock.meaning_of_life
24
 
  end
25
 
 
26
 
  def test_should_blow_up_if_not_called
27
 
    @mock.foo
28
 
 
29
 
    util_verify_bad
30
 
  end
31
 
 
32
 
  def test_should_not_blow_up_if_everything_called
33
 
    @mock.foo
34
 
    @mock.meaning_of_life
35
 
 
36
 
    assert @mock.verify
37
 
  end
38
 
 
39
 
  def test_should_allow_expectations_to_be_added_after_creation
40
 
    @mock.expect(:bar, true)
41
 
    assert @mock.bar
42
 
  end
43
 
 
44
 
  def test_should_not_verify_if_new_expected_method_is_not_called
45
 
    @mock.foo
46
 
    @mock.meaning_of_life
47
 
    @mock.expect(:bar, true)
48
 
 
49
 
    util_verify_bad
50
 
  end
51
 
 
52
 
  def test_should_not_verify_if_unexpected_method_is_called
53
 
    assert_raises NoMethodError do
54
 
      @mock.unexpected
55
 
    end
56
 
  end
57
 
 
58
 
  def test_should_blow_up_on_wrong_number_of_arguments
59
 
    @mock.foo
60
 
    @mock.meaning_of_life
61
 
    @mock.expect(:sum, 3, [1, 2])
62
 
 
63
 
    assert_raises ArgumentError do
64
 
      @mock.sum
65
 
    end
66
 
  end
67
 
 
68
 
  def test_should_blow_up_on_wrong_arguments
69
 
    @mock.foo
70
 
    @mock.meaning_of_life
71
 
    @mock.expect(:sum, 3, [1, 2])
72
 
 
73
 
    @mock.sum(2, 4)
74
 
 
75
 
    util_verify_bad
76
 
  end
77
 
 
78
 
  def test_no_method_error_on_unexpected_methods
79
 
    assert_raises NoMethodError do
80
 
      @mock.bar
81
 
    end
82
 
  end
83
 
 
84
 
  def util_verify_bad
85
 
    assert_raises MockExpectationError do
86
 
      @mock.verify
87
 
    end
88
 
  end
89
 
end