assert 2.18.3 → 2.19.3
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 -5
- data/bin/assert +1 -0
- data/lib/assert.rb +20 -6
- data/lib/assert/actual_value.rb +26 -8
- data/lib/assert/assert_runner.rb +38 -17
- data/lib/assert/assertions.rb +145 -41
- data/lib/assert/cli.rb +19 -66
- data/lib/assert/clirb.rb +55 -0
- data/lib/assert/config.rb +9 -7
- data/lib/assert/config_helpers.rb +57 -22
- data/lib/assert/context.rb +33 -49
- data/lib/assert/context/let_dsl.rb +10 -4
- 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 +26 -25
- 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 +117 -61
- data/lib/assert/runner.rb +70 -51
- data/lib/assert/stub.rb +44 -3
- data/lib/assert/suite.rb +76 -38
- data/lib/assert/test.rb +43 -44
- 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 +272 -250
- data/test/system/test_tests.rb +89 -73
- data/test/unit/actual_value_tests.rb +103 -46
- data/test/unit/assert_tests.rb +49 -39
- data/test/unit/assertions/assert_block_tests.rb +14 -14
- data/test/unit/assertions/assert_changes_tests.rb +103 -0
- data/test/unit/assertions/assert_empty_tests.rb +18 -16
- data/test/unit/assertions/assert_equal_tests.rb +48 -32
- data/test/unit/assertions/assert_file_exists_tests.rb +19 -17
- data/test/unit/assertions/assert_includes_tests.rb +14 -14
- data/test/unit/assertions/assert_instance_of_tests.rb +18 -18
- data/test/unit/assertions/assert_is_a_tests.rb +128 -0
- data/test/unit/assertions/assert_match_tests.rb +14 -14
- data/test/unit/assertions/assert_nil_tests.rb +20 -16
- data/test/unit/assertions/assert_raises_tests.rb +36 -27
- data/test/unit/assertions/assert_respond_to_tests.rb +14 -14
- data/test/unit/assertions/assert_same_tests.rb +28 -32
- data/test/unit/assertions/assert_true_false_tests.rb +38 -32
- data/test/unit/assertions_tests.rb +25 -18
- data/test/unit/config_helpers_tests.rb +20 -9
- data/test/unit/config_tests.rb +16 -8
- data/test/unit/context/let_dsl_tests.rb +2 -0
- data/test/unit/context/setup_dsl_tests.rb +27 -15
- data/test/unit/context/subject_dsl_tests.rb +5 -4
- data/test/unit/context/suite_dsl_tests.rb +6 -5
- data/test/unit/context/test_dsl_tests.rb +43 -19
- data/test/unit/context_info_tests.rb +12 -3
- data/test/unit/context_tests.rb +166 -116
- data/test/unit/default_runner_tests.rb +2 -0
- data/test/unit/default_suite_tests.rb +17 -5
- data/test/unit/factory_tests.rb +5 -1
- data/test/unit/file_line_tests.rb +14 -12
- data/test/unit/macro_tests.rb +17 -10
- data/test/unit/result_tests.rb +72 -75
- data/test/unit/runner_tests.rb +38 -23
- data/test/unit/suite_tests.rb +48 -30
- data/test/unit/test_tests.rb +88 -102
- data/test/unit/utils_tests.rb +53 -36
- data/test/unit/view_helpers_tests.rb +25 -17
- data/test/unit/view_tests.rb +8 -5
- metadata +40 -9
- data/test/unit/assertions/assert_kind_of_tests.rb +0 -68
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,27 +10,25 @@ 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
|
-
Assert.stub(
|
15
|
-
Assert.stub(
|
16
|
+
Assert.stub(subject, :noargs){ "default" }
|
17
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
16
18
|
|
17
|
-
Assert.stub(
|
18
|
-
Assert.stub(
|
19
|
+
Assert.stub(subject, :withargs){ "default" }
|
20
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
19
21
|
|
20
|
-
Assert.stub(
|
21
|
-
Assert.stub(
|
22
|
+
Assert.stub(subject, :anyargs){ "default" }
|
23
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
22
24
|
|
23
|
-
Assert.stub(
|
24
|
-
Assert.stub(
|
25
|
-
Assert.stub(
|
25
|
+
Assert.stub(subject, :minargs){ "default" }
|
26
|
+
Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
|
27
|
+
Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
|
26
28
|
|
27
|
-
Assert.stub(
|
29
|
+
Assert.stub(subject, :withblock){ "default" }
|
28
30
|
end
|
29
31
|
|
30
|
-
let(:instance1) { TestClass.new }
|
31
|
-
|
32
32
|
should "allow stubbing a method that doesn't take args" do
|
33
33
|
assert_that(subject.noargs).equals("none")
|
34
34
|
end
|
@@ -56,53 +56,51 @@ class Assert::Stub
|
|
56
56
|
end
|
57
57
|
|
58
58
|
should "not allow stubbing methods with invalid arity" do
|
59
|
-
assert_that
|
59
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
60
60
|
|
61
|
-
assert_that
|
62
|
-
assert_that
|
61
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
62
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
63
63
|
|
64
|
-
assert_that
|
65
|
-
assert_that
|
64
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
65
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
66
66
|
|
67
|
-
assert_that
|
67
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
68
68
|
end
|
69
69
|
|
70
70
|
should "not allow calling methods with invalid arity" do
|
71
|
-
assert_that
|
71
|
+
assert_that{ subject.noargs(1) }.raises
|
72
72
|
|
73
|
-
assert_that
|
74
|
-
assert_that
|
73
|
+
assert_that{ subject.withargs }.raises
|
74
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
75
75
|
|
76
|
-
assert_that
|
77
|
-
assert_that
|
76
|
+
assert_that{ subject.minargs }.raises
|
77
|
+
assert_that{ subject.minargs(1) }.raises
|
78
78
|
|
79
|
-
assert_that
|
79
|
+
assert_that{ subject.withblock(1) }.raises
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
class ClassTests < SystemTests
|
84
84
|
desc "for singleton methods on a class"
|
85
|
-
subject
|
85
|
+
subject{ TestClass }
|
86
86
|
|
87
87
|
setup do
|
88
|
-
Assert.stub(
|
89
|
-
Assert.stub(
|
88
|
+
Assert.stub(subject, :noargs){ "default" }
|
89
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
90
90
|
|
91
|
-
Assert.stub(
|
92
|
-
Assert.stub(
|
91
|
+
Assert.stub(subject, :withargs){ "default" }
|
92
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
93
93
|
|
94
|
-
Assert.stub(
|
95
|
-
Assert.stub(
|
94
|
+
Assert.stub(subject, :anyargs){ "default" }
|
95
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
96
96
|
|
97
|
-
Assert.stub(
|
98
|
-
Assert.stub(
|
99
|
-
Assert.stub(
|
97
|
+
Assert.stub(subject, :minargs){ "default" }
|
98
|
+
Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
|
99
|
+
Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
|
100
100
|
|
101
|
-
Assert.stub(
|
101
|
+
Assert.stub(subject, :withblock){ "default" }
|
102
102
|
end
|
103
103
|
|
104
|
-
let(:class1) { TestClass }
|
105
|
-
|
106
104
|
should "allow stubbing a method that doesn't take args" do
|
107
105
|
assert_that(subject.noargs).equals("none")
|
108
106
|
end
|
@@ -131,53 +129,51 @@ class Assert::Stub
|
|
131
129
|
end
|
132
130
|
|
133
131
|
should "not allow stubbing methods with invalid arity" do
|
134
|
-
assert_that
|
132
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
135
133
|
|
136
|
-
assert_that
|
137
|
-
assert_that
|
134
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
135
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
138
136
|
|
139
|
-
assert_that
|
140
|
-
assert_that
|
137
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
138
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
141
139
|
|
142
|
-
assert_that
|
140
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
143
141
|
end
|
144
142
|
|
145
143
|
should "not allow calling methods with invalid arity" do
|
146
|
-
assert_that
|
144
|
+
assert_that{ subject.noargs(1) }.raises
|
147
145
|
|
148
|
-
assert_that
|
149
|
-
assert_that
|
146
|
+
assert_that{ subject.withargs }.raises
|
147
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
150
148
|
|
151
|
-
assert_that
|
152
|
-
assert_that
|
149
|
+
assert_that{ subject.minargs }.raises
|
150
|
+
assert_that{ subject.minargs(1) }.raises
|
153
151
|
|
154
|
-
assert_that
|
152
|
+
assert_that{ subject.withblock(1) }.raises
|
155
153
|
end
|
156
154
|
end
|
157
155
|
|
158
156
|
class ModuleTests < SystemTests
|
159
157
|
desc "for singleton methods on a module"
|
160
|
-
subject
|
158
|
+
subject{ TestModule }
|
161
159
|
|
162
160
|
setup do
|
163
|
-
Assert.stub(
|
164
|
-
Assert.stub(
|
161
|
+
Assert.stub(subject, :noargs){ "default" }
|
162
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
165
163
|
|
166
|
-
Assert.stub(
|
167
|
-
Assert.stub(
|
164
|
+
Assert.stub(subject, :withargs){ "default" }
|
165
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
168
166
|
|
169
|
-
Assert.stub(
|
170
|
-
Assert.stub(
|
167
|
+
Assert.stub(subject, :anyargs){ "default" }
|
168
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
171
169
|
|
172
|
-
Assert.stub(
|
173
|
-
Assert.stub(
|
174
|
-
Assert.stub(
|
170
|
+
Assert.stub(subject, :minargs){ "default" }
|
171
|
+
Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
|
172
|
+
Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
|
175
173
|
|
176
|
-
Assert.stub(
|
174
|
+
Assert.stub(subject, :withblock){ "default" }
|
177
175
|
end
|
178
176
|
|
179
|
-
let(:module1) { TestModule }
|
180
|
-
|
181
177
|
should "allow stubbing a method that doesn't take args" do
|
182
178
|
assert_that(subject.noargs).equals("none")
|
183
179
|
end
|
@@ -206,53 +202,51 @@ class Assert::Stub
|
|
206
202
|
end
|
207
203
|
|
208
204
|
should "not allow stubbing methods with invalid arity" do
|
209
|
-
assert_that
|
205
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
210
206
|
|
211
|
-
assert_that
|
212
|
-
assert_that
|
207
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
208
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
213
209
|
|
214
|
-
assert_that
|
215
|
-
assert_that
|
210
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
211
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
216
212
|
|
217
|
-
assert_that
|
213
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
218
214
|
end
|
219
215
|
|
220
216
|
should "not allow calling methods with invalid arity" do
|
221
|
-
assert_that
|
217
|
+
assert_that{ subject.noargs(1) }.raises
|
222
218
|
|
223
|
-
assert_that
|
224
|
-
assert_that
|
219
|
+
assert_that{ subject.withargs }.raises
|
220
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
225
221
|
|
226
|
-
assert_that
|
227
|
-
assert_that
|
222
|
+
assert_that{ subject.minargs }.raises
|
223
|
+
assert_that{ subject.minargs(1) }.raises
|
228
224
|
|
229
|
-
assert_that
|
225
|
+
assert_that{ subject.withblock(1) }.raises
|
230
226
|
end
|
231
227
|
end
|
232
228
|
|
233
229
|
class ExtendedTests < SystemTests
|
234
230
|
desc "for extended methods"
|
235
|
-
subject {
|
231
|
+
subject{ Class.new{ extend TestMixin } }
|
236
232
|
|
237
233
|
setup do
|
238
|
-
Assert.stub(
|
239
|
-
Assert.stub(
|
234
|
+
Assert.stub(subject, :noargs){ "default" }
|
235
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
240
236
|
|
241
|
-
Assert.stub(
|
242
|
-
Assert.stub(
|
237
|
+
Assert.stub(subject, :withargs){ "default" }
|
238
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
243
239
|
|
244
|
-
Assert.stub(
|
245
|
-
Assert.stub(
|
240
|
+
Assert.stub(subject, :anyargs){ "default" }
|
241
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
246
242
|
|
247
|
-
Assert.stub(
|
248
|
-
Assert.stub(
|
249
|
-
Assert.stub(
|
243
|
+
Assert.stub(subject, :minargs){ "default" }
|
244
|
+
Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
|
245
|
+
Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
|
250
246
|
|
251
|
-
Assert.stub(
|
247
|
+
Assert.stub(subject, :withblock){ "default" }
|
252
248
|
end
|
253
249
|
|
254
|
-
let(:class1) { Class.new{ extend TestMixin } }
|
255
|
-
|
256
250
|
should "allow stubbing a method that doesn't take args" do
|
257
251
|
assert_that(subject.noargs).equals("none")
|
258
252
|
end
|
@@ -281,53 +275,53 @@ class Assert::Stub
|
|
281
275
|
end
|
282
276
|
|
283
277
|
should "not allow stubbing methods with invalid arity" do
|
284
|
-
assert_that
|
278
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
285
279
|
|
286
|
-
assert_that
|
287
|
-
assert_that
|
280
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
281
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
288
282
|
|
289
|
-
assert_that
|
290
|
-
assert_that
|
283
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
284
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
291
285
|
|
292
|
-
assert_that
|
286
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
293
287
|
end
|
294
288
|
|
295
289
|
should "not allow calling methods with invalid arity" do
|
296
|
-
assert_that
|
290
|
+
assert_that{ subject.noargs(1) }.raises
|
297
291
|
|
298
|
-
assert_that
|
299
|
-
assert_that
|
292
|
+
assert_that{ subject.withargs }.raises
|
293
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
300
294
|
|
301
|
-
assert_that
|
302
|
-
assert_that
|
295
|
+
assert_that{ subject.minargs }.raises
|
296
|
+
assert_that{ subject.minargs(1) }.raises
|
303
297
|
|
304
|
-
assert_that
|
298
|
+
assert_that{ subject.withblock(1) }.raises
|
305
299
|
end
|
306
300
|
end
|
307
301
|
|
308
302
|
class IncludedTests < SystemTests
|
309
303
|
desc "for an included method"
|
310
|
-
subject
|
304
|
+
subject do
|
305
|
+
Class.new{ include TestMixin }.new
|
306
|
+
end
|
311
307
|
|
312
308
|
setup do
|
313
|
-
Assert.stub(
|
314
|
-
Assert.stub(
|
309
|
+
Assert.stub(subject, :noargs){ "default" }
|
310
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
315
311
|
|
316
|
-
Assert.stub(
|
317
|
-
Assert.stub(
|
312
|
+
Assert.stub(subject, :withargs){ "default" }
|
313
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
318
314
|
|
319
|
-
Assert.stub(
|
320
|
-
Assert.stub(
|
315
|
+
Assert.stub(subject, :anyargs){ "default" }
|
316
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
321
317
|
|
322
|
-
Assert.stub(
|
323
|
-
Assert.stub(
|
324
|
-
Assert.stub(
|
318
|
+
Assert.stub(subject, :minargs){ "default" }
|
319
|
+
Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
|
320
|
+
Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
|
325
321
|
|
326
|
-
Assert.stub(
|
322
|
+
Assert.stub(subject, :withblock){ "default" }
|
327
323
|
end
|
328
324
|
|
329
|
-
let(:instance1) { Class.new { include TestMixin }.new }
|
330
|
-
|
331
325
|
should "allow stubbing a method that doesn't take args" do
|
332
326
|
assert_that(subject.noargs).equals("none")
|
333
327
|
end
|
@@ -356,53 +350,51 @@ class Assert::Stub
|
|
356
350
|
end
|
357
351
|
|
358
352
|
should "not allow stubbing methods with invalid arity" do
|
359
|
-
assert_that
|
353
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
360
354
|
|
361
|
-
assert_that
|
362
|
-
assert_that
|
355
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
356
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
363
357
|
|
364
|
-
assert_that
|
365
|
-
assert_that
|
358
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
359
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
366
360
|
|
367
|
-
assert_that
|
361
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
368
362
|
end
|
369
363
|
|
370
364
|
should "not allow calling methods with invalid arity" do
|
371
|
-
assert_that
|
365
|
+
assert_that{ subject.noargs(1) }.raises
|
372
366
|
|
373
|
-
assert_that
|
374
|
-
assert_that
|
367
|
+
assert_that{ subject.withargs }.raises
|
368
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
375
369
|
|
376
|
-
assert_that
|
377
|
-
assert_that
|
370
|
+
assert_that{ subject.minargs }.raises
|
371
|
+
assert_that{ subject.minargs(1) }.raises
|
378
372
|
|
379
|
-
assert_that
|
373
|
+
assert_that{ subject.withblock(1) }.raises
|
380
374
|
end
|
381
375
|
end
|
382
376
|
|
383
377
|
class InheritedClassTests < SystemTests
|
384
378
|
desc "for an inherited class method"
|
385
|
-
subject
|
379
|
+
subject{ Class.new(TestClass) }
|
386
380
|
|
387
381
|
setup do
|
388
|
-
Assert.stub(
|
389
|
-
Assert.stub(
|
382
|
+
Assert.stub(subject, :noargs){ "default" }
|
383
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
390
384
|
|
391
|
-
Assert.stub(
|
392
|
-
Assert.stub(
|
385
|
+
Assert.stub(subject, :withargs){ "default" }
|
386
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
393
387
|
|
394
|
-
Assert.stub(
|
395
|
-
Assert.stub(
|
388
|
+
Assert.stub(subject, :anyargs){ "default" }
|
389
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
396
390
|
|
397
|
-
Assert.stub(
|
398
|
-
Assert.stub(
|
399
|
-
Assert.stub(
|
391
|
+
Assert.stub(subject, :minargs){ "default" }
|
392
|
+
Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
|
393
|
+
Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
|
400
394
|
|
401
|
-
Assert.stub(
|
395
|
+
Assert.stub(subject, :withblock){ "default" }
|
402
396
|
end
|
403
397
|
|
404
|
-
let(:class1) { Class.new(TestClass) }
|
405
|
-
|
406
398
|
should "allow stubbing a method that doesn't take args" do
|
407
399
|
assert_that(subject.noargs).equals("none")
|
408
400
|
end
|
@@ -431,53 +423,51 @@ class Assert::Stub
|
|
431
423
|
end
|
432
424
|
|
433
425
|
should "not allow stubbing methods with invalid arity" do
|
434
|
-
assert_that
|
426
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
435
427
|
|
436
|
-
assert_that
|
437
|
-
assert_that
|
428
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
429
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
438
430
|
|
439
|
-
assert_that
|
440
|
-
assert_that
|
431
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
432
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
441
433
|
|
442
|
-
assert_that
|
434
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
443
435
|
end
|
444
436
|
|
445
437
|
should "not allow calling methods with invalid arity" do
|
446
|
-
assert_that
|
438
|
+
assert_that{ subject.noargs(1) }.raises
|
447
439
|
|
448
|
-
assert_that
|
449
|
-
assert_that
|
440
|
+
assert_that{ subject.withargs }.raises
|
441
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
450
442
|
|
451
|
-
assert_that
|
452
|
-
assert_that
|
443
|
+
assert_that{ subject.minargs }.raises
|
444
|
+
assert_that{ subject.minargs(1) }.raises
|
453
445
|
|
454
|
-
assert_that
|
446
|
+
assert_that{ subject.withblock(1) }.raises
|
455
447
|
end
|
456
448
|
end
|
457
449
|
|
458
450
|
class InheritedInstanceTests < SystemTests
|
459
451
|
desc "for an inherited instance method"
|
460
|
-
subject
|
452
|
+
subject{ Class.new(TestClass).new }
|
461
453
|
|
462
454
|
setup do
|
463
|
-
Assert.stub(
|
464
|
-
Assert.stub(
|
455
|
+
Assert.stub(subject, :noargs){ "default" }
|
456
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
465
457
|
|
466
|
-
Assert.stub(
|
467
|
-
Assert.stub(
|
458
|
+
Assert.stub(subject, :withargs){ "default" }
|
459
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
468
460
|
|
469
|
-
Assert.stub(
|
470
|
-
Assert.stub(
|
461
|
+
Assert.stub(subject, :anyargs){ "default" }
|
462
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
471
463
|
|
472
|
-
Assert.stub(
|
473
|
-
Assert.stub(
|
474
|
-
Assert.stub(
|
464
|
+
Assert.stub(subject, :minargs){ "default" }
|
465
|
+
Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
|
466
|
+
Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
|
475
467
|
|
476
|
-
Assert.stub(
|
468
|
+
Assert.stub(subject, :withblock){ "default" }
|
477
469
|
end
|
478
470
|
|
479
|
-
let(:instance1) { Class.new(TestClass).new }
|
480
|
-
|
481
471
|
should "allow stubbing a method that doesn't take args" do
|
482
472
|
assert_that(subject.noargs).equals("none")
|
483
473
|
end
|
@@ -506,53 +496,51 @@ class Assert::Stub
|
|
506
496
|
end
|
507
497
|
|
508
498
|
should "not allow stubbing methods with invalid arity" do
|
509
|
-
assert_that
|
499
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.raises
|
510
500
|
|
511
|
-
assert_that
|
512
|
-
assert_that
|
501
|
+
assert_that{ Assert.stub(subject, :withargs).with{} }.raises
|
502
|
+
assert_that{ Assert.stub(subject, :withargs).with(1, 2){} }.raises
|
513
503
|
|
514
|
-
assert_that
|
515
|
-
assert_that
|
504
|
+
assert_that{ Assert.stub(subject, :minargs).with{} }.raises
|
505
|
+
assert_that{ Assert.stub(subject, :minargs).with(1){} }.raises
|
516
506
|
|
517
|
-
assert_that
|
507
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.raises
|
518
508
|
end
|
519
509
|
|
520
510
|
should "not allow calling methods with invalid arity" do
|
521
|
-
assert_that
|
511
|
+
assert_that{ subject.noargs(1) }.raises
|
522
512
|
|
523
|
-
assert_that
|
524
|
-
assert_that
|
513
|
+
assert_that{ subject.withargs }.raises
|
514
|
+
assert_that{ subject.withargs(1, 2) }.raises
|
525
515
|
|
526
|
-
assert_that
|
527
|
-
assert_that
|
516
|
+
assert_that{ subject.minargs }.raises
|
517
|
+
assert_that{ subject.minargs(1) }.raises
|
528
518
|
|
529
|
-
assert_that
|
519
|
+
assert_that{ subject.withblock(1) }.raises
|
530
520
|
end
|
531
521
|
end
|
532
522
|
|
533
523
|
class DelegateClassTests < SystemTests
|
534
524
|
desc "a class that delegates another object"
|
535
|
-
subject
|
525
|
+
subject{ DelegateClass }
|
536
526
|
|
537
527
|
setup do
|
538
|
-
Assert.stub(
|
539
|
-
Assert.stub(
|
528
|
+
Assert.stub(subject, :noargs){ "default" }
|
529
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
540
530
|
|
541
|
-
Assert.stub(
|
542
|
-
Assert.stub(
|
531
|
+
Assert.stub(subject, :withargs){ "default" }
|
532
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
543
533
|
|
544
|
-
Assert.stub(
|
545
|
-
Assert.stub(
|
534
|
+
Assert.stub(subject, :anyargs){ "default" }
|
535
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
546
536
|
|
547
|
-
Assert.stub(
|
548
|
-
Assert.stub(
|
549
|
-
Assert.stub(
|
537
|
+
Assert.stub(subject, :minargs){ "default" }
|
538
|
+
Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
|
539
|
+
Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
|
550
540
|
|
551
|
-
Assert.stub(
|
541
|
+
Assert.stub(subject, :withblock){ "default" }
|
552
542
|
end
|
553
543
|
|
554
|
-
let(:class1) { DelegateClass }
|
555
|
-
|
556
544
|
should "allow stubbing a method that doesn't take args" do
|
557
545
|
assert_that(subject.noargs).equals("none")
|
558
546
|
end
|
@@ -581,53 +569,51 @@ class Assert::Stub
|
|
581
569
|
end
|
582
570
|
|
583
571
|
should "allow stubbing methods with invalid arity" do
|
584
|
-
assert_that
|
572
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.does_not_raise
|
585
573
|
|
586
|
-
assert_that
|
587
|
-
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
|
588
576
|
|
589
|
-
assert_that
|
590
|
-
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
|
591
579
|
|
592
|
-
assert_that
|
580
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.does_not_raise
|
593
581
|
end
|
594
582
|
|
595
583
|
should "allow calling methods with invalid arity" do
|
596
|
-
assert_that
|
584
|
+
assert_that{ subject.noargs(1) }.does_not_raise
|
597
585
|
|
598
|
-
assert_that
|
599
|
-
assert_that
|
586
|
+
assert_that{ subject.withargs }.does_not_raise
|
587
|
+
assert_that{ subject.withargs(1, 2) }.does_not_raise
|
600
588
|
|
601
|
-
assert_that
|
602
|
-
assert_that
|
589
|
+
assert_that{ subject.minargs }.does_not_raise
|
590
|
+
assert_that{ subject.minargs(1) }.does_not_raise
|
603
591
|
|
604
|
-
assert_that
|
592
|
+
assert_that{ subject.withblock(1) }.does_not_raise
|
605
593
|
end
|
606
594
|
end
|
607
595
|
|
608
596
|
class DelegateInstanceTests < SystemTests
|
609
597
|
desc "an instance that delegates another object"
|
610
|
-
subject
|
598
|
+
subject{ DelegateClass.new }
|
611
599
|
|
612
600
|
setup do
|
613
|
-
Assert.stub(
|
614
|
-
Assert.stub(
|
601
|
+
Assert.stub(subject, :noargs){ "default" }
|
602
|
+
Assert.stub(subject, :noargs).with{ "none" }
|
615
603
|
|
616
|
-
Assert.stub(
|
617
|
-
Assert.stub(
|
604
|
+
Assert.stub(subject, :withargs){ "default" }
|
605
|
+
Assert.stub(subject, :withargs).with(1){ "one" }
|
618
606
|
|
619
|
-
Assert.stub(
|
620
|
-
Assert.stub(
|
607
|
+
Assert.stub(subject, :anyargs){ "default" }
|
608
|
+
Assert.stub(subject, :anyargs).with(1, 2){ "one-two" }
|
621
609
|
|
622
|
-
Assert.stub(
|
623
|
-
Assert.stub(
|
624
|
-
Assert.stub(
|
610
|
+
Assert.stub(subject, :minargs){ "default" }
|
611
|
+
Assert.stub(subject, :minargs).with(1, 2){ "one-two" }
|
612
|
+
Assert.stub(subject, :minargs).with(1, 2, 3){ "one-two-three" }
|
625
613
|
|
626
|
-
Assert.stub(
|
614
|
+
Assert.stub(subject, :withblock){ "default" }
|
627
615
|
end
|
628
616
|
|
629
|
-
let(:instance1) { DelegateClass.new }
|
630
|
-
|
631
617
|
should "allow stubbing a method that doesn't take args" do
|
632
618
|
assert_that(subject.noargs).equals("none")
|
633
619
|
end
|
@@ -656,27 +642,27 @@ class Assert::Stub
|
|
656
642
|
end
|
657
643
|
|
658
644
|
should "allow stubbing methods with invalid arity" do
|
659
|
-
assert_that
|
645
|
+
assert_that{ Assert.stub(subject, :noargs).with(1){} }.does_not_raise
|
660
646
|
|
661
|
-
assert_that
|
662
|
-
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
|
663
649
|
|
664
|
-
assert_that
|
665
|
-
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
|
666
652
|
|
667
|
-
assert_that
|
653
|
+
assert_that{ Assert.stub(subject, :withblock).with(1){} }.does_not_raise
|
668
654
|
end
|
669
655
|
|
670
656
|
should "allow calling methods with invalid arity" do
|
671
|
-
assert_that
|
657
|
+
assert_that{ subject.noargs(1) }.does_not_raise
|
672
658
|
|
673
|
-
assert_that
|
674
|
-
assert_that
|
659
|
+
assert_that{ subject.withargs }.does_not_raise
|
660
|
+
assert_that{ subject.withargs(1, 2) }.does_not_raise
|
675
661
|
|
676
|
-
assert_that
|
677
|
-
assert_that
|
662
|
+
assert_that{ subject.minargs }.does_not_raise
|
663
|
+
assert_that{ subject.minargs(1) }.does_not_raise
|
678
664
|
|
679
|
-
assert_that
|
665
|
+
assert_that{ subject.withblock(1) }.does_not_raise
|
680
666
|
end
|
681
667
|
end
|
682
668
|
|
@@ -687,8 +673,8 @@ class Assert::Stub
|
|
687
673
|
Assert.stub(child_class, :new){ "child" }
|
688
674
|
end
|
689
675
|
|
690
|
-
let(:parent_class)
|
691
|
-
let(:child_class)
|
676
|
+
let(:parent_class){ Class.new }
|
677
|
+
let(:child_class){ Class.new(parent_class) }
|
692
678
|
|
693
679
|
should "allow stubbing the methods individually" do
|
694
680
|
assert_that(parent_class.new).equals("parent")
|
@@ -697,37 +683,73 @@ class Assert::Stub
|
|
697
683
|
end
|
698
684
|
|
699
685
|
class TestClass
|
700
|
-
def self.noargs
|
701
|
-
|
702
|
-
|
703
|
-
def self.
|
704
|
-
|
705
|
-
|
706
|
-
def
|
707
|
-
|
708
|
-
|
709
|
-
def minargs(a, b, *args)
|
710
|
-
|
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
|
711
715
|
end
|
712
716
|
|
713
717
|
module TestModule
|
714
|
-
def self.noargs
|
715
|
-
|
716
|
-
|
717
|
-
def self.
|
718
|
-
|
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
|
719
732
|
end
|
720
733
|
|
721
734
|
module TestMixin
|
722
|
-
def noargs
|
723
|
-
|
724
|
-
|
725
|
-
def
|
726
|
-
|
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
|
727
749
|
end
|
728
750
|
|
729
751
|
class DelegateClass
|
730
|
-
def self.
|
752
|
+
def self.respond_to_missing?(*args)
|
731
753
|
TestClass.respond_to?(*args) || super
|
732
754
|
end
|
733
755
|
|
@@ -739,7 +761,7 @@ class Assert::Stub
|
|
739
761
|
@delegate = TestClass.new
|
740
762
|
end
|
741
763
|
|
742
|
-
def
|
764
|
+
def respond_to_missing?(*args)
|
743
765
|
@delegate.respond_to?(*args) || super
|
744
766
|
end
|
745
767
|
|