assert 2.18.2 → 2.18.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -6
- data/assert.gemspec +1 -1
- data/lib/assert/actual_value.rb +127 -0
- data/lib/assert/assertions.rb +11 -20
- data/lib/assert/context.rb +13 -5
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/macros/methods.rb +4 -4
- data/lib/assert/stub.rb +4 -0
- data/lib/assert/version.rb +1 -1
- data/test/helper.rb +23 -25
- data/test/support/factory.rb +15 -0
- data/test/system/stub_tests.rb +348 -333
- data/test/system/test_tests.rb +111 -109
- data/test/unit/actual_value_tests.rb +335 -0
- data/test/unit/assert_tests.rb +84 -59
- data/test/unit/assertions/assert_block_tests.rb +32 -31
- data/test/unit/assertions/assert_empty_tests.rb +35 -32
- data/test/unit/assertions/assert_equal_tests.rb +81 -75
- data/test/unit/assertions/assert_file_exists_tests.rb +34 -33
- data/test/unit/assertions/assert_includes_tests.rb +40 -37
- data/test/unit/assertions/assert_instance_of_tests.rb +36 -33
- data/test/unit/assertions/assert_kind_of_tests.rb +36 -33
- data/test/unit/assertions/assert_match_tests.rb +36 -33
- data/test/unit/assertions/assert_nil_tests.rb +32 -31
- data/test/unit/assertions/assert_raises_tests.rb +55 -55
- data/test/unit/assertions/assert_respond_to_tests.rb +38 -35
- data/test/unit/assertions/assert_same_tests.rb +91 -80
- data/test/unit/assertions/assert_true_false_tests.rb +64 -60
- data/test/unit/assertions_tests.rb +15 -13
- data/test/unit/config_helpers_tests.rb +36 -35
- data/test/unit/config_tests.rb +33 -34
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +70 -81
- data/test/unit/context/subject_dsl_tests.rb +16 -43
- data/test/unit/context/suite_dsl_tests.rb +16 -16
- data/test/unit/context/test_dsl_tests.rb +50 -54
- data/test/unit/context_info_tests.rb +16 -15
- data/test/unit/context_tests.rb +170 -157
- data/test/unit/default_runner_tests.rb +2 -5
- data/test/unit/default_suite_tests.rb +51 -53
- data/test/unit/factory_tests.rb +3 -3
- data/test/unit/file_line_tests.rb +31 -33
- data/test/unit/macro_tests.rb +9 -10
- data/test/unit/result_tests.rb +150 -163
- data/test/unit/runner_tests.rb +63 -63
- data/test/unit/suite_tests.rb +57 -54
- data/test/unit/test_tests.rb +134 -126
- data/test/unit/utils_tests.rb +41 -45
- data/test/unit/view_helpers_tests.rb +55 -52
- data/test/unit/view_tests.rb +20 -22
- metadata +11 -4
data/test/system/stub_tests.rb
CHANGED
@@ -8,676 +8,691 @@ class Assert::Stub
|
|
8
8
|
|
9
9
|
class InstanceTests < SystemTests
|
10
10
|
desc "for instance methods"
|
11
|
+
subject { instance1 }
|
12
|
+
|
11
13
|
setup do
|
12
|
-
|
13
|
-
Assert.stub(
|
14
|
-
Assert.stub(@instance, :noargs).with{ "none" }
|
14
|
+
Assert.stub(instance1, :noargs){ "default" }
|
15
|
+
Assert.stub(instance1, :noargs).with{ "none" }
|
15
16
|
|
16
|
-
Assert.stub(
|
17
|
-
Assert.stub(
|
17
|
+
Assert.stub(instance1, :withargs){ "default" }
|
18
|
+
Assert.stub(instance1, :withargs).with(1){ "one" }
|
18
19
|
|
19
|
-
Assert.stub(
|
20
|
-
Assert.stub(
|
20
|
+
Assert.stub(instance1, :anyargs){ "default" }
|
21
|
+
Assert.stub(instance1, :anyargs).with(1, 2){ "one-two" }
|
21
22
|
|
22
|
-
Assert.stub(
|
23
|
-
Assert.stub(
|
24
|
-
Assert.stub(
|
23
|
+
Assert.stub(instance1, :minargs){ "default" }
|
24
|
+
Assert.stub(instance1, :minargs).with(1, 2){ "one-two" }
|
25
|
+
Assert.stub(instance1, :minargs).with(1, 2, 3){ "one-two-three" }
|
25
26
|
|
26
|
-
Assert.stub(
|
27
|
+
Assert.stub(instance1, :withblock){ "default" }
|
27
28
|
end
|
28
|
-
|
29
|
+
|
30
|
+
let(:instance1) { TestClass.new }
|
29
31
|
|
30
32
|
should "allow stubbing a method that doesn't take args" do
|
31
|
-
|
33
|
+
assert_that(subject.noargs).equals("none")
|
32
34
|
end
|
33
35
|
|
34
36
|
should "allow stubbing a method that takes args" do
|
35
|
-
|
36
|
-
assert_equal "default", subject.withargs(2)
|
37
|
+
assert_that(subject.withargs(2)).equals("default")
|
37
38
|
end
|
38
39
|
|
39
40
|
should "allow stubbing a method that takes any args" do
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
assert_that(subject.anyargs).equals("default")
|
42
|
+
assert_that(subject.anyargs(1)).equals("default")
|
43
|
+
assert_that(subject.anyargs(1, 2)).equals("one-two")
|
43
44
|
end
|
44
45
|
|
45
46
|
should "allow stubbing a method that takes a minimum number of args" do
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
assert_that(subject.minargs(1, 2)).equals("one-two")
|
48
|
+
assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
|
49
|
+
assert_that(subject.minargs(1, 2, 4)).equals("default")
|
50
|
+
assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
|
50
51
|
end
|
51
52
|
|
52
53
|
should "allow stubbing a method that takes a block" do
|
53
|
-
|
54
|
-
|
54
|
+
assert_that(subject.withblock).equals("default")
|
55
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
55
56
|
end
|
56
57
|
|
57
58
|
should "not allow stubbing methods with invalid arity" do
|
58
|
-
|
59
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
62
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
62
63
|
|
63
|
-
|
64
|
-
|
64
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
65
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
65
66
|
|
66
|
-
|
67
|
+
assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
|
67
68
|
end
|
68
69
|
|
69
70
|
should "not allow calling methods with invalid arity" do
|
70
|
-
|
71
|
+
assert_that(-> { subject.noargs(1) }).raises
|
71
72
|
|
72
|
-
|
73
|
-
|
73
|
+
assert_that(-> { subject.withargs }).raises
|
74
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
74
75
|
|
75
|
-
|
76
|
-
|
76
|
+
assert_that(-> { subject.minargs }).raises
|
77
|
+
assert_that(-> { subject.minargs(1) }).raises
|
77
78
|
|
78
|
-
|
79
|
+
assert_that(-> { subject.withblock(1) }).raises
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
82
83
|
class ClassTests < SystemTests
|
83
84
|
desc "for singleton methods on a class"
|
85
|
+
subject { class1 }
|
86
|
+
|
84
87
|
setup do
|
85
|
-
|
86
|
-
Assert.stub(
|
87
|
-
Assert.stub(@class, :noargs).with{ "none" }
|
88
|
+
Assert.stub(class1, :noargs){ "default" }
|
89
|
+
Assert.stub(class1, :noargs).with{ "none" }
|
88
90
|
|
89
|
-
Assert.stub(
|
90
|
-
Assert.stub(
|
91
|
+
Assert.stub(class1, :withargs){ "default" }
|
92
|
+
Assert.stub(class1, :withargs).with(1){ "one" }
|
91
93
|
|
92
|
-
Assert.stub(
|
93
|
-
Assert.stub(
|
94
|
+
Assert.stub(class1, :anyargs){ "default" }
|
95
|
+
Assert.stub(class1, :anyargs).with(1, 2){ "one-two" }
|
94
96
|
|
95
|
-
Assert.stub(
|
96
|
-
Assert.stub(
|
97
|
-
Assert.stub(
|
97
|
+
Assert.stub(class1, :minargs){ "default" }
|
98
|
+
Assert.stub(class1, :minargs).with(1, 2){ "one-two" }
|
99
|
+
Assert.stub(class1, :minargs).with(1, 2, 3){ "one-two-three" }
|
98
100
|
|
99
|
-
Assert.stub(
|
101
|
+
Assert.stub(class1, :withblock){ "default" }
|
100
102
|
end
|
101
|
-
|
103
|
+
|
104
|
+
let(:class1) { TestClass }
|
102
105
|
|
103
106
|
should "allow stubbing a method that doesn't take args" do
|
104
|
-
|
107
|
+
assert_that(subject.noargs).equals("none")
|
105
108
|
end
|
106
109
|
|
107
110
|
should "allow stubbing a method that takes args" do
|
108
|
-
|
109
|
-
|
111
|
+
assert_that(subject.withargs(1)).equals("one")
|
112
|
+
assert_that(subject.withargs(2)).equals("default")
|
110
113
|
end
|
111
114
|
|
112
115
|
should "allow stubbing a method that takes any args" do
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
+
assert_that(subject.anyargs).equals("default")
|
117
|
+
assert_that(subject.anyargs(1)).equals("default")
|
118
|
+
assert_that(subject.anyargs(1, 2)).equals("one-two")
|
116
119
|
end
|
117
120
|
|
118
121
|
should "allow stubbing a method that takes a minimum number of args" do
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
122
|
+
assert_that(subject.minargs(1, 2)).equals("one-two")
|
123
|
+
assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
|
124
|
+
assert_that(subject.minargs(1, 2, 4)).equals("default")
|
125
|
+
assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
|
123
126
|
end
|
124
127
|
|
125
128
|
should "allow stubbing a method that takes a block" do
|
126
|
-
|
127
|
-
|
129
|
+
assert_that(subject.withblock).equals("default")
|
130
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
128
131
|
end
|
129
132
|
|
130
133
|
should "not allow stubbing methods with invalid arity" do
|
131
|
-
|
134
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
132
135
|
|
133
|
-
|
134
|
-
|
136
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
137
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
135
138
|
|
136
|
-
|
137
|
-
|
139
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
140
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
138
141
|
|
139
|
-
|
142
|
+
assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
|
140
143
|
end
|
141
144
|
|
142
145
|
should "not allow calling methods with invalid arity" do
|
143
|
-
|
146
|
+
assert_that(-> { subject.noargs(1) }).raises
|
144
147
|
|
145
|
-
|
146
|
-
|
148
|
+
assert_that(-> { subject.withargs }).raises
|
149
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
147
150
|
|
148
|
-
|
149
|
-
|
151
|
+
assert_that(-> { subject.minargs }).raises
|
152
|
+
assert_that(-> { subject.minargs(1) }).raises
|
150
153
|
|
151
|
-
|
154
|
+
assert_that(-> { subject.withblock(1) }).raises
|
152
155
|
end
|
153
156
|
end
|
154
157
|
|
155
158
|
class ModuleTests < SystemTests
|
156
159
|
desc "for singleton methods on a module"
|
160
|
+
subject { module1 }
|
161
|
+
|
157
162
|
setup do
|
158
|
-
|
159
|
-
Assert.stub(
|
160
|
-
Assert.stub(@module, :noargs).with{ "none" }
|
163
|
+
Assert.stub(module1, :noargs){ "default" }
|
164
|
+
Assert.stub(module1, :noargs).with{ "none" }
|
161
165
|
|
162
|
-
Assert.stub(
|
163
|
-
Assert.stub(
|
166
|
+
Assert.stub(module1, :withargs){ "default" }
|
167
|
+
Assert.stub(module1, :withargs).with(1){ "one" }
|
164
168
|
|
165
|
-
Assert.stub(
|
166
|
-
Assert.stub(
|
169
|
+
Assert.stub(module1, :anyargs){ "default" }
|
170
|
+
Assert.stub(module1, :anyargs).with(1, 2){ "one-two" }
|
167
171
|
|
168
|
-
Assert.stub(
|
169
|
-
Assert.stub(
|
170
|
-
Assert.stub(
|
172
|
+
Assert.stub(module1, :minargs){ "default" }
|
173
|
+
Assert.stub(module1, :minargs).with(1, 2){ "one-two" }
|
174
|
+
Assert.stub(module1, :minargs).with(1, 2, 3){ "one-two-three" }
|
171
175
|
|
172
|
-
Assert.stub(
|
176
|
+
Assert.stub(module1, :withblock){ "default" }
|
173
177
|
end
|
174
|
-
|
178
|
+
|
179
|
+
let(:module1) { TestModule }
|
175
180
|
|
176
181
|
should "allow stubbing a method that doesn't take args" do
|
177
|
-
|
182
|
+
assert_that(subject.noargs).equals("none")
|
178
183
|
end
|
179
184
|
|
180
185
|
should "allow stubbing a method that takes args" do
|
181
|
-
|
182
|
-
|
186
|
+
assert_that(subject.withargs(1)).equals("one")
|
187
|
+
assert_that(subject.withargs(2)).equals("default")
|
183
188
|
end
|
184
189
|
|
185
190
|
should "allow stubbing a method that takes any args" do
|
186
|
-
|
187
|
-
|
188
|
-
|
191
|
+
assert_that(subject.anyargs).equals("default")
|
192
|
+
assert_that(subject.anyargs(1)).equals("default")
|
193
|
+
assert_that(subject.anyargs(1, 2)).equals("one-two")
|
189
194
|
end
|
190
195
|
|
191
196
|
should "allow stubbing a method that takes a minimum number of args" do
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
197
|
+
assert_that(subject.minargs(1, 2)).equals("one-two")
|
198
|
+
assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
|
199
|
+
assert_that(subject.minargs(1, 2, 4)).equals("default")
|
200
|
+
assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
|
196
201
|
end
|
197
202
|
|
198
203
|
should "allow stubbing a method that takes a block" do
|
199
|
-
|
200
|
-
|
204
|
+
assert_that(subject.withblock).equals("default")
|
205
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
201
206
|
end
|
202
207
|
|
203
208
|
should "not allow stubbing methods with invalid arity" do
|
204
|
-
|
209
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
205
210
|
|
206
|
-
|
207
|
-
|
211
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
212
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
208
213
|
|
209
|
-
|
210
|
-
|
214
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
215
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
211
216
|
|
212
|
-
|
217
|
+
assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
|
213
218
|
end
|
214
219
|
|
215
220
|
should "not allow calling methods with invalid arity" do
|
216
|
-
|
221
|
+
assert_that(-> { subject.noargs(1) }).raises
|
217
222
|
|
218
|
-
|
219
|
-
|
223
|
+
assert_that(-> { subject.withargs }).raises
|
224
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
220
225
|
|
221
|
-
|
222
|
-
|
226
|
+
assert_that(-> { subject.minargs }).raises
|
227
|
+
assert_that(-> { subject.minargs(1) }).raises
|
223
228
|
|
224
|
-
|
229
|
+
assert_that(-> { subject.withblock(1) }).raises
|
225
230
|
end
|
226
231
|
end
|
227
232
|
|
228
233
|
class ExtendedTests < SystemTests
|
229
234
|
desc "for extended methods"
|
235
|
+
subject { class1 }
|
236
|
+
|
230
237
|
setup do
|
231
|
-
|
232
|
-
Assert.stub(
|
233
|
-
Assert.stub(@class, :noargs).with{ "none" }
|
238
|
+
Assert.stub(class1, :noargs){ "default" }
|
239
|
+
Assert.stub(class1, :noargs).with{ "none" }
|
234
240
|
|
235
|
-
Assert.stub(
|
236
|
-
Assert.stub(
|
241
|
+
Assert.stub(class1, :withargs){ "default" }
|
242
|
+
Assert.stub(class1, :withargs).with(1){ "one" }
|
237
243
|
|
238
|
-
Assert.stub(
|
239
|
-
Assert.stub(
|
244
|
+
Assert.stub(class1, :anyargs){ "default" }
|
245
|
+
Assert.stub(class1, :anyargs).with(1, 2){ "one-two" }
|
240
246
|
|
241
|
-
Assert.stub(
|
242
|
-
Assert.stub(
|
243
|
-
Assert.stub(
|
247
|
+
Assert.stub(class1, :minargs){ "default" }
|
248
|
+
Assert.stub(class1, :minargs).with(1, 2){ "one-two" }
|
249
|
+
Assert.stub(class1, :minargs).with(1, 2, 3){ "one-two-three" }
|
244
250
|
|
245
|
-
Assert.stub(
|
251
|
+
Assert.stub(class1, :withblock){ "default" }
|
246
252
|
end
|
247
|
-
|
253
|
+
|
254
|
+
let(:class1) { Class.new{ extend TestMixin } }
|
248
255
|
|
249
256
|
should "allow stubbing a method that doesn't take args" do
|
250
|
-
|
257
|
+
assert_that(subject.noargs).equals("none")
|
251
258
|
end
|
252
259
|
|
253
260
|
should "allow stubbing a method that takes args" do
|
254
|
-
|
255
|
-
|
261
|
+
assert_that(subject.withargs(1)).equals("one")
|
262
|
+
assert_that(subject.withargs(2)).equals("default")
|
256
263
|
end
|
257
264
|
|
258
265
|
should "allow stubbing a method that takes any args" do
|
259
|
-
|
260
|
-
|
261
|
-
|
266
|
+
assert_that(subject.anyargs).equals("default")
|
267
|
+
assert_that(subject.anyargs(1)).equals("default")
|
268
|
+
assert_that(subject.anyargs(1, 2)).equals("one-two")
|
262
269
|
end
|
263
270
|
|
264
271
|
should "allow stubbing a method that takes a minimum number of args" do
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
272
|
+
assert_that(subject.minargs(1, 2)).equals("one-two")
|
273
|
+
assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
|
274
|
+
assert_that(subject.minargs(1, 2, 4)).equals("default")
|
275
|
+
assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
|
269
276
|
end
|
270
277
|
|
271
278
|
should "allow stubbing a method that takes a block" do
|
272
|
-
|
273
|
-
|
279
|
+
assert_that(subject.withblock).equals("default")
|
280
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
274
281
|
end
|
275
282
|
|
276
283
|
should "not allow stubbing methods with invalid arity" do
|
277
|
-
|
284
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
278
285
|
|
279
|
-
|
280
|
-
|
286
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
287
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
281
288
|
|
282
|
-
|
283
|
-
|
289
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
290
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
284
291
|
|
285
|
-
|
292
|
+
assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
|
286
293
|
end
|
287
294
|
|
288
295
|
should "not allow calling methods with invalid arity" do
|
289
|
-
|
296
|
+
assert_that(-> { subject.noargs(1) }).raises
|
290
297
|
|
291
|
-
|
292
|
-
|
298
|
+
assert_that(-> { subject.withargs }).raises
|
299
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
293
300
|
|
294
|
-
|
295
|
-
|
301
|
+
assert_that(-> { subject.minargs }).raises
|
302
|
+
assert_that(-> { subject.minargs(1) }).raises
|
296
303
|
|
297
|
-
|
304
|
+
assert_that(-> { subject.withblock(1) }).raises
|
298
305
|
end
|
299
306
|
end
|
300
307
|
|
301
308
|
class IncludedTests < SystemTests
|
302
309
|
desc "for an included method"
|
310
|
+
subject { instance1 }
|
311
|
+
|
303
312
|
setup do
|
304
|
-
|
305
|
-
|
306
|
-
Assert.stub(@instance, :noargs){ "default" }
|
307
|
-
Assert.stub(@instance, :noargs).with{ "none" }
|
313
|
+
Assert.stub(instance1, :noargs){ "default" }
|
314
|
+
Assert.stub(instance1, :noargs).with{ "none" }
|
308
315
|
|
309
|
-
Assert.stub(
|
310
|
-
Assert.stub(
|
316
|
+
Assert.stub(instance1, :withargs){ "default" }
|
317
|
+
Assert.stub(instance1, :withargs).with(1){ "one" }
|
311
318
|
|
312
|
-
Assert.stub(
|
313
|
-
Assert.stub(
|
319
|
+
Assert.stub(instance1, :anyargs){ "default" }
|
320
|
+
Assert.stub(instance1, :anyargs).with(1, 2){ "one-two" }
|
314
321
|
|
315
|
-
Assert.stub(
|
316
|
-
Assert.stub(
|
317
|
-
Assert.stub(
|
322
|
+
Assert.stub(instance1, :minargs){ "default" }
|
323
|
+
Assert.stub(instance1, :minargs).with(1, 2){ "one-two" }
|
324
|
+
Assert.stub(instance1, :minargs).with(1, 2, 3){ "one-two-three" }
|
318
325
|
|
319
|
-
Assert.stub(
|
326
|
+
Assert.stub(instance1, :withblock){ "default" }
|
320
327
|
end
|
321
|
-
|
328
|
+
|
329
|
+
let(:instance1) { Class.new { include TestMixin }.new }
|
322
330
|
|
323
331
|
should "allow stubbing a method that doesn't take args" do
|
324
|
-
|
332
|
+
assert_that(subject.noargs).equals("none")
|
325
333
|
end
|
326
334
|
|
327
335
|
should "allow stubbing a method that takes args" do
|
328
|
-
|
329
|
-
|
336
|
+
assert_that(subject.withargs(1)).equals("one")
|
337
|
+
assert_that(subject.withargs(2)).equals("default")
|
330
338
|
end
|
331
339
|
|
332
340
|
should "allow stubbing a method that takes any args" do
|
333
|
-
|
334
|
-
|
335
|
-
|
341
|
+
assert_that(subject.anyargs).equals("default")
|
342
|
+
assert_that(subject.anyargs(1)).equals("default")
|
343
|
+
assert_that(subject.anyargs(1, 2)).equals("one-two")
|
336
344
|
end
|
337
345
|
|
338
346
|
should "allow stubbing a method that takes a minimum number of args" do
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
347
|
+
assert_that(subject.minargs(1, 2)).equals("one-two")
|
348
|
+
assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
|
349
|
+
assert_that(subject.minargs(1, 2, 4)).equals("default")
|
350
|
+
assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
|
343
351
|
end
|
344
352
|
|
345
353
|
should "allow stubbing a method that takes a block" do
|
346
|
-
|
347
|
-
|
354
|
+
assert_that(subject.withblock).equals("default")
|
355
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
348
356
|
end
|
349
357
|
|
350
358
|
should "not allow stubbing methods with invalid arity" do
|
351
|
-
|
359
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
352
360
|
|
353
|
-
|
354
|
-
|
361
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
362
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
355
363
|
|
356
|
-
|
357
|
-
|
364
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
365
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
358
366
|
|
359
|
-
|
367
|
+
assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
|
360
368
|
end
|
361
369
|
|
362
370
|
should "not allow calling methods with invalid arity" do
|
363
|
-
|
371
|
+
assert_that(-> { subject.noargs(1) }).raises
|
364
372
|
|
365
|
-
|
366
|
-
|
373
|
+
assert_that(-> { subject.withargs }).raises
|
374
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
367
375
|
|
368
|
-
|
369
|
-
|
376
|
+
assert_that(-> { subject.minargs }).raises
|
377
|
+
assert_that(-> { subject.minargs(1) }).raises
|
370
378
|
|
371
|
-
|
379
|
+
assert_that(-> { subject.withblock(1) }).raises
|
372
380
|
end
|
373
381
|
end
|
374
382
|
|
375
383
|
class InheritedClassTests < SystemTests
|
376
384
|
desc "for an inherited class method"
|
385
|
+
subject { class1 }
|
386
|
+
|
377
387
|
setup do
|
378
|
-
|
379
|
-
Assert.stub(
|
380
|
-
Assert.stub(@class, :noargs).with{ "none" }
|
388
|
+
Assert.stub(class1, :noargs){ "default" }
|
389
|
+
Assert.stub(class1, :noargs).with{ "none" }
|
381
390
|
|
382
|
-
Assert.stub(
|
383
|
-
Assert.stub(
|
391
|
+
Assert.stub(class1, :withargs){ "default" }
|
392
|
+
Assert.stub(class1, :withargs).with(1){ "one" }
|
384
393
|
|
385
|
-
Assert.stub(
|
386
|
-
Assert.stub(
|
394
|
+
Assert.stub(class1, :anyargs){ "default" }
|
395
|
+
Assert.stub(class1, :anyargs).with(1, 2){ "one-two" }
|
387
396
|
|
388
|
-
Assert.stub(
|
389
|
-
Assert.stub(
|
390
|
-
Assert.stub(
|
397
|
+
Assert.stub(class1, :minargs){ "default" }
|
398
|
+
Assert.stub(class1, :minargs).with(1, 2){ "one-two" }
|
399
|
+
Assert.stub(class1, :minargs).with(1, 2, 3){ "one-two-three" }
|
391
400
|
|
392
|
-
Assert.stub(
|
401
|
+
Assert.stub(class1, :withblock){ "default" }
|
393
402
|
end
|
394
|
-
|
403
|
+
|
404
|
+
let(:class1) { Class.new(TestClass) }
|
395
405
|
|
396
406
|
should "allow stubbing a method that doesn't take args" do
|
397
|
-
|
407
|
+
assert_that(subject.noargs).equals("none")
|
398
408
|
end
|
399
409
|
|
400
410
|
should "allow stubbing a method that takes args" do
|
401
|
-
|
402
|
-
|
411
|
+
assert_that(subject.withargs(1)).equals("one")
|
412
|
+
assert_that(subject.withargs(2)).equals("default")
|
403
413
|
end
|
404
414
|
|
405
415
|
should "allow stubbing a method that takes any args" do
|
406
|
-
|
407
|
-
|
408
|
-
|
416
|
+
assert_that(subject.anyargs).equals("default")
|
417
|
+
assert_that(subject.anyargs(1)).equals("default")
|
418
|
+
assert_that(subject.anyargs(1, 2)).equals("one-two")
|
409
419
|
end
|
410
420
|
|
411
421
|
should "allow stubbing a method that takes a minimum number of args" do
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
422
|
+
assert_that(subject.minargs(1, 2)).equals("one-two")
|
423
|
+
assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
|
424
|
+
assert_that(subject.minargs(1, 2, 4)).equals("default")
|
425
|
+
assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
|
416
426
|
end
|
417
427
|
|
418
428
|
should "allow stubbing a method that takes a block" do
|
419
|
-
|
420
|
-
|
429
|
+
assert_that(subject.withblock).equals("default")
|
430
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
421
431
|
end
|
422
432
|
|
423
433
|
should "not allow stubbing methods with invalid arity" do
|
424
|
-
|
434
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
425
435
|
|
426
|
-
|
427
|
-
|
436
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
437
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
428
438
|
|
429
|
-
|
430
|
-
|
439
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
440
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
431
441
|
|
432
|
-
|
442
|
+
assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
|
433
443
|
end
|
434
444
|
|
435
445
|
should "not allow calling methods with invalid arity" do
|
436
|
-
|
446
|
+
assert_that(-> { subject.noargs(1) }).raises
|
437
447
|
|
438
|
-
|
439
|
-
|
448
|
+
assert_that(-> { subject.withargs }).raises
|
449
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
440
450
|
|
441
|
-
|
442
|
-
|
451
|
+
assert_that(-> { subject.minargs }).raises
|
452
|
+
assert_that(-> { subject.minargs(1) }).raises
|
443
453
|
|
444
|
-
|
454
|
+
assert_that(-> { subject.withblock(1) }).raises
|
445
455
|
end
|
446
456
|
end
|
447
457
|
|
448
458
|
class InheritedInstanceTests < SystemTests
|
449
459
|
desc "for an inherited instance method"
|
460
|
+
subject { instance1 }
|
461
|
+
|
450
462
|
setup do
|
451
|
-
|
452
|
-
|
453
|
-
Assert.stub(@instance, :noargs){ "default" }
|
454
|
-
Assert.stub(@instance, :noargs).with{ "none" }
|
463
|
+
Assert.stub(instance1, :noargs){ "default" }
|
464
|
+
Assert.stub(instance1, :noargs).with{ "none" }
|
455
465
|
|
456
|
-
Assert.stub(
|
457
|
-
Assert.stub(
|
466
|
+
Assert.stub(instance1, :withargs){ "default" }
|
467
|
+
Assert.stub(instance1, :withargs).with(1){ "one" }
|
458
468
|
|
459
|
-
Assert.stub(
|
460
|
-
Assert.stub(
|
469
|
+
Assert.stub(instance1, :anyargs){ "default" }
|
470
|
+
Assert.stub(instance1, :anyargs).with(1, 2){ "one-two" }
|
461
471
|
|
462
|
-
Assert.stub(
|
463
|
-
Assert.stub(
|
464
|
-
Assert.stub(
|
472
|
+
Assert.stub(instance1, :minargs){ "default" }
|
473
|
+
Assert.stub(instance1, :minargs).with(1, 2){ "one-two" }
|
474
|
+
Assert.stub(instance1, :minargs).with(1, 2, 3){ "one-two-three" }
|
465
475
|
|
466
|
-
Assert.stub(
|
476
|
+
Assert.stub(instance1, :withblock){ "default" }
|
467
477
|
end
|
468
|
-
|
478
|
+
|
479
|
+
let(:instance1) { Class.new(TestClass).new }
|
469
480
|
|
470
481
|
should "allow stubbing a method that doesn't take args" do
|
471
|
-
|
482
|
+
assert_that(subject.noargs).equals("none")
|
472
483
|
end
|
473
484
|
|
474
485
|
should "allow stubbing a method that takes args" do
|
475
|
-
|
476
|
-
|
486
|
+
assert_that(subject.withargs(1)).equals("one")
|
487
|
+
assert_that(subject.withargs(2)).equals("default")
|
477
488
|
end
|
478
489
|
|
479
490
|
should "allow stubbing a method that takes any args" do
|
480
|
-
|
481
|
-
|
482
|
-
|
491
|
+
assert_that(subject.anyargs).equals("default")
|
492
|
+
assert_that(subject.anyargs(1)).equals("default")
|
493
|
+
assert_that(subject.anyargs(1, 2)).equals("one-two")
|
483
494
|
end
|
484
495
|
|
485
496
|
should "allow stubbing a method that takes a minimum number of args" do
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
497
|
+
assert_that(subject.minargs(1, 2)).equals("one-two")
|
498
|
+
assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
|
499
|
+
assert_that(subject.minargs(1, 2, 4)).equals("default")
|
500
|
+
assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
|
490
501
|
end
|
491
502
|
|
492
503
|
should "allow stubbing a method that takes a block" do
|
493
|
-
|
494
|
-
|
504
|
+
assert_that(subject.withblock).equals("default")
|
505
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
495
506
|
end
|
496
507
|
|
497
508
|
should "not allow stubbing methods with invalid arity" do
|
498
|
-
|
509
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).raises
|
499
510
|
|
500
|
-
|
501
|
-
|
511
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).raises
|
512
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).raises
|
502
513
|
|
503
|
-
|
504
|
-
|
514
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).raises
|
515
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).raises
|
505
516
|
|
506
|
-
|
517
|
+
assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).raises
|
507
518
|
end
|
508
519
|
|
509
520
|
should "not allow calling methods with invalid arity" do
|
510
|
-
|
521
|
+
assert_that(-> { subject.noargs(1) }).raises
|
511
522
|
|
512
|
-
|
513
|
-
|
523
|
+
assert_that(-> { subject.withargs }).raises
|
524
|
+
assert_that(-> { subject.withargs(1, 2) }).raises
|
514
525
|
|
515
|
-
|
516
|
-
|
526
|
+
assert_that(-> { subject.minargs }).raises
|
527
|
+
assert_that(-> { subject.minargs(1) }).raises
|
517
528
|
|
518
|
-
|
529
|
+
assert_that(-> { subject.withblock(1) }).raises
|
519
530
|
end
|
520
531
|
end
|
521
532
|
|
522
533
|
class DelegateClassTests < SystemTests
|
523
534
|
desc "a class that delegates another object"
|
535
|
+
subject { class1 }
|
536
|
+
|
524
537
|
setup do
|
525
|
-
|
526
|
-
Assert.stub(
|
527
|
-
Assert.stub(@class, :noargs).with{ "none" }
|
538
|
+
Assert.stub(class1, :noargs){ "default" }
|
539
|
+
Assert.stub(class1, :noargs).with{ "none" }
|
528
540
|
|
529
|
-
Assert.stub(
|
530
|
-
Assert.stub(
|
541
|
+
Assert.stub(class1, :withargs){ "default" }
|
542
|
+
Assert.stub(class1, :withargs).with(1){ "one" }
|
531
543
|
|
532
|
-
Assert.stub(
|
533
|
-
Assert.stub(
|
544
|
+
Assert.stub(class1, :anyargs){ "default" }
|
545
|
+
Assert.stub(class1, :anyargs).with(1, 2){ "one-two" }
|
534
546
|
|
535
|
-
Assert.stub(
|
536
|
-
Assert.stub(
|
537
|
-
Assert.stub(
|
547
|
+
Assert.stub(class1, :minargs){ "default" }
|
548
|
+
Assert.stub(class1, :minargs).with(1, 2){ "one-two" }
|
549
|
+
Assert.stub(class1, :minargs).with(1, 2, 3){ "one-two-three" }
|
538
550
|
|
539
|
-
Assert.stub(
|
551
|
+
Assert.stub(class1, :withblock){ "default" }
|
540
552
|
end
|
541
|
-
|
553
|
+
|
554
|
+
let(:class1) { DelegateClass }
|
542
555
|
|
543
556
|
should "allow stubbing a method that doesn't take args" do
|
544
|
-
|
557
|
+
assert_that(subject.noargs).equals("none")
|
545
558
|
end
|
546
559
|
|
547
560
|
should "allow stubbing a method that takes args" do
|
548
|
-
|
549
|
-
|
561
|
+
assert_that(subject.withargs(1)).equals("one")
|
562
|
+
assert_that(subject.withargs(2)).equals("default")
|
550
563
|
end
|
551
564
|
|
552
565
|
should "allow stubbing a method that takes any args" do
|
553
|
-
|
554
|
-
|
555
|
-
|
566
|
+
assert_that(subject.anyargs).equals("default")
|
567
|
+
assert_that(subject.anyargs(1)).equals("default")
|
568
|
+
assert_that(subject.anyargs(1, 2)).equals("one-two")
|
556
569
|
end
|
557
570
|
|
558
571
|
should "allow stubbing a method that takes a minimum number of args" do
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
572
|
+
assert_that(subject.minargs(1, 2)).equals("one-two")
|
573
|
+
assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
|
574
|
+
assert_that(subject.minargs(1, 2, 4)).equals("default")
|
575
|
+
assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
|
563
576
|
end
|
564
577
|
|
565
578
|
should "allow stubbing a method that takes a block" do
|
566
|
-
|
567
|
-
|
579
|
+
assert_that(subject.withblock).equals("default")
|
580
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
568
581
|
end
|
569
582
|
|
570
583
|
should "allow stubbing methods with invalid arity" do
|
571
|
-
|
584
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).does_not_raise
|
572
585
|
|
573
|
-
|
574
|
-
|
586
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).does_not_raise
|
587
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).does_not_raise
|
575
588
|
|
576
|
-
|
577
|
-
|
589
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).does_not_raise
|
590
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).does_not_raise
|
578
591
|
|
579
|
-
|
592
|
+
assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).does_not_raise
|
580
593
|
end
|
581
594
|
|
582
595
|
should "allow calling methods with invalid arity" do
|
583
|
-
|
596
|
+
assert_that(-> { subject.noargs(1) }).does_not_raise
|
584
597
|
|
585
|
-
|
586
|
-
|
598
|
+
assert_that(-> { subject.withargs }).does_not_raise
|
599
|
+
assert_that(-> { subject.withargs(1, 2) }).does_not_raise
|
587
600
|
|
588
|
-
|
589
|
-
|
601
|
+
assert_that(-> { subject.minargs }).does_not_raise
|
602
|
+
assert_that(-> { subject.minargs(1) }).does_not_raise
|
590
603
|
|
591
|
-
|
604
|
+
assert_that(-> { subject.withblock(1) }).does_not_raise
|
592
605
|
end
|
593
606
|
end
|
594
607
|
|
595
608
|
class DelegateInstanceTests < SystemTests
|
596
609
|
desc "an instance that delegates another object"
|
610
|
+
subject { instance1 }
|
611
|
+
|
597
612
|
setup do
|
598
|
-
|
599
|
-
Assert.stub(
|
600
|
-
Assert.stub(@instance, :noargs).with{ "none" }
|
613
|
+
Assert.stub(instance1, :noargs){ "default" }
|
614
|
+
Assert.stub(instance1, :noargs).with{ "none" }
|
601
615
|
|
602
|
-
Assert.stub(
|
603
|
-
Assert.stub(
|
616
|
+
Assert.stub(instance1, :withargs){ "default" }
|
617
|
+
Assert.stub(instance1, :withargs).with(1){ "one" }
|
604
618
|
|
605
|
-
Assert.stub(
|
606
|
-
Assert.stub(
|
619
|
+
Assert.stub(instance1, :anyargs){ "default" }
|
620
|
+
Assert.stub(instance1, :anyargs).with(1, 2){ "one-two" }
|
607
621
|
|
608
|
-
Assert.stub(
|
609
|
-
Assert.stub(
|
610
|
-
Assert.stub(
|
622
|
+
Assert.stub(instance1, :minargs){ "default" }
|
623
|
+
Assert.stub(instance1, :minargs).with(1, 2){ "one-two" }
|
624
|
+
Assert.stub(instance1, :minargs).with(1, 2, 3){ "one-two-three" }
|
611
625
|
|
612
|
-
Assert.stub(
|
626
|
+
Assert.stub(instance1, :withblock){ "default" }
|
613
627
|
end
|
614
|
-
|
628
|
+
|
629
|
+
let(:instance1) { DelegateClass.new }
|
615
630
|
|
616
631
|
should "allow stubbing a method that doesn't take args" do
|
617
|
-
|
632
|
+
assert_that(subject.noargs).equals("none")
|
618
633
|
end
|
619
634
|
|
620
635
|
should "allow stubbing a method that takes args" do
|
621
|
-
|
622
|
-
|
636
|
+
assert_that(subject.withargs(1)).equals("one")
|
637
|
+
assert_that(subject.withargs(2)).equals("default")
|
623
638
|
end
|
624
639
|
|
625
640
|
should "allow stubbing a method that takes any args" do
|
626
|
-
|
627
|
-
|
628
|
-
|
641
|
+
assert_that(subject.anyargs).equals("default")
|
642
|
+
assert_that(subject.anyargs(1)).equals("default")
|
643
|
+
assert_that(subject.anyargs(1, 2)).equals("one-two")
|
629
644
|
end
|
630
645
|
|
631
646
|
should "allow stubbing a method that takes a minimum number of args" do
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
647
|
+
assert_that(subject.minargs(1, 2)).equals("one-two")
|
648
|
+
assert_that(subject.minargs(1, 2, 3)).equals("one-two-three")
|
649
|
+
assert_that(subject.minargs(1, 2, 4)).equals("default")
|
650
|
+
assert_that(subject.minargs(1, 2, 3, 4)).equals("default")
|
636
651
|
end
|
637
652
|
|
638
653
|
should "allow stubbing a method that takes a block" do
|
639
|
-
|
640
|
-
|
654
|
+
assert_that(subject.withblock).equals("default")
|
655
|
+
assert_that(subject.withblock{ "my-block" }).equals("default")
|
641
656
|
end
|
642
657
|
|
643
658
|
should "allow stubbing methods with invalid arity" do
|
644
|
-
|
659
|
+
assert_that(-> { Assert.stub(subject, :noargs).with(1){ } }).does_not_raise
|
645
660
|
|
646
|
-
|
647
|
-
|
661
|
+
assert_that(-> { Assert.stub(subject, :withargs).with{ } }).does_not_raise
|
662
|
+
assert_that(-> { Assert.stub(subject, :withargs).with(1, 2){ } }).does_not_raise
|
648
663
|
|
649
|
-
|
650
|
-
|
664
|
+
assert_that(-> { Assert.stub(subject, :minargs).with{ } }).does_not_raise
|
665
|
+
assert_that(-> { Assert.stub(subject, :minargs).with(1){ } }).does_not_raise
|
651
666
|
|
652
|
-
|
667
|
+
assert_that(-> { Assert.stub(subject, :withblock).with(1){ } }).does_not_raise
|
653
668
|
end
|
654
669
|
|
655
670
|
should "allow calling methods with invalid arity" do
|
656
|
-
|
671
|
+
assert_that(-> { subject.noargs(1) }).does_not_raise
|
657
672
|
|
658
|
-
|
659
|
-
|
673
|
+
assert_that(-> { subject.withargs }).does_not_raise
|
674
|
+
assert_that(-> { subject.withargs(1, 2) }).does_not_raise
|
660
675
|
|
661
|
-
|
662
|
-
|
676
|
+
assert_that(-> { subject.minargs }).does_not_raise
|
677
|
+
assert_that(-> { subject.minargs(1) }).does_not_raise
|
663
678
|
|
664
|
-
|
679
|
+
assert_that(-> { subject.withblock(1) }).does_not_raise
|
665
680
|
end
|
666
681
|
end
|
667
682
|
|
668
683
|
class ParentAndChildClassTests < SystemTests
|
669
684
|
desc "for a parent method stubbed on both the parent and child"
|
670
685
|
setup do
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
Assert.stub(@parent_class, :new){ "parent" }
|
675
|
-
Assert.stub(@child_class, :new){ "child" }
|
686
|
+
Assert.stub(parent_class, :new){ "parent" }
|
687
|
+
Assert.stub(child_class, :new){ "child" }
|
676
688
|
end
|
677
689
|
|
690
|
+
let(:parent_class) { Class.new }
|
691
|
+
let(:child_class) { Class.new(parent_class) }
|
692
|
+
|
678
693
|
should "allow stubbing the methods individually" do
|
679
|
-
|
680
|
-
|
694
|
+
assert_that(parent_class.new).equals("parent")
|
695
|
+
assert_that(child_class.new).equals("child")
|
681
696
|
end
|
682
697
|
end
|
683
698
|
|