minitest 2.11.0 → 2.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +7 -0
- data/lib/minitest/mock.rb +33 -21
- data/lib/minitest/unit.rb +2 -2
- data/test/test_minitest_mock.rb +35 -4
- metadata +4 -4
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/lib/minitest/mock.rb
CHANGED
@@ -19,8 +19,8 @@ module MiniTest
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def initialize # :nodoc:
|
22
|
-
@expected_calls = {}
|
23
|
-
@actual_calls
|
22
|
+
@expected_calls = Hash.new { |calls, name| calls[name] = [] }
|
23
|
+
@actual_calls = Hash.new { |calls, name| calls[name] = [] }
|
24
24
|
end
|
25
25
|
|
26
26
|
##
|
@@ -45,7 +45,8 @@ module MiniTest
|
|
45
45
|
# @mock.verify # => raises MockExpectationError
|
46
46
|
|
47
47
|
def expect(name, retval, args=[])
|
48
|
-
|
48
|
+
raise ArgumentError, "args must be an array" unless Array === args
|
49
|
+
@expected_calls[name] << { :retval => retval, :args => args }
|
49
50
|
self
|
50
51
|
end
|
51
52
|
|
@@ -55,36 +56,47 @@ module MiniTest
|
|
55
56
|
# expected.
|
56
57
|
|
57
58
|
def verify
|
58
|
-
@expected_calls.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
59
|
+
@expected_calls.each do |name, calls|
|
60
|
+
calls.each do |expected|
|
61
|
+
msg1 = "expected #{name}, #{expected.inspect}"
|
62
|
+
msg2 = "#{msg1}, got #{@actual_calls[name].inspect}"
|
63
|
+
|
64
|
+
raise MockExpectationError, msg2 if
|
65
|
+
@actual_calls.has_key? name and
|
66
|
+
not @actual_calls[name].include?(expected)
|
67
|
+
|
68
|
+
raise MockExpectationError, msg1 unless
|
69
|
+
@actual_calls.has_key? name and @actual_calls[name].include?(expected)
|
70
|
+
end
|
69
71
|
end
|
70
72
|
true
|
71
73
|
end
|
72
74
|
|
73
75
|
def method_missing(sym, *args) # :nodoc:
|
74
|
-
|
75
|
-
|
76
|
-
unless expected then
|
76
|
+
unless @expected_calls.has_key?(sym) then
|
77
77
|
raise NoMethodError, "unmocked method %p, expected one of %p" %
|
78
78
|
[sym, @expected_calls.keys.sort_by(&:to_s)]
|
79
79
|
end
|
80
80
|
|
81
|
-
|
81
|
+
expected_calls = @expected_calls[sym].select { |call| call[:args].size == args.size }
|
82
|
+
|
83
|
+
if expected_calls.empty?
|
84
|
+
arg_sizes = @expected_calls[sym].map { |call| call[:args].size }.uniq.sort
|
85
|
+
raise ArgumentError, "mocked method %p expects %s arguments, got %d" %
|
86
|
+
[sym, arg_sizes.join('/'), args.size]
|
87
|
+
end
|
88
|
+
|
89
|
+
expected_call = expected_calls.find do |call|
|
90
|
+
call[:args].zip(args).all? { |mod, a| mod === a or mod == a }
|
91
|
+
end
|
82
92
|
|
83
|
-
unless
|
84
|
-
raise
|
85
|
-
[sym,
|
93
|
+
unless expected_call
|
94
|
+
raise MockExpectationError, "mocked method %p called with unexpected arguments %p" %
|
95
|
+
[sym, args]
|
86
96
|
end
|
87
97
|
|
98
|
+
expected_args, retval = expected_call[:args], expected_call[:retval]
|
99
|
+
|
88
100
|
@actual_calls[sym] << {
|
89
101
|
:retval => retval,
|
90
102
|
:args => expected_args.zip(args).map { |mod, a| mod === a ? mod : a }
|
data/lib/minitest/unit.rb
CHANGED
@@ -643,7 +643,7 @@ module MiniTest
|
|
643
643
|
end
|
644
644
|
|
645
645
|
class Unit # :nodoc:
|
646
|
-
VERSION = "2.11.
|
646
|
+
VERSION = "2.11.1" # :nodoc:
|
647
647
|
|
648
648
|
attr_accessor :report, :failures, :errors, :skips # :nodoc:
|
649
649
|
attr_accessor :test_count, :assertion_count # :nodoc:
|
@@ -893,7 +893,7 @@ module MiniTest
|
|
893
893
|
options[:verbose] = true
|
894
894
|
end
|
895
895
|
|
896
|
-
opts.on '-n', '--name PATTERN', "Filter test names on pattern." do |a|
|
896
|
+
opts.on '-n', '--name PATTERN', "Filter test names on pattern (e.g. /foo/)" do |a|
|
897
897
|
options[:filter] = a
|
898
898
|
end
|
899
899
|
|
data/test/test_minitest_mock.rb
CHANGED
@@ -78,9 +78,15 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
78
78
|
@mock.meaning_of_life
|
79
79
|
@mock.expect(:sum, 3, [1, 2])
|
80
80
|
|
81
|
-
|
81
|
+
assert_raises MockExpectationError do
|
82
|
+
@mock.sum(2, 4)
|
83
|
+
end
|
84
|
+
end
|
82
85
|
|
83
|
-
|
86
|
+
def test_expect_with_non_array_args
|
87
|
+
assert_raises ArgumentError do
|
88
|
+
@mock.expect :blah, 3, false
|
89
|
+
end
|
84
90
|
end
|
85
91
|
|
86
92
|
def test_respond_appropriately
|
@@ -136,15 +142,19 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
136
142
|
def test_verify_raises_with_strict_args
|
137
143
|
mock = MiniTest::Mock.new
|
138
144
|
mock.expect :strict_expectation, true, [2]
|
139
|
-
mock.strict_expectation 1
|
140
145
|
|
141
|
-
|
146
|
+
assert_raises MockExpectationError do
|
147
|
+
mock.strict_expectation 1
|
148
|
+
end
|
142
149
|
end
|
143
150
|
|
144
151
|
def test_verify_shows_the_actual_arguments_in_the_message
|
145
152
|
mock = MiniTest::Mock.new
|
146
153
|
mock.expect :capitalized, true, ["a"]
|
154
|
+
mock.expect :capitalized, true, ["b"]
|
155
|
+
|
147
156
|
mock.capitalized "b"
|
157
|
+
|
148
158
|
e = assert_raises MockExpectationError do
|
149
159
|
mock.verify
|
150
160
|
end
|
@@ -156,6 +166,27 @@ class TestMiniTestMock < MiniTest::Unit::TestCase
|
|
156
166
|
assert_equal expected, e.message
|
157
167
|
end
|
158
168
|
|
169
|
+
def test_same_method_expects_are_verified_when_all_called
|
170
|
+
mock = MiniTest::Mock.new
|
171
|
+
mock.expect :foo, nil, [:bar]
|
172
|
+
mock.expect :foo, nil, [:baz]
|
173
|
+
|
174
|
+
mock.foo :bar
|
175
|
+
mock.foo :baz
|
176
|
+
|
177
|
+
assert mock.verify
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_same_method_expects_blow_up_when_not_all_called
|
181
|
+
mock = MiniTest::Mock.new
|
182
|
+
mock.expect :foo, nil, [:bar]
|
183
|
+
mock.expect :foo, nil, [:baz]
|
184
|
+
|
185
|
+
mock.foo :baz
|
186
|
+
|
187
|
+
assert_raises(MockExpectationError) { mock.verify }
|
188
|
+
end
|
189
|
+
|
159
190
|
def util_verify_bad
|
160
191
|
assert_raises MockExpectationError do
|
161
192
|
@mock.verify
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 33
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 11
|
9
|
-
-
|
10
|
-
version: 2.11.
|
9
|
+
- 1
|
10
|
+
version: 2.11.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Davis
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
FBHgymkyj/AOSqKRIpXPhjC6
|
37
37
|
-----END CERTIFICATE-----
|
38
38
|
|
39
|
-
date: 2012-01
|
39
|
+
date: 2012-02-01 00:00:00 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rdoc
|
metadata.gz.sig
CHANGED
Binary file
|