assert 2.17.0 → 2.18.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +66 -41
- data/assert.gemspec +2 -3
- data/lib/assert.rb +0 -10
- data/lib/assert/actual_value.rb +127 -0
- data/lib/assert/assert_runner.rb +0 -3
- data/lib/assert/assertions.rb +10 -23
- data/lib/assert/cli.rb +30 -46
- data/lib/assert/config.rb +0 -4
- data/lib/assert/config_helpers.rb +0 -4
- data/lib/assert/context.rb +18 -9
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/setup_dsl.rb +0 -4
- data/lib/assert/context/subject_dsl.rb +23 -28
- data/lib/assert/context/suite_dsl.rb +0 -4
- data/lib/assert/context/test_dsl.rb +0 -4
- data/lib/assert/context_info.rb +0 -4
- data/lib/assert/default_runner.rb +0 -4
- data/lib/assert/default_suite.rb +0 -5
- data/lib/assert/default_view.rb +0 -4
- data/lib/assert/factory.rb +0 -3
- data/lib/assert/file_line.rb +0 -4
- data/lib/assert/macro.rb +0 -3
- data/lib/assert/macros/methods.rb +4 -10
- data/lib/assert/result.rb +2 -17
- data/lib/assert/runner.rb +0 -3
- data/lib/assert/stub.rb +15 -1
- data/lib/assert/suite.rb +0 -4
- data/lib/assert/test.rb +2 -7
- data/lib/assert/utils.rb +0 -4
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +0 -3
- data/lib/assert/view_helpers.rb +0 -11
- data/log/{.gitkeep → .keep} +0 -0
- data/test/helper.rb +23 -29
- data/test/support/factory.rb +14 -0
- data/test/support/inherited_stuff.rb +0 -2
- data/test/system/stub_tests.rb +332 -352
- data/test/system/test_tests.rb +98 -124
- data/test/unit/actual_value_tests.rb +335 -0
- data/test/unit/assert_tests.rb +121 -46
- data/test/unit/assertions/assert_block_tests.rb +30 -35
- data/test/unit/assertions/assert_empty_tests.rb +33 -35
- data/test/unit/assertions/assert_equal_tests.rb +75 -83
- data/test/unit/assertions/assert_file_exists_tests.rb +32 -36
- data/test/unit/assertions/assert_includes_tests.rb +38 -41
- data/test/unit/assertions/assert_instance_of_tests.rb +34 -37
- data/test/unit/assertions/assert_kind_of_tests.rb +34 -37
- data/test/unit/assertions/assert_match_tests.rb +34 -37
- data/test/unit/assertions/assert_nil_tests.rb +30 -35
- data/test/unit/assertions/assert_raises_tests.rb +54 -60
- data/test/unit/assertions/assert_respond_to_tests.rb +36 -39
- data/test/unit/assertions/assert_same_tests.rb +86 -88
- data/test/unit/assertions/assert_true_false_tests.rb +60 -66
- data/test/unit/assertions_tests.rb +14 -17
- data/test/unit/config_helpers_tests.rb +41 -39
- data/test/unit/config_tests.rb +38 -37
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +68 -87
- data/test/unit/context/subject_dsl_tests.rb +15 -49
- data/test/unit/context/suite_dsl_tests.rb +15 -20
- data/test/unit/context/test_dsl_tests.rb +50 -57
- data/test/unit/context_info_tests.rb +23 -18
- data/test/unit/context_tests.rb +183 -194
- data/test/unit/default_runner_tests.rb +1 -7
- data/test/unit/default_suite_tests.rb +57 -56
- data/test/unit/factory_tests.rb +5 -6
- data/test/unit/file_line_tests.rb +33 -39
- data/test/unit/macro_tests.rb +14 -18
- data/test/unit/result_tests.rb +159 -196
- data/test/unit/runner_tests.rb +64 -71
- data/test/unit/suite_tests.rb +58 -59
- data/test/unit/test_tests.rb +125 -136
- data/test/unit/utils_tests.rb +43 -54
- data/test/unit/view_helpers_tests.rb +54 -58
- data/test/unit/view_tests.rb +22 -27
- metadata +15 -10
- data/tmp/.gitkeep +0 -0
@@ -0,0 +1,335 @@
|
|
1
|
+
require "assert"
|
2
|
+
require "assert/actual_value"
|
3
|
+
|
4
|
+
class Assert::ActualValue
|
5
|
+
class UnitTests < Assert::Context
|
6
|
+
desc "Assert::ActualValue"
|
7
|
+
subject { unit_class }
|
8
|
+
|
9
|
+
let(:unit_class) { Assert::ActualValue }
|
10
|
+
end
|
11
|
+
|
12
|
+
class InitTests < UnitTests
|
13
|
+
desc "when init"
|
14
|
+
subject { unit_class.new(actual_value1, context: context1) }
|
15
|
+
|
16
|
+
let(:actual_value1) { Factory.string }
|
17
|
+
let(:context1) { Factory.modes_off_context }
|
18
|
+
|
19
|
+
should have_imeths :returns_true, :does_not_return_true
|
20
|
+
should have_imeths :raises, :does_not_raise
|
21
|
+
should have_imeths :is_a_kind_of, :is_not_a_kind_of
|
22
|
+
should have_imeths :is_kind_of, :is_not_kind_of
|
23
|
+
should have_imeths :is_an_instance_of, :is_not_an_instance_of
|
24
|
+
should have_imeths :is_instance_of, :is_not_instance_of
|
25
|
+
should have_imeths :responds_to, :does_not_respond_to
|
26
|
+
should have_imeths :is_the_same_as, :is_not_the_same_as
|
27
|
+
should have_imeths :equals, :does_not_equal
|
28
|
+
should have_imeths :is_equal_to, :is_not_equal_to
|
29
|
+
should have_imeths :matches, :does_not_match
|
30
|
+
should have_imeths :is_empty, :is_not_empty
|
31
|
+
should have_imeths :includes, :does_not_include
|
32
|
+
should have_imeths :is_nil, :is_not_nil
|
33
|
+
should have_imeths :is_true, :is_not_true
|
34
|
+
should have_imeths :is_false, :is_not_false
|
35
|
+
should have_imeths :is_a_file, :is_not_a_file
|
36
|
+
end
|
37
|
+
|
38
|
+
class MethodsTests < InitTests
|
39
|
+
desc "methods"
|
40
|
+
|
41
|
+
let(:args1) { Factory.integer(3).times.map { Factory.string } }
|
42
|
+
let(:capture_last_call_block) { ->(call) { @last_call = call } }
|
43
|
+
|
44
|
+
should "call to their equivalent context methods" do
|
45
|
+
assert_calls(
|
46
|
+
:assert_block,
|
47
|
+
when_calling: :returns_true,
|
48
|
+
on_value: -> {}
|
49
|
+
) do |value, call|
|
50
|
+
assert_equal args1, call.args
|
51
|
+
assert_equal value, call.block
|
52
|
+
end
|
53
|
+
|
54
|
+
assert_calls(
|
55
|
+
:assert_not_block,
|
56
|
+
when_calling: :does_not_return_true,
|
57
|
+
on_value: -> {}
|
58
|
+
) do |value, call|
|
59
|
+
assert_equal args1, call.args
|
60
|
+
assert_equal value, call.block
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_calls(
|
64
|
+
:assert_raises,
|
65
|
+
when_calling: :raises,
|
66
|
+
on_value: -> {}
|
67
|
+
) do |value, call|
|
68
|
+
assert_equal args1, call.args
|
69
|
+
assert_equal value, call.block
|
70
|
+
end
|
71
|
+
|
72
|
+
assert_calls(
|
73
|
+
:assert_nothing_raised,
|
74
|
+
when_calling: :does_not_raise,
|
75
|
+
on_value: -> {}
|
76
|
+
) do |value, call|
|
77
|
+
assert_equal args1, call.args
|
78
|
+
assert_equal value, call.block
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_calls(
|
82
|
+
:assert_kind_of,
|
83
|
+
when_calling: [:is_a_kind_of, String],
|
84
|
+
on_value: actual_value1
|
85
|
+
) do |value, call|
|
86
|
+
assert_equal [String, value, *args1], call.args
|
87
|
+
end
|
88
|
+
|
89
|
+
assert_calls(
|
90
|
+
:assert_kind_of,
|
91
|
+
when_calling: [:is_kind_of, String],
|
92
|
+
on_value: actual_value1
|
93
|
+
) do |value, call|
|
94
|
+
assert_equal [String, value, *args1], call.args
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_calls(
|
98
|
+
:assert_not_kind_of,
|
99
|
+
when_calling: [:is_not_a_kind_of, String],
|
100
|
+
on_value: actual_value1
|
101
|
+
) do |value, call|
|
102
|
+
assert_equal [String, value, *args1], call.args
|
103
|
+
end
|
104
|
+
|
105
|
+
assert_calls(
|
106
|
+
:assert_not_kind_of,
|
107
|
+
when_calling: [:is_not_kind_of, String],
|
108
|
+
on_value: actual_value1
|
109
|
+
) do |value, call|
|
110
|
+
assert_equal [String, value, *args1], call.args
|
111
|
+
end
|
112
|
+
|
113
|
+
assert_calls(
|
114
|
+
:assert_instance_of,
|
115
|
+
when_calling: [:is_an_instance_of, String],
|
116
|
+
on_value: actual_value1
|
117
|
+
) do |value, call|
|
118
|
+
assert_equal [String, value, *args1], call.args
|
119
|
+
end
|
120
|
+
|
121
|
+
assert_calls(
|
122
|
+
:assert_instance_of,
|
123
|
+
when_calling: [:is_instance_of, String],
|
124
|
+
on_value: actual_value1
|
125
|
+
) do |value, call|
|
126
|
+
assert_equal [String, value, *args1], call.args
|
127
|
+
end
|
128
|
+
|
129
|
+
assert_calls(
|
130
|
+
:assert_not_instance_of,
|
131
|
+
when_calling: [:is_not_an_instance_of, String],
|
132
|
+
on_value: actual_value1
|
133
|
+
) do |value, call|
|
134
|
+
assert_equal [String, value, *args1], call.args
|
135
|
+
end
|
136
|
+
|
137
|
+
assert_calls(
|
138
|
+
:assert_not_instance_of,
|
139
|
+
when_calling: [:is_not_instance_of, String],
|
140
|
+
on_value: actual_value1
|
141
|
+
) do |value, call|
|
142
|
+
assert_equal [String, value, *args1], call.args
|
143
|
+
end
|
144
|
+
|
145
|
+
assert_calls(
|
146
|
+
:assert_responds_to,
|
147
|
+
when_calling: [:responds_to, :method],
|
148
|
+
on_value: actual_value1
|
149
|
+
) do |value, call|
|
150
|
+
assert_equal [:method, value, *args1], call.args
|
151
|
+
end
|
152
|
+
|
153
|
+
assert_calls(
|
154
|
+
:assert_not_responds_to,
|
155
|
+
when_calling: [:does_not_respond_to, :method],
|
156
|
+
on_value: actual_value1
|
157
|
+
) do |value, call|
|
158
|
+
assert_equal [:method, value, *args1], call.args
|
159
|
+
end
|
160
|
+
|
161
|
+
assert_calls(
|
162
|
+
:assert_same,
|
163
|
+
when_calling: [:is_the_same_as, "something"],
|
164
|
+
on_value: actual_value1
|
165
|
+
) do |value, call|
|
166
|
+
assert_equal ["something", value, *args1], call.args
|
167
|
+
end
|
168
|
+
|
169
|
+
assert_calls(
|
170
|
+
:assert_not_same,
|
171
|
+
when_calling: [:is_not_the_same_as, "something"],
|
172
|
+
on_value: actual_value1
|
173
|
+
) do |value, call|
|
174
|
+
assert_equal ["something", value, *args1], call.args
|
175
|
+
end
|
176
|
+
|
177
|
+
assert_calls(
|
178
|
+
:assert_equal,
|
179
|
+
when_calling: [:equals, "something"],
|
180
|
+
on_value: actual_value1
|
181
|
+
) do |value, call|
|
182
|
+
assert_equal ["something", value, *args1], call.args
|
183
|
+
end
|
184
|
+
|
185
|
+
assert_calls(
|
186
|
+
:assert_equal,
|
187
|
+
when_calling: [:is_equal_to, "something"],
|
188
|
+
on_value: actual_value1
|
189
|
+
) do |value, call|
|
190
|
+
assert_equal ["something", value, *args1], call.args
|
191
|
+
end
|
192
|
+
|
193
|
+
assert_calls(
|
194
|
+
:assert_not_equal,
|
195
|
+
when_calling: [:does_not_equal, "something"],
|
196
|
+
on_value: actual_value1
|
197
|
+
) do |value, call|
|
198
|
+
assert_equal ["something", value, *args1], call.args
|
199
|
+
end
|
200
|
+
|
201
|
+
assert_calls(
|
202
|
+
:assert_not_equal,
|
203
|
+
when_calling: [:is_not_equal_to, "something"],
|
204
|
+
on_value: actual_value1
|
205
|
+
) do |value, call|
|
206
|
+
assert_equal ["something", value, *args1], call.args
|
207
|
+
end
|
208
|
+
|
209
|
+
assert_calls(
|
210
|
+
:assert_match,
|
211
|
+
when_calling: [:matches, "something"],
|
212
|
+
on_value: actual_value1
|
213
|
+
) do |value, call|
|
214
|
+
assert_equal ["something", value, *args1], call.args
|
215
|
+
end
|
216
|
+
|
217
|
+
assert_calls(
|
218
|
+
:assert_not_match,
|
219
|
+
when_calling: [:does_not_match, "something"],
|
220
|
+
on_value: actual_value1
|
221
|
+
) do |value, call|
|
222
|
+
assert_equal ["something", value, *args1], call.args
|
223
|
+
end
|
224
|
+
|
225
|
+
assert_calls(
|
226
|
+
:assert_empty,
|
227
|
+
when_calling: :is_empty,
|
228
|
+
on_value: actual_value1
|
229
|
+
) do |value, call|
|
230
|
+
assert_equal [value, *args1], call.args
|
231
|
+
end
|
232
|
+
|
233
|
+
assert_calls(
|
234
|
+
:assert_not_empty,
|
235
|
+
when_calling: :is_not_empty,
|
236
|
+
on_value: actual_value1
|
237
|
+
) do |value, call|
|
238
|
+
assert_equal [value, *args1], call.args
|
239
|
+
end
|
240
|
+
|
241
|
+
assert_calls(
|
242
|
+
:assert_includes,
|
243
|
+
when_calling: [:includes, "something"],
|
244
|
+
on_value: actual_value1
|
245
|
+
) do |value, call|
|
246
|
+
assert_equal ["something", value, *args1], call.args
|
247
|
+
end
|
248
|
+
|
249
|
+
assert_calls(
|
250
|
+
:assert_not_includes,
|
251
|
+
when_calling: [:does_not_include, "something"],
|
252
|
+
on_value: actual_value1
|
253
|
+
) do |value, call|
|
254
|
+
assert_equal ["something", value, *args1], call.args
|
255
|
+
end
|
256
|
+
|
257
|
+
assert_calls(
|
258
|
+
:assert_nil,
|
259
|
+
when_calling: :is_nil,
|
260
|
+
on_value: actual_value1
|
261
|
+
) do |value, call|
|
262
|
+
assert_equal [value, *args1], call.args
|
263
|
+
end
|
264
|
+
|
265
|
+
assert_calls(
|
266
|
+
:assert_not_nil,
|
267
|
+
when_calling: :is_not_nil,
|
268
|
+
on_value: actual_value1
|
269
|
+
) do |value, call|
|
270
|
+
assert_equal [value, *args1], call.args
|
271
|
+
end
|
272
|
+
|
273
|
+
assert_calls(
|
274
|
+
:assert_true,
|
275
|
+
when_calling: :is_true,
|
276
|
+
on_value: actual_value1
|
277
|
+
) do |value, call|
|
278
|
+
assert_equal [value, *args1], call.args
|
279
|
+
end
|
280
|
+
|
281
|
+
assert_calls(
|
282
|
+
:assert_not_true,
|
283
|
+
when_calling: :is_not_true,
|
284
|
+
on_value: actual_value1
|
285
|
+
) do |value, call|
|
286
|
+
assert_equal [value, *args1], call.args
|
287
|
+
end
|
288
|
+
|
289
|
+
assert_calls(
|
290
|
+
:assert_false,
|
291
|
+
when_calling: :is_false,
|
292
|
+
on_value: actual_value1
|
293
|
+
) do |value, call|
|
294
|
+
assert_equal [value, *args1], call.args
|
295
|
+
end
|
296
|
+
|
297
|
+
assert_calls(
|
298
|
+
:assert_not_false,
|
299
|
+
when_calling: :is_not_false,
|
300
|
+
on_value: actual_value1
|
301
|
+
) do |value, call|
|
302
|
+
assert_equal [value, *args1], call.args
|
303
|
+
end
|
304
|
+
|
305
|
+
assert_calls(
|
306
|
+
:assert_file_exists,
|
307
|
+
when_calling: :is_a_file,
|
308
|
+
on_value: actual_value1
|
309
|
+
) do |value, call|
|
310
|
+
assert_equal [value, *args1], call.args
|
311
|
+
end
|
312
|
+
|
313
|
+
assert_calls(
|
314
|
+
:assert_not_file_exists,
|
315
|
+
when_calling: :is_not_a_file,
|
316
|
+
on_value: actual_value1
|
317
|
+
) do |value, call|
|
318
|
+
assert_equal [value, *args1], call.args
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
private
|
323
|
+
|
324
|
+
def assert_calls(context_method, when_calling:, on_value:)
|
325
|
+
@last_call = nil
|
326
|
+
Assert.stub_on_call(context1, context_method, &capture_last_call_block)
|
327
|
+
|
328
|
+
unit_class.new(on_value, context: context1).public_send(*[*when_calling, *args1])
|
329
|
+
yield(on_value, @last_call)
|
330
|
+
|
331
|
+
Assert.unstub(context1, context_method)
|
332
|
+
@last_call = nil
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
data/test/unit/assert_tests.rb
CHANGED
@@ -5,81 +5,104 @@ require "assert/stub"
|
|
5
5
|
require "much-stub"
|
6
6
|
|
7
7
|
module Assert
|
8
|
-
|
9
8
|
class UnitTests < Assert::Context
|
10
9
|
desc "Assert"
|
11
|
-
subject {
|
10
|
+
subject { unit_class }
|
11
|
+
|
12
|
+
let(:unit_class) { Assert }
|
12
13
|
|
13
14
|
should have_imeths :config, :configure, :view, :suite, :runner
|
14
15
|
should have_imeths :stubs, :stub, :unstub, :unstub!, :stub_send
|
15
16
|
|
16
17
|
should "know its config instance" do
|
17
|
-
|
18
|
+
assert_that(subject.config).is_kind_of(Assert::Config)
|
18
19
|
end
|
19
20
|
|
20
21
|
should "map its view, suite and runner to its config" do
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
assert_that(subject.view).is_the_same_as(subject.config.view)
|
23
|
+
assert_that(subject.suite).is_the_same_as(subject.config.suite)
|
24
|
+
assert_that(subject.runner).is_the_same_as(subject.config.runner)
|
24
25
|
end
|
25
26
|
|
26
27
|
# Note: don't really need to explicitly test the configure method as
|
27
28
|
# nothing runs if it isn't working
|
28
|
-
|
29
29
|
end
|
30
30
|
|
31
31
|
class StubTests < UnitTests
|
32
|
-
setup do
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
# setup do
|
33
|
+
# orig_value1 = Factory.string
|
34
|
+
# stub_value1 = Factory.string
|
35
|
+
|
36
|
+
# @myclass =
|
37
|
+
# Class.new do
|
38
|
+
# def initialize(value); @value = value; end
|
39
|
+
# def mymeth; @value; end
|
40
|
+
# end
|
41
|
+
# object1 = @myclass.new(orig_value1)
|
42
|
+
# end
|
43
|
+
|
44
|
+
let(:class1) {
|
45
|
+
Class.new do
|
37
46
|
def initialize(value); @value = value; end
|
38
47
|
def mymeth; @value; end
|
39
48
|
end
|
40
|
-
|
41
|
-
|
49
|
+
}
|
50
|
+
let(:object1) { class1.new(orig_value1) }
|
51
|
+
let(:orig_value1) { Factory.string }
|
52
|
+
let(:stub_value1) { Factory.string }
|
42
53
|
|
43
54
|
should "build a stub" do
|
44
|
-
stub1 = Assert.stub(
|
55
|
+
stub1 = Assert.stub(object1, :mymeth)
|
56
|
+
assert_that(stub1).is_kind_of(MuchStub::Stub)
|
57
|
+
end
|
58
|
+
|
59
|
+
should "build a stub with an on_call block" do
|
60
|
+
my_meth_called_with = nil
|
61
|
+
stub1 =
|
62
|
+
Assert.stub_on_call(object1, :mymeth) { |call|
|
63
|
+
my_meth_called_with = call
|
64
|
+
}
|
65
|
+
|
66
|
+
object1.mymeth
|
45
67
|
assert_kind_of MuchStub::Stub, stub1
|
68
|
+
assert_equal [], my_meth_called_with.args
|
46
69
|
end
|
47
70
|
|
48
71
|
should "lookup stubs that have been called before" do
|
49
|
-
stub1 = Assert.stub(
|
50
|
-
stub2 = Assert.stub(
|
51
|
-
|
72
|
+
stub1 = Assert.stub(object1, :mymeth)
|
73
|
+
stub2 = Assert.stub(object1, :mymeth)
|
74
|
+
assert_that(stub2).is_the_same_as(stub1)
|
52
75
|
end
|
53
76
|
|
54
77
|
should "set the stub's do block if given a block" do
|
55
|
-
Assert.stub(
|
56
|
-
|
57
|
-
Assert.stub(
|
58
|
-
|
78
|
+
Assert.stub(object1, :mymeth)
|
79
|
+
assert_that(-> { object1.mymeth }).raises(MuchStub::NotStubbedError)
|
80
|
+
Assert.stub(object1, :mymeth){ stub_value1 }
|
81
|
+
assert_that(object1.mymeth).equals(stub_value1)
|
59
82
|
end
|
60
83
|
|
61
84
|
should "teardown stubs" do
|
62
|
-
|
63
|
-
Assert.unstub(
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
Assert.stub(
|
68
|
-
|
69
|
-
Assert.unstub(
|
70
|
-
|
85
|
+
assert_that(object1.mymeth).equals(orig_value1)
|
86
|
+
Assert.unstub(object1, :mymeth)
|
87
|
+
assert_that(object1.mymeth).equals(orig_value1)
|
88
|
+
|
89
|
+
assert_that(object1.mymeth).equals(orig_value1)
|
90
|
+
Assert.stub(object1, :mymeth){ stub_value1 }
|
91
|
+
assert_that(object1.mymeth).equals(stub_value1)
|
92
|
+
Assert.unstub(object1, :mymeth)
|
93
|
+
assert_that(object1.mymeth).equals(orig_value1)
|
71
94
|
end
|
72
95
|
|
73
96
|
should "know and teardown all stubs" do
|
74
|
-
|
97
|
+
assert_that(object1.mymeth).equals(orig_value1)
|
75
98
|
|
76
|
-
Assert.stub(
|
77
|
-
|
78
|
-
|
99
|
+
Assert.stub(object1, :mymeth){ stub_value1 }
|
100
|
+
assert_that(object1.mymeth).equals(stub_value1)
|
101
|
+
assert_that(Assert.stubs.size).equals(1)
|
79
102
|
|
80
103
|
Assert.unstub!
|
81
|
-
|
82
|
-
|
104
|
+
assert_that(object1.mymeth).equals(orig_value1)
|
105
|
+
assert_that(Assert.stubs).is_empty
|
83
106
|
end
|
84
107
|
|
85
108
|
should "auto-unstub any stubs on teardown" do
|
@@ -90,23 +113,75 @@ module Assert
|
|
90
113
|
end
|
91
114
|
|
92
115
|
context_class.run_setups("scope")
|
93
|
-
|
116
|
+
assert_that(Assert.stubs.size).equals(1)
|
94
117
|
|
95
118
|
context_class.run_teardowns("scope")
|
96
|
-
|
119
|
+
assert_that(Assert.stubs).is_empty
|
97
120
|
end
|
98
121
|
|
99
122
|
should "be able to call a stub's original method" do
|
100
|
-
err =
|
101
|
-
|
102
|
-
|
123
|
+
err =
|
124
|
+
assert_that(-> { Assert.stub_send(object1, :mymeth) }).
|
125
|
+
raises(MuchStub::NotStubbedError)
|
126
|
+
assert_that(err.message).includes("not stubbed.")
|
127
|
+
assert_that(err.backtrace.first).includes("test/unit/assert_tests.rb")
|
103
128
|
|
104
|
-
Assert.stub(
|
129
|
+
Assert.stub(object1, :mymeth){ stub_value1 }
|
105
130
|
|
106
|
-
|
107
|
-
|
131
|
+
assert_that(object1.mymeth).equals(stub_value1)
|
132
|
+
assert_that(Assert.stub_send(object1, :mymeth)).equals(orig_value1)
|
108
133
|
end
|
109
134
|
|
110
|
-
|
135
|
+
should "be able to add a stub tap" do
|
136
|
+
my_meth_called_with = nil
|
137
|
+
Assert.stub_tap(object1, :mymeth){ |value, *args, &block|
|
138
|
+
my_meth_called_with = args
|
139
|
+
}
|
111
140
|
|
141
|
+
assert_that(object1.mymeth).equals(orig_value1)
|
142
|
+
assert_that(my_meth_called_with).equals([])
|
143
|
+
end
|
144
|
+
|
145
|
+
should "be able to add a stub tap with an on_call block" do
|
146
|
+
my_meth_called_with = nil
|
147
|
+
Assert.stub_tap_on_call(object1, :mymeth){ |value, call|
|
148
|
+
my_meth_called_with = call
|
149
|
+
}
|
150
|
+
|
151
|
+
assert_that(object1.mymeth).equals(orig_value1)
|
152
|
+
assert_that(my_meth_called_with.args).equals([])
|
153
|
+
end
|
154
|
+
|
155
|
+
should "be able to add a stubbed spy" do
|
156
|
+
myclass = Class.new do
|
157
|
+
def one; self; end
|
158
|
+
def two(val); self; end
|
159
|
+
def three; self; end
|
160
|
+
def ready?; false; end
|
161
|
+
end
|
162
|
+
myobj = myclass.new
|
163
|
+
|
164
|
+
spy =
|
165
|
+
Assert.stub_spy(
|
166
|
+
myobj,
|
167
|
+
:one,
|
168
|
+
:two,
|
169
|
+
:three,
|
170
|
+
ready?: true)
|
171
|
+
|
172
|
+
assert_that(myobj.one).equals(spy)
|
173
|
+
assert_that(myobj.two("a")).equals(spy)
|
174
|
+
assert_that(myobj.three).equals(spy)
|
175
|
+
|
176
|
+
assert_that(myobj.one.two("b").three.ready?).is_true
|
177
|
+
|
178
|
+
assert_that(spy).is_kind_of(MuchStub::CallSpy)
|
179
|
+
assert_that(spy.one_call_count).equals(2)
|
180
|
+
assert_that(spy.two_call_count).equals(2)
|
181
|
+
assert_that(spy.three_call_count).equals(2)
|
182
|
+
assert_that(spy.ready_predicate_call_count).equals(1)
|
183
|
+
assert_that(spy.two_last_called_with.args).equals(["b"])
|
184
|
+
assert_that(spy.ready_predicate_called?).is_true
|
185
|
+
end
|
186
|
+
end
|
112
187
|
end
|