assert 2.19.0 → 2.19.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/assert.gemspec +11 -6
- data/bin/assert +1 -0
- data/lib/assert.rb +20 -6
- data/lib/assert/actual_value.rb +11 -6
- data/lib/assert/assert_runner.rb +38 -17
- data/lib/assert/assertions.rb +85 -50
- data/lib/assert/cli.rb +32 -70
- data/lib/assert/clirb.rb +55 -0
- data/lib/assert/config.rb +22 -8
- data/lib/assert/config_helpers.rb +57 -22
- data/lib/assert/context.rb +16 -18
- data/lib/assert/context/let_dsl.rb +8 -2
- data/lib/assert/context/method_missing.rb +3 -0
- data/lib/assert/context/setup_dsl.rb +24 -16
- data/lib/assert/context/subject_dsl.rb +9 -7
- data/lib/assert/context/suite_dsl.rb +5 -1
- data/lib/assert/context/test_dsl.rb +58 -19
- data/lib/assert/context_info.rb +2 -0
- data/lib/assert/default_runner.rb +2 -0
- data/lib/assert/default_suite.rb +27 -15
- data/lib/assert/default_view.rb +49 -30
- data/lib/assert/factory.rb +2 -0
- data/lib/assert/file_line.rb +8 -6
- data/lib/assert/macro.rb +3 -1
- data/lib/assert/macros/methods.rb +73 -45
- data/lib/assert/result.rb +114 -62
- data/lib/assert/runner.rb +70 -51
- data/lib/assert/stub.rb +44 -3
- data/lib/assert/suite.rb +69 -28
- data/lib/assert/test.rb +43 -36
- data/lib/assert/utils.rb +22 -11
- data/lib/assert/version.rb +3 -1
- data/lib/assert/view.rb +46 -18
- data/lib/assert/view_helpers.rb +102 -92
- data/test/helper.rb +8 -4
- data/test/support/factory.rb +40 -21
- data/test/support/inherited_stuff.rb +2 -0
- data/test/system/stub_tests.rb +182 -144
- data/test/system/test_tests.rb +88 -60
- data/test/unit/actual_value_tests.rb +71 -50
- data/test/unit/assert_tests.rb +42 -23
- data/test/unit/assertions/assert_block_tests.rb +12 -10
- data/test/unit/assertions/assert_changes_tests.rb +27 -21
- data/test/unit/assertions/assert_empty_tests.rb +16 -12
- data/test/unit/assertions/assert_equal_tests.rb +28 -26
- data/test/unit/assertions/assert_file_exists_tests.rb +17 -13
- data/test/unit/assertions/assert_includes_tests.rb +12 -10
- data/test/unit/assertions/assert_instance_of_tests.rb +16 -14
- data/test/unit/assertions/assert_is_a_tests.rb +128 -0
- data/test/unit/assertions/assert_match_tests.rb +12 -10
- data/test/unit/assertions/assert_nil_tests.rb +18 -12
- data/test/unit/assertions/assert_raises_tests.rb +29 -20
- data/test/unit/assertions/assert_respond_to_tests.rb +12 -10
- data/test/unit/assertions/assert_same_tests.rb +26 -24
- data/test/unit/assertions/assert_true_false_tests.rb +34 -24
- data/test/unit/assertions_tests.rb +16 -9
- data/test/unit/config_helpers_tests.rb +17 -10
- data/test/unit/config_tests.rb +36 -9
- data/test/unit/context/let_dsl_tests.rb +2 -0
- data/test/unit/context/setup_dsl_tests.rb +26 -14
- data/test/unit/context/subject_dsl_tests.rb +5 -3
- data/test/unit/context/suite_dsl_tests.rb +6 -4
- data/test/unit/context/test_dsl_tests.rb +39 -17
- data/test/unit/context_info_tests.rb +6 -4
- data/test/unit/context_tests.rb +112 -54
- data/test/unit/default_runner_tests.rb +2 -0
- data/test/unit/default_suite_tests.rb +12 -6
- data/test/unit/factory_tests.rb +4 -2
- data/test/unit/file_line_tests.rb +9 -7
- data/test/unit/macro_tests.rb +13 -11
- data/test/unit/result_tests.rb +49 -41
- data/test/unit/runner_tests.rb +33 -18
- data/test/unit/suite_tests.rb +39 -15
- data/test/unit/test_tests.rb +65 -50
- data/test/unit/utils_tests.rb +52 -37
- data/test/unit/view_helpers_tests.rb +23 -14
- data/test/unit/view_tests.rb +7 -5
- metadata +26 -11
- data/test/unit/assertions/assert_kind_of_tests.rb +0 -66
data/test/support/factory.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert/config"
|
2
4
|
require "assert/default_suite"
|
3
5
|
require "assert/factory"
|
@@ -8,11 +10,17 @@ module Factory
|
|
8
10
|
extend Assert::Factory
|
9
11
|
|
10
12
|
def self.context_info_called_from
|
11
|
-
File.expand_path(
|
13
|
+
File.expand_path(
|
14
|
+
"#{Factory.path}_tests.rb:#{Factory.integer}",
|
15
|
+
Dir.pwd,
|
16
|
+
)
|
12
17
|
end
|
13
18
|
|
14
19
|
def self.context_info(context_klass = nil)
|
15
|
-
Assert::ContextInfo.new(
|
20
|
+
Assert::ContextInfo.new(
|
21
|
+
context_klass || context_class,
|
22
|
+
context_info_called_from,
|
23
|
+
)
|
16
24
|
end
|
17
25
|
|
18
26
|
# Generate an anonymous `Context` inherited from `Assert::Context` by default.
|
@@ -22,9 +30,8 @@ module Factory
|
|
22
30
|
klass = Class.new(inherit_from || Assert::Context, &block)
|
23
31
|
default = const_name = "FactoryAssertContext"
|
24
32
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
33
|
+
const_name =
|
34
|
+
"#{default}#{rand(Time.now.to_i)}" while Object.const_defined?(const_name)
|
28
35
|
Object.const_set(const_name, klass)
|
29
36
|
klass
|
30
37
|
end
|
@@ -33,9 +40,9 @@ module Factory
|
|
33
40
|
|
34
41
|
def self.test(*args, &block)
|
35
42
|
config, context_info, name = [
|
36
|
-
args.last.
|
37
|
-
args.last.
|
38
|
-
args.last.
|
43
|
+
args.last.is_a?(Assert::Config) ? args.pop : modes_off_config,
|
44
|
+
args.last.is_a?(Assert::ContextInfo) ? args.pop : self.context_info,
|
45
|
+
args.last.is_a?(::String) ? args.pop : "a test",
|
39
46
|
]
|
40
47
|
Assert::Test.for_block(name, context_info, config, &block)
|
41
48
|
end
|
@@ -43,15 +50,27 @@ module Factory
|
|
43
50
|
# Generate results for use in testing.
|
44
51
|
|
45
52
|
def self.pass_result(msg = nil)
|
46
|
-
Assert::Result::Pass.for_test(
|
53
|
+
Assert::Result::Pass.for_test(
|
54
|
+
Factory.test(Factory.string),
|
55
|
+
msg || Factory.string,
|
56
|
+
[],
|
57
|
+
)
|
47
58
|
end
|
48
59
|
|
49
60
|
def self.ignore_result(msg = nil)
|
50
|
-
Assert::Result::Ignore.for_test(
|
61
|
+
Assert::Result::Ignore.for_test(
|
62
|
+
Factory.test(Factory.string),
|
63
|
+
msg || Factory.string,
|
64
|
+
[],
|
65
|
+
)
|
51
66
|
end
|
52
67
|
|
53
68
|
def self.fail_result(msg = nil)
|
54
|
-
Assert::Result::Fail.for_test(
|
69
|
+
Assert::Result::Fail.for_test(
|
70
|
+
Factory.test(Factory.string),
|
71
|
+
msg || Factory.string,
|
72
|
+
[],
|
73
|
+
)
|
55
74
|
end
|
56
75
|
|
57
76
|
def self.skip_result(exception = nil)
|
@@ -66,23 +85,23 @@ module Factory
|
|
66
85
|
|
67
86
|
def self.modes_off_config
|
68
87
|
Assert::Config.new({
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
88
|
+
capture_output: false,
|
89
|
+
halt_on_fail: false,
|
90
|
+
changed_only: false,
|
91
|
+
pp_objects: false,
|
92
|
+
debug: false,
|
74
93
|
})
|
75
94
|
end
|
76
95
|
|
77
96
|
def self.modes_off_suite
|
78
|
-
Assert::DefaultSuite.new(
|
97
|
+
Assert::DefaultSuite.new(modes_off_config)
|
79
98
|
end
|
80
99
|
|
81
100
|
def self.modes_off_context_class(*args, &block)
|
82
|
-
suite_obj =
|
83
|
-
|
101
|
+
suite_obj = modes_off_suite
|
102
|
+
context_class(*args) do
|
84
103
|
suite(suite_obj)
|
85
|
-
instance_eval(&block)
|
104
|
+
instance_eval(&block) unless block.nil?
|
86
105
|
end
|
87
106
|
end
|
88
107
|
|
@@ -91,7 +110,7 @@ module Factory
|
|
91
110
|
Factory.modes_off_context_class.new(
|
92
111
|
test,
|
93
112
|
test.config,
|
94
|
-
result_block || proc
|
113
|
+
result_block || proc{ |r| },
|
95
114
|
)
|
96
115
|
end
|
97
116
|
|
data/test/system/stub_tests.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/stub"
|
3
5
|
|
@@ -8,7 +10,7 @@ class Assert::Stub
|
|
8
10
|
|
9
11
|
class InstanceTests < SystemTests
|
10
12
|
desc "for instance methods"
|
11
|
-
subject
|
13
|
+
subject{ TestClass.new }
|
12
14
|
|
13
15
|
setup do
|
14
16
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -54,33 +56,33 @@ class Assert::Stub
|
|
54
56
|
end
|
55
57
|
|
56
58
|
should "not allow stubbing methods with invalid arity" do
|
57
|
-
assert_that
|
59
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
58
60
|
|
59
|
-
assert_that
|
60
|
-
assert_that
|
61
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
62
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
61
63
|
|
62
|
-
assert_that
|
63
|
-
assert_that
|
64
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
65
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
64
66
|
|
65
|
-
assert_that
|
67
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
66
68
|
end
|
67
69
|
|
68
70
|
should "not allow calling methods with invalid arity" do
|
69
|
-
assert_that
|
71
|
+
assert_that{ subject.noargs(1) }.raises
|
70
72
|
|
71
|
-
assert_that
|
72
|
-
assert_that
|
73
|
+
assert_that{ subject.withargs }.raises
|
74
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
73
75
|
|
74
|
-
assert_that
|
75
|
-
assert_that
|
76
|
+
assert_that{ subject.minargs }.raises
|
77
|
+
assert_that{ subject.minargs(1) }.raises
|
76
78
|
|
77
|
-
assert_that
|
79
|
+
assert_that{ subject.withblock(1) }.raises
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
83
|
class ClassTests < SystemTests
|
82
84
|
desc "for singleton methods on a class"
|
83
|
-
subject
|
85
|
+
subject{ TestClass }
|
84
86
|
|
85
87
|
setup do
|
86
88
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -127,33 +129,33 @@ class Assert::Stub
|
|
127
129
|
end
|
128
130
|
|
129
131
|
should "not allow stubbing methods with invalid arity" do
|
130
|
-
assert_that
|
132
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
131
133
|
|
132
|
-
assert_that
|
133
|
-
assert_that
|
134
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
135
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
134
136
|
|
135
|
-
assert_that
|
136
|
-
assert_that
|
137
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
138
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
137
139
|
|
138
|
-
assert_that
|
140
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
139
141
|
end
|
140
142
|
|
141
143
|
should "not allow calling methods with invalid arity" do
|
142
|
-
assert_that
|
144
|
+
assert_that{ subject.noargs(1) }.raises
|
143
145
|
|
144
|
-
assert_that
|
145
|
-
assert_that
|
146
|
+
assert_that{ subject.withargs }.raises
|
147
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
146
148
|
|
147
|
-
assert_that
|
148
|
-
assert_that
|
149
|
+
assert_that{ subject.minargs }.raises
|
150
|
+
assert_that{ subject.minargs(1) }.raises
|
149
151
|
|
150
|
-
assert_that
|
152
|
+
assert_that{ subject.withblock(1) }.raises
|
151
153
|
end
|
152
154
|
end
|
153
155
|
|
154
156
|
class ModuleTests < SystemTests
|
155
157
|
desc "for singleton methods on a module"
|
156
|
-
subject
|
158
|
+
subject{ TestModule }
|
157
159
|
|
158
160
|
setup do
|
159
161
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -200,33 +202,33 @@ class Assert::Stub
|
|
200
202
|
end
|
201
203
|
|
202
204
|
should "not allow stubbing methods with invalid arity" do
|
203
|
-
assert_that
|
205
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
204
206
|
|
205
|
-
assert_that
|
206
|
-
assert_that
|
207
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
208
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
207
209
|
|
208
|
-
assert_that
|
209
|
-
assert_that
|
210
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
211
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
210
212
|
|
211
|
-
assert_that
|
213
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
212
214
|
end
|
213
215
|
|
214
216
|
should "not allow calling methods with invalid arity" do
|
215
|
-
assert_that
|
217
|
+
assert_that{ subject.noargs(1) }.raises
|
216
218
|
|
217
|
-
assert_that
|
218
|
-
assert_that
|
219
|
+
assert_that{ subject.withargs }.raises
|
220
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
219
221
|
|
220
|
-
assert_that
|
221
|
-
assert_that
|
222
|
+
assert_that{ subject.minargs }.raises
|
223
|
+
assert_that{ subject.minargs(1) }.raises
|
222
224
|
|
223
|
-
assert_that
|
225
|
+
assert_that{ subject.withblock(1) }.raises
|
224
226
|
end
|
225
227
|
end
|
226
228
|
|
227
229
|
class ExtendedTests < SystemTests
|
228
230
|
desc "for extended methods"
|
229
|
-
subject
|
231
|
+
subject{ Class.new{ extend TestMixin } }
|
230
232
|
|
231
233
|
setup do
|
232
234
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -273,35 +275,35 @@ class Assert::Stub
|
|
273
275
|
end
|
274
276
|
|
275
277
|
should "not allow stubbing methods with invalid arity" do
|
276
|
-
assert_that
|
278
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
277
279
|
|
278
|
-
assert_that
|
279
|
-
assert_that
|
280
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
281
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
280
282
|
|
281
|
-
assert_that
|
282
|
-
assert_that
|
283
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
284
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
283
285
|
|
284
|
-
assert_that
|
286
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
285
287
|
end
|
286
288
|
|
287
289
|
should "not allow calling methods with invalid arity" do
|
288
|
-
assert_that
|
290
|
+
assert_that{ subject.noargs(1) }.raises
|
289
291
|
|
290
|
-
assert_that
|
291
|
-
assert_that
|
292
|
+
assert_that{ subject.withargs }.raises
|
293
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
292
294
|
|
293
|
-
assert_that
|
294
|
-
assert_that
|
295
|
+
assert_that{ subject.minargs }.raises
|
296
|
+
assert_that{ subject.minargs(1) }.raises
|
295
297
|
|
296
|
-
assert_that
|
298
|
+
assert_that{ subject.withblock(1) }.raises
|
297
299
|
end
|
298
300
|
end
|
299
301
|
|
300
302
|
class IncludedTests < SystemTests
|
301
303
|
desc "for an included method"
|
302
|
-
subject
|
303
|
-
Class.new
|
304
|
-
|
304
|
+
subject do
|
305
|
+
Class.new{ include TestMixin }.new
|
306
|
+
end
|
305
307
|
|
306
308
|
setup do
|
307
309
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -348,33 +350,33 @@ class Assert::Stub
|
|
348
350
|
end
|
349
351
|
|
350
352
|
should "not allow stubbing methods with invalid arity" do
|
351
|
-
assert_that
|
353
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
352
354
|
|
353
|
-
assert_that
|
354
|
-
assert_that
|
355
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
356
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
355
357
|
|
356
|
-
assert_that
|
357
|
-
assert_that
|
358
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
359
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
358
360
|
|
359
|
-
assert_that
|
361
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
360
362
|
end
|
361
363
|
|
362
364
|
should "not allow calling methods with invalid arity" do
|
363
|
-
assert_that
|
365
|
+
assert_that{ subject.noargs(1) }.raises
|
364
366
|
|
365
|
-
assert_that
|
366
|
-
assert_that
|
367
|
+
assert_that{ subject.withargs }.raises
|
368
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
367
369
|
|
368
|
-
assert_that
|
369
|
-
assert_that
|
370
|
+
assert_that{ subject.minargs }.raises
|
371
|
+
assert_that{ subject.minargs(1) }.raises
|
370
372
|
|
371
|
-
assert_that
|
373
|
+
assert_that{ subject.withblock(1) }.raises
|
372
374
|
end
|
373
375
|
end
|
374
376
|
|
375
377
|
class InheritedClassTests < SystemTests
|
376
378
|
desc "for an inherited class method"
|
377
|
-
subject
|
379
|
+
subject{ Class.new(TestClass) }
|
378
380
|
|
379
381
|
setup do
|
380
382
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -421,33 +423,33 @@ class Assert::Stub
|
|
421
423
|
end
|
422
424
|
|
423
425
|
should "not allow stubbing methods with invalid arity" do
|
424
|
-
assert_that
|
426
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
425
427
|
|
426
|
-
assert_that
|
427
|
-
assert_that
|
428
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
429
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
428
430
|
|
429
|
-
assert_that
|
430
|
-
assert_that
|
431
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
432
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
431
433
|
|
432
|
-
assert_that
|
434
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
433
435
|
end
|
434
436
|
|
435
437
|
should "not allow calling methods with invalid arity" do
|
436
|
-
assert_that
|
438
|
+
assert_that{ subject.noargs(1) }.raises
|
437
439
|
|
438
|
-
assert_that
|
439
|
-
assert_that
|
440
|
+
assert_that{ subject.withargs }.raises
|
441
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
440
442
|
|
441
|
-
assert_that
|
442
|
-
assert_that
|
443
|
+
assert_that{ subject.minargs }.raises
|
444
|
+
assert_that{ subject.minargs(1) }.raises
|
443
445
|
|
444
|
-
assert_that
|
446
|
+
assert_that{ subject.withblock(1) }.raises
|
445
447
|
end
|
446
448
|
end
|
447
449
|
|
448
450
|
class InheritedInstanceTests < SystemTests
|
449
451
|
desc "for an inherited instance method"
|
450
|
-
subject
|
452
|
+
subject{ Class.new(TestClass).new }
|
451
453
|
|
452
454
|
setup do
|
453
455
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -494,33 +496,33 @@ class Assert::Stub
|
|
494
496
|
end
|
495
497
|
|
496
498
|
should "not allow stubbing methods with invalid arity" do
|
497
|
-
assert_that
|
499
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
498
500
|
|
499
|
-
assert_that
|
500
|
-
assert_that
|
501
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
502
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
501
503
|
|
502
|
-
assert_that
|
503
|
-
assert_that
|
504
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
505
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
504
506
|
|
505
|
-
assert_that
|
507
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
506
508
|
end
|
507
509
|
|
508
510
|
should "not allow calling methods with invalid arity" do
|
509
|
-
assert_that
|
511
|
+
assert_that{ subject.noargs(1) }.raises
|
510
512
|
|
511
|
-
assert_that
|
512
|
-
assert_that
|
513
|
+
assert_that{ subject.withargs }.raises
|
514
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
513
515
|
|
514
|
-
assert_that
|
515
|
-
assert_that
|
516
|
+
assert_that{ subject.minargs }.raises
|
517
|
+
assert_that{ subject.minargs(1) }.raises
|
516
518
|
|
517
|
-
assert_that
|
519
|
+
assert_that{ subject.withblock(1) }.raises
|
518
520
|
end
|
519
521
|
end
|
520
522
|
|
521
523
|
class DelegateClassTests < SystemTests
|
522
524
|
desc "a class that delegates another object"
|
523
|
-
subject
|
525
|
+
subject{ DelegateClass }
|
524
526
|
|
525
527
|
setup do
|
526
528
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -567,33 +569,33 @@ class Assert::Stub
|
|
567
569
|
end
|
568
570
|
|
569
571
|
should "allow stubbing methods with invalid arity" do
|
570
|
-
assert_that
|
572
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.does_not_raise
|
571
573
|
|
572
|
-
assert_that
|
573
|
-
assert_that
|
574
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.does_not_raise
|
575
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.does_not_raise
|
574
576
|
|
575
|
-
assert_that
|
576
|
-
assert_that
|
577
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.does_not_raise
|
578
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.does_not_raise
|
577
579
|
|
578
|
-
assert_that
|
580
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.does_not_raise
|
579
581
|
end
|
580
582
|
|
581
583
|
should "allow calling methods with invalid arity" do
|
582
|
-
assert_that
|
584
|
+
assert_that{ subject.noargs(1) }.does_not_raise
|
583
585
|
|
584
|
-
assert_that
|
585
|
-
assert_that
|
586
|
+
assert_that{ subject.withargs }.does_not_raise
|
587
|
+
assert_that{ subject.withargs(1, 2) }.does_not_raise
|
586
588
|
|
587
|
-
assert_that
|
588
|
-
assert_that
|
589
|
+
assert_that{ subject.minargs }.does_not_raise
|
590
|
+
assert_that{ subject.minargs(1) }.does_not_raise
|
589
591
|
|
590
|
-
assert_that
|
592
|
+
assert_that{ subject.withblock(1) }.does_not_raise
|
591
593
|
end
|
592
594
|
end
|
593
595
|
|
594
596
|
class DelegateInstanceTests < SystemTests
|
595
597
|
desc "an instance that delegates another object"
|
596
|
-
subject
|
598
|
+
subject{ DelegateClass.new }
|
597
599
|
|
598
600
|
setup do
|
599
601
|
Assert.stub(subject, :noargs){ "default" }
|
@@ -640,27 +642,27 @@ class Assert::Stub
|
|
640
642
|
end
|
641
643
|
|
642
644
|
should "allow stubbing methods with invalid arity" do
|
643
|
-
assert_that
|
645
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.does_not_raise
|
644
646
|
|
645
|
-
assert_that
|
646
|
-
assert_that
|
647
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.does_not_raise
|
648
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.does_not_raise
|
647
649
|
|
648
|
-
assert_that
|
649
|
-
assert_that
|
650
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.does_not_raise
|
651
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.does_not_raise
|
650
652
|
|
651
|
-
assert_that
|
653
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.does_not_raise
|
652
654
|
end
|
653
655
|
|
654
656
|
should "allow calling methods with invalid arity" do
|
655
|
-
assert_that
|
657
|
+
assert_that{ subject.noargs(1) }.does_not_raise
|
656
658
|
|
657
|
-
assert_that
|
658
|
-
assert_that
|
659
|
+
assert_that{ subject.withargs }.does_not_raise
|
660
|
+
assert_that{ subject.withargs(1, 2) }.does_not_raise
|
659
661
|
|
660
|
-
assert_that
|
661
|
-
assert_that
|
662
|
+
assert_that{ subject.minargs }.does_not_raise
|
663
|
+
assert_that{ subject.minargs(1) }.does_not_raise
|
662
664
|
|
663
|
-
assert_that
|
665
|
+
assert_that{ subject.withblock(1) }.does_not_raise
|
664
666
|
end
|
665
667
|
end
|
666
668
|
|
@@ -671,8 +673,8 @@ class Assert::Stub
|
|
671
673
|
Assert.stub(child_class, :new){ "child" }
|
672
674
|
end
|
673
675
|
|
674
|
-
let(:parent_class)
|
675
|
-
let(:child_class)
|
676
|
+
let(:parent_class){ Class.new }
|
677
|
+
let(:child_class){ Class.new(parent_class) }
|
676
678
|
|
677
679
|
should "allow stubbing the methods individually" do
|
678
680
|
assert_that(parent_class.new).equals("parent")
|
@@ -681,37 +683,73 @@ class Assert::Stub
|
|
681
683
|
end
|
682
684
|
|
683
685
|
class TestClass
|
684
|
-
def self.noargs
|
685
|
-
|
686
|
-
|
687
|
-
def self.
|
688
|
-
|
689
|
-
|
690
|
-
def
|
691
|
-
|
692
|
-
|
693
|
-
def minargs(a, b, *args)
|
694
|
-
|
686
|
+
def self.noargs
|
687
|
+
end
|
688
|
+
|
689
|
+
def self.withargs(a)
|
690
|
+
end
|
691
|
+
|
692
|
+
def self.anyargs(*args)
|
693
|
+
end
|
694
|
+
|
695
|
+
def self.minargs(a, b, *args)
|
696
|
+
end
|
697
|
+
|
698
|
+
def self.withblock(&block)
|
699
|
+
end
|
700
|
+
|
701
|
+
def noargs
|
702
|
+
end
|
703
|
+
|
704
|
+
def withargs(a)
|
705
|
+
end
|
706
|
+
|
707
|
+
def anyargs(*args)
|
708
|
+
end
|
709
|
+
|
710
|
+
def minargs(a, b, *args)
|
711
|
+
end
|
712
|
+
|
713
|
+
def withblock(&block)
|
714
|
+
end
|
695
715
|
end
|
696
716
|
|
697
717
|
module TestModule
|
698
|
-
def self.noargs
|
699
|
-
|
700
|
-
|
701
|
-
def self.
|
702
|
-
|
718
|
+
def self.noargs
|
719
|
+
end
|
720
|
+
|
721
|
+
def self.withargs(a)
|
722
|
+
end
|
723
|
+
|
724
|
+
def self.anyargs(*args)
|
725
|
+
end
|
726
|
+
|
727
|
+
def self.minargs(a, b, *args)
|
728
|
+
end
|
729
|
+
|
730
|
+
def self.withblock(&block)
|
731
|
+
end
|
703
732
|
end
|
704
733
|
|
705
734
|
module TestMixin
|
706
|
-
def noargs
|
707
|
-
|
708
|
-
|
709
|
-
def
|
710
|
-
|
735
|
+
def noargs
|
736
|
+
end
|
737
|
+
|
738
|
+
def withargs(a)
|
739
|
+
end
|
740
|
+
|
741
|
+
def anyargs(*args)
|
742
|
+
end
|
743
|
+
|
744
|
+
def minargs(a, b, *args)
|
745
|
+
end
|
746
|
+
|
747
|
+
def withblock(&block)
|
748
|
+
end
|
711
749
|
end
|
712
750
|
|
713
751
|
class DelegateClass
|
714
|
-
def self.
|
752
|
+
def self.respond_to_missing?(*args)
|
715
753
|
TestClass.respond_to?(*args) || super
|
716
754
|
end
|
717
755
|
|
@@ -723,7 +761,7 @@ class Assert::Stub
|
|
723
761
|
@delegate = TestClass.new
|
724
762
|
end
|
725
763
|
|
726
|
-
def
|
764
|
+
def respond_to_missing?(*args)
|
727
765
|
@delegate.respond_to?(*args) || super
|
728
766
|
end
|
729
767
|
|