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