assert 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -1
- data/README.rdoc +6 -6
- data/Rakefile +2 -3
- data/assert.gemspec +1 -0
- data/lib/assert/assertions.rb +30 -30
- data/lib/assert/context.rb +71 -66
- data/lib/assert/macro.rb +14 -0
- data/lib/assert/macros/methods.rb +52 -0
- data/lib/assert/rake_tasks.rb +31 -13
- data/lib/assert/result.rb +12 -4
- data/lib/assert/result_set.rb +2 -2
- data/lib/assert/runner.rb +2 -6
- data/lib/assert/setup/autorun.rb +0 -1
- data/lib/assert/suite.rb +19 -15
- data/lib/assert/test.rb +6 -17
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view/base.rb +1 -1
- data/lib/assert/view/terminal.rb +8 -30
- data/test/assertions/assert_block_test.rb +1 -1
- data/test/assertions/assert_empty_test.rb +43 -0
- data/test/assertions/assert_equal_test.rb +43 -0
- data/test/assertions/assert_includes_test.rb +44 -0
- data/test/assertions/assert_instance_of_test.rb +4 -4
- data/test/assertions/assert_kind_of_test.rb +3 -3
- data/test/assertions/assert_match_test.rb +43 -0
- data/test/assertions/assert_nil_test.rb +43 -0
- data/test/assertions/assert_not_block_test.rb +1 -1
- data/test/assertions/assert_not_empty_test.rb +43 -0
- data/test/assertions/assert_not_equal_test.rb +43 -0
- data/test/assertions/assert_not_included_test.rb +44 -0
- data/test/assertions/assert_not_instance_of_test.rb +4 -4
- data/test/assertions/assert_not_kind_of_test.rb +2 -2
- data/test/assertions/assert_not_match_test.rb +43 -0
- data/test/assertions/assert_not_nil_test.rb +43 -0
- data/test/assertions/assert_not_respond_to_test.rb +6 -6
- data/test/assertions/assert_not_same_test.rb +45 -0
- data/test/assertions/assert_respond_to_test.rb +6 -6
- data/test/assertions/assert_same_test.rb +45 -0
- data/test/assertions_test.rb +21 -298
- data/test/context/class_methods_test.rb +81 -112
- data/test/context_test.rb +35 -40
- data/test/helper.rb +5 -2
- data/test/irb.rb +2 -5
- data/test/macro_test.rb +99 -0
- data/test/options_test.rb +2 -2
- data/test/result_set_test.rb +47 -54
- data/test/result_test.rb +4 -17
- data/test/runner_test.rb +2 -10
- data/test/suite_test.rb +85 -13
- data/test/test/running_test.rb +19 -28
- data/test/test_test.rb +130 -128
- data/test/view_test.rb +3 -17
- metadata +50 -7
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'assert'
|
2
|
+
|
3
|
+
class Assert::Assertions::AssertNotSameTest < Assert::Context
|
4
|
+
desc "the assert_not_same helper run in a test"
|
5
|
+
setup do
|
6
|
+
klass = Class.new
|
7
|
+
object = klass.new
|
8
|
+
fail_desc = @fail_desc = "assert not same fail desc"
|
9
|
+
fail_args = @fail_args = [ object, object, fail_desc ]
|
10
|
+
@test = Factory.test do
|
11
|
+
assert_not_same(*fail_args) # fail
|
12
|
+
assert_not_same(object, klass.new) # pass
|
13
|
+
end
|
14
|
+
@test.run
|
15
|
+
end
|
16
|
+
subject{ @test }
|
17
|
+
|
18
|
+
should "have 2 total results" do
|
19
|
+
assert_equal 2, subject.result_count
|
20
|
+
end
|
21
|
+
should "have 1 pass result" do
|
22
|
+
assert_equal 1, subject.result_count(:pass)
|
23
|
+
end
|
24
|
+
should "have 1 fail result" do
|
25
|
+
assert_equal 1, subject.result_count(:fail)
|
26
|
+
end
|
27
|
+
|
28
|
+
class FailMessageTest < AssertNotSameTest
|
29
|
+
desc "with a failed result"
|
30
|
+
setup do
|
31
|
+
@expected = [
|
32
|
+
@fail_args[2],
|
33
|
+
"#{@fail_args[0].inspect} (#{@fail_args[0].object_id}) not expected to be the same as #{@fail_args[1].inspect} (#{@fail_args[1].object_id}).",
|
34
|
+
].join("\n")
|
35
|
+
@fail_message = @test.fail_results.first.message
|
36
|
+
end
|
37
|
+
subject{ @fail_message }
|
38
|
+
|
39
|
+
should "have a fail message with an explanation of what failed and my fail description" do
|
40
|
+
assert_equal @expected, subject
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -4,9 +4,9 @@ class Assert::Assertions::AssertRespondToTest < Assert::Context
|
|
4
4
|
desc "the assert_respond_to helper run in a test"
|
5
5
|
setup do
|
6
6
|
fail_desc = @fail_desc = "assert respond to fail desc"
|
7
|
-
fail_args = @fail_args = [ "1",
|
7
|
+
fail_args = @fail_args = [ :abs, "1", fail_desc ]
|
8
8
|
@test = Factory.test do
|
9
|
-
assert_respond_to(
|
9
|
+
assert_respond_to(:abs, 1) # pass
|
10
10
|
assert_respond_to(*fail_args) # fail
|
11
11
|
end
|
12
12
|
@test.run
|
@@ -27,9 +27,9 @@ class Assert::Assertions::AssertRespondToTest < Assert::Context
|
|
27
27
|
desc "with a failed result"
|
28
28
|
setup do
|
29
29
|
@expected = [
|
30
|
-
|
31
|
-
"
|
32
|
-
].join("
|
30
|
+
@fail_args[2],
|
31
|
+
"Expected #{@fail_args[1].inspect} (#{@fail_args[1].class}) to respond to ##{@fail_args[0]}."
|
32
|
+
].join("\n")
|
33
33
|
@fail_message = @test.fail_results.first.message
|
34
34
|
end
|
35
35
|
subject{ @fail_message }
|
@@ -40,4 +40,4 @@ class Assert::Assertions::AssertRespondToTest < Assert::Context
|
|
40
40
|
|
41
41
|
end
|
42
42
|
|
43
|
-
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'assert'
|
2
|
+
|
3
|
+
class Assert::Assertions::AssertSameTest < Assert::Context
|
4
|
+
desc "the assert_same helper run in a test"
|
5
|
+
setup do
|
6
|
+
klass = Class.new
|
7
|
+
object = klass.new
|
8
|
+
fail_desc = @fail_desc = "assert same fail desc"
|
9
|
+
fail_args = @fail_args = [ object, klass.new, fail_desc ]
|
10
|
+
@test = Factory.test do
|
11
|
+
assert_same(object, object) # pass
|
12
|
+
assert_same(*fail_args) # fail
|
13
|
+
end
|
14
|
+
@test.run
|
15
|
+
end
|
16
|
+
subject{ @test }
|
17
|
+
|
18
|
+
should "have 2 total results" do
|
19
|
+
assert_equal 2, subject.result_count
|
20
|
+
end
|
21
|
+
should "have 1 pass result" do
|
22
|
+
assert_equal 1, subject.result_count(:pass)
|
23
|
+
end
|
24
|
+
should "have 1 fail result" do
|
25
|
+
assert_equal 1, subject.result_count(:fail)
|
26
|
+
end
|
27
|
+
|
28
|
+
class FailMessageTest < AssertSameTest
|
29
|
+
desc "with a failed result"
|
30
|
+
setup do
|
31
|
+
@expected = [
|
32
|
+
@fail_args[2],
|
33
|
+
"Expected #{@fail_args[0].inspect} (#{@fail_args[0].object_id}) to be the same as #{@fail_args[1].inspect} (#{@fail_args[1].object_id}).",
|
34
|
+
].join("\n")
|
35
|
+
@fail_message = @test.fail_results.first.message
|
36
|
+
end
|
37
|
+
subject{ @fail_message }
|
38
|
+
|
39
|
+
should "have a fail message with an explanation of what failed and my fail description" do
|
40
|
+
assert_equal @expected, subject
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/test/assertions_test.rb
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
require 'assert'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
desc "An assert context"
|
6
|
-
setup do
|
7
|
-
@context_class = Factory.context_class
|
8
|
-
@context = @context_class.new
|
9
|
-
end
|
10
|
-
subject{ @context }
|
3
|
+
module Assert::Assertions
|
4
|
+
class BasicTest < Assert::Context
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
:assert_instance_of, :assert_not_instance_of, :refute_instance_of,
|
17
|
-
:assert_respond_to, :assert_not_respond_to, :refute_respond_to,
|
18
|
-
:assert_same, :assert_not_same, :refute_same,
|
19
|
-
:assert_equal, :assert_not_equal, :refute_equal,
|
20
|
-
:assert_match, :assert_not_match, :assert_no_match, :refute_match
|
21
|
-
]
|
22
|
-
INSTANCE_METHODS.each do |method|
|
23
|
-
should "respond to the instance method ##{method}" do
|
24
|
-
assert_respond_to subject, method
|
6
|
+
desc "An assert context"
|
7
|
+
setup do
|
8
|
+
@context_class = Factory.context_class
|
9
|
+
@context = @context_class.new
|
25
10
|
end
|
11
|
+
subject{ @context }
|
12
|
+
|
13
|
+
should have_instance_methods :assert_block, :assert_not_block, :refute_block
|
14
|
+
should have_instance_methods :assert_raises, :assert_raise, :assert_nothing_raised, :assert_not_raises, :assert_not_raise
|
15
|
+
should have_instance_methods :assert_kind_of, :assert_not_kind_of, :refute_kind_of
|
16
|
+
should have_instance_methods :assert_instance_of, :assert_not_instance_of, :refute_instance_of
|
17
|
+
should have_instance_methods :assert_respond_to, :assert_not_respond_to, :refute_respond_to
|
18
|
+
should have_instance_methods :assert_same, :assert_not_same, :refute_same
|
19
|
+
should have_instance_methods :assert_equal, :assert_not_equal, :refute_equal
|
20
|
+
should have_instance_methods :assert_match, :assert_not_match, :assert_no_match, :refute_match
|
21
|
+
should have_instance_methods :assert_empty, :assert_not_empty, :refute_empty
|
22
|
+
should have_instance_methods :assert_includes, :assert_included
|
23
|
+
should have_instance_methods :assert_not_includes, :assert_not_included, :refute_includes, :refute_included
|
24
|
+
should have_instance_methods :assert_nil, :assert_not_nil, :refute_nil
|
26
25
|
end
|
27
26
|
|
28
27
|
class IgnoredTest < BasicTest
|
@@ -48,6 +47,7 @@ class Assert::Assertions::BasicTest < Assert::Context
|
|
48
47
|
end
|
49
48
|
assert_equal(Assert::Assertions::IGNORED_ASSERTION_HELPERS.size, subject.size)
|
50
49
|
end
|
50
|
+
|
51
51
|
should "have a custom ignore message for each helper in the constant" do
|
52
52
|
assert_equal(@expected_messages, subject.collect(&:message))
|
53
53
|
end
|
@@ -55,280 +55,3 @@ class Assert::Assertions::BasicTest < Assert::Context
|
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
58
|
-
|
59
|
-
=begin
|
60
|
-
module Assert::Assertions
|
61
|
-
|
62
|
-
class AssertSameTest < BasicTest
|
63
|
-
|
64
|
-
setup do
|
65
|
-
klass = Class.new
|
66
|
-
object = klass.new
|
67
|
-
@test = Assert::Test.new("assert same test", lambda do
|
68
|
-
assert_same(object, object) # pass
|
69
|
-
assert_same(object, klass.new) # fail
|
70
|
-
end, @context_klass)
|
71
|
-
@test.run
|
72
|
-
end
|
73
|
-
subject{ @test }
|
74
|
-
|
75
|
-
should "have 2 total results" do
|
76
|
-
assert_equal 2, subject.result_count
|
77
|
-
end
|
78
|
-
|
79
|
-
should "have 1 pass result" do
|
80
|
-
assert_equal 1, subject.result_count(:pass)
|
81
|
-
end
|
82
|
-
|
83
|
-
should "have 1 fail result" do
|
84
|
-
assert_equal 1, subject.result_count(:fail)
|
85
|
-
end
|
86
|
-
|
87
|
-
class MessagesTest < AssertSameTest
|
88
|
-
|
89
|
-
setup do
|
90
|
-
klass = Class.new
|
91
|
-
args = [ klass.new, klass.new, "assert same shoudn't fail!" ]
|
92
|
-
@test = Assert::Test.new("assert same message test", lambda do
|
93
|
-
assert_same(*args)
|
94
|
-
end, @context_klass)
|
95
|
-
@expected_message = "Expected #{args[0].inspect} (#{args[0].object_id}) to be the same as #{args[1]} (#{args[1].object_id}).\n#{args[2]}"
|
96
|
-
@test.run
|
97
|
-
@message = @test.fail_results.first.message
|
98
|
-
end
|
99
|
-
subject{ @message }
|
100
|
-
|
101
|
-
should "have the correct failure message" do
|
102
|
-
assert_equal @expected_message, subject
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
class AssertNotSameTest < BasicTest
|
110
|
-
|
111
|
-
setup do
|
112
|
-
klass = Class.new
|
113
|
-
object = klass.new
|
114
|
-
@test = Assert::Test.new("assert not same test", lambda do
|
115
|
-
assert_not_same(object, object) # fail
|
116
|
-
assert_not_same(object, klass.new) # pass
|
117
|
-
end, @context_klass)
|
118
|
-
@test.run
|
119
|
-
end
|
120
|
-
subject{ @test }
|
121
|
-
|
122
|
-
should "have 2 total results" do
|
123
|
-
assert_equal 2, subject.result_count
|
124
|
-
end
|
125
|
-
|
126
|
-
should "have 1 pass result" do
|
127
|
-
assert_equal 1, subject.result_count(:pass)
|
128
|
-
end
|
129
|
-
|
130
|
-
should "have 1 fail result" do
|
131
|
-
assert_equal 1, subject.result_count(:fail)
|
132
|
-
end
|
133
|
-
|
134
|
-
class MessagesTest < AssertNotSameTest
|
135
|
-
|
136
|
-
setup do
|
137
|
-
klass = Class.new
|
138
|
-
object = klass.new
|
139
|
-
args = [ object, object, "assert not same shoudn't fail!" ]
|
140
|
-
@test = Assert::Test.new("assert not same message test", lambda do
|
141
|
-
assert_not_same(*args)
|
142
|
-
end, @context_klass)
|
143
|
-
@expected_message = "#{args[0].inspect} (#{args[0].object_id}) not expected to be the same as #{args[1]} (#{args[1].object_id}).\n#{args[2]}"
|
144
|
-
@test.run
|
145
|
-
@message = @test.fail_results.first.message
|
146
|
-
end
|
147
|
-
subject{ @message }
|
148
|
-
|
149
|
-
should "have the correct failure message" do
|
150
|
-
assert_equal @expected_message, subject
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
class AssertEqualTest < BasicTest
|
158
|
-
|
159
|
-
setup do
|
160
|
-
@test = Assert::Test.new("assert equal test", lambda do
|
161
|
-
assert_equal(1, 1) # pass
|
162
|
-
assert_equal(1, 2) # fail
|
163
|
-
end, @context_klass)
|
164
|
-
@test.run
|
165
|
-
end
|
166
|
-
subject{ @test }
|
167
|
-
|
168
|
-
should "have 2 total results" do
|
169
|
-
assert_equal 2, subject.result_count
|
170
|
-
end
|
171
|
-
|
172
|
-
should "have 1 pass result" do
|
173
|
-
assert_equal 1, subject.result_count(:pass)
|
174
|
-
end
|
175
|
-
|
176
|
-
should "have 1 fail result" do
|
177
|
-
assert_equal 1, subject.result_count(:fail)
|
178
|
-
end
|
179
|
-
|
180
|
-
class MessagesTest < AssertEqualTest
|
181
|
-
|
182
|
-
setup do
|
183
|
-
args = [ 1, 2, "assert equal shoudn't fail!" ]
|
184
|
-
@test = Assert::Test.new("assert equal message test", lambda do
|
185
|
-
assert_equal(*args)
|
186
|
-
end, @context_klass)
|
187
|
-
@expected_message = "Expected #{args[0].inspect}, not #{args[1].inspect}.\n#{args[2]}"
|
188
|
-
@test.run
|
189
|
-
@message = @test.fail_results.first.message
|
190
|
-
end
|
191
|
-
subject{ @message }
|
192
|
-
|
193
|
-
should "have the correct failure message" do
|
194
|
-
assert_equal @expected_message, subject
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
198
|
-
|
199
|
-
end
|
200
|
-
|
201
|
-
class AssertNotEqualTest < BasicTest
|
202
|
-
|
203
|
-
setup do
|
204
|
-
@test = Assert::Test.new("assert not equal test", lambda do
|
205
|
-
assert_not_equal(1, 1) # fail
|
206
|
-
assert_not_equal(1, 2) # pass
|
207
|
-
end, @context_klass)
|
208
|
-
@test.run
|
209
|
-
end
|
210
|
-
subject{ @test }
|
211
|
-
|
212
|
-
should "have 2 total results" do
|
213
|
-
assert_equal 2, subject.result_count
|
214
|
-
end
|
215
|
-
|
216
|
-
should "have 1 pass result" do
|
217
|
-
assert_equal 1, subject.result_count(:pass)
|
218
|
-
end
|
219
|
-
|
220
|
-
should "have 1 fail result" do
|
221
|
-
assert_equal 1, subject.result_count(:fail)
|
222
|
-
end
|
223
|
-
|
224
|
-
class MessagesTest < AssertNotEqualTest
|
225
|
-
|
226
|
-
setup do
|
227
|
-
args = [ 1, 1, "assert not equal shoudn't fail!" ]
|
228
|
-
@test = Assert::Test.new("assert not equal message test", lambda do
|
229
|
-
assert_not_equal(*args)
|
230
|
-
end, @context_klass)
|
231
|
-
@expected_message = "#{args[0].inspect} not expected to be equal to #{args[1].inspect}.\n#{args[2]}"
|
232
|
-
@test.run
|
233
|
-
@message = @test.fail_results.first.message
|
234
|
-
end
|
235
|
-
subject{ @message }
|
236
|
-
|
237
|
-
should "have the correct failure message" do
|
238
|
-
assert_equal @expected_message, subject
|
239
|
-
end
|
240
|
-
|
241
|
-
end
|
242
|
-
|
243
|
-
end
|
244
|
-
|
245
|
-
class AssertMatchTest < BasicTest
|
246
|
-
|
247
|
-
setup do
|
248
|
-
@test = Assert::Test.new("assert match test", lambda do
|
249
|
-
assert_match("a string", /a/) # pass
|
250
|
-
assert_match("a string", "not") # fail
|
251
|
-
end, @context_klass)
|
252
|
-
@test.run
|
253
|
-
end
|
254
|
-
subject{ @test }
|
255
|
-
|
256
|
-
should "have 2 total results" do
|
257
|
-
assert_equal 2, subject.result_count
|
258
|
-
end
|
259
|
-
|
260
|
-
should "have 1 pass result" do
|
261
|
-
assert_equal 1, subject.result_count(:pass)
|
262
|
-
end
|
263
|
-
|
264
|
-
should "have 1 fail result" do
|
265
|
-
assert_equal 1, subject.result_count(:fail)
|
266
|
-
end
|
267
|
-
|
268
|
-
class MessagesTest < AssertMatchTest
|
269
|
-
|
270
|
-
setup do
|
271
|
-
args = [ "a string", "not", "assert match shoudn't fail!" ]
|
272
|
-
@test = Assert::Test.new("assert match message test", lambda do
|
273
|
-
assert_match(*args)
|
274
|
-
end, @context_klass)
|
275
|
-
@expected_message = "Expected #{args[0].inspect} to match #{args[1].inspect}.\n#{args[2]}"
|
276
|
-
@test.run
|
277
|
-
@message = @test.fail_results.first.message
|
278
|
-
end
|
279
|
-
subject{ @message }
|
280
|
-
|
281
|
-
should "have the correct failure message" do
|
282
|
-
assert_equal @expected_message, subject
|
283
|
-
end
|
284
|
-
|
285
|
-
end
|
286
|
-
|
287
|
-
end
|
288
|
-
|
289
|
-
class AssertNotMatchTest < BasicTest
|
290
|
-
|
291
|
-
setup do
|
292
|
-
@test = Assert::Test.new("assert not match test", lambda do
|
293
|
-
assert_not_match("a string", /a/) # fail
|
294
|
-
assert_not_match("a string", "not") # pass
|
295
|
-
end, @context_klass)
|
296
|
-
@test.run
|
297
|
-
end
|
298
|
-
subject{ @test }
|
299
|
-
|
300
|
-
should "have 2 total results" do
|
301
|
-
assert_equal 2, subject.result_count
|
302
|
-
end
|
303
|
-
|
304
|
-
should "have 1 pass result" do
|
305
|
-
assert_equal 1, subject.result_count(:pass)
|
306
|
-
end
|
307
|
-
|
308
|
-
should "have 1 fail result" do
|
309
|
-
assert_equal 1, subject.result_count(:fail)
|
310
|
-
end
|
311
|
-
|
312
|
-
class MessagesTest < AssertNotMatchTest
|
313
|
-
|
314
|
-
setup do
|
315
|
-
args = [ "a string", /a/, "assert not match shoudn't fail!" ]
|
316
|
-
@test = Assert::Test.new("assert not match message test", lambda do
|
317
|
-
assert_not_match(*args)
|
318
|
-
end, @context_klass)
|
319
|
-
@expected_message = "#{args[0].inspect} not expected to match #{args[1].inspect}.\n#{args[2]}"
|
320
|
-
@test.run
|
321
|
-
@message = @test.fail_results.first.message
|
322
|
-
end
|
323
|
-
subject{ @message }
|
324
|
-
|
325
|
-
should "have the correct failure message" do
|
326
|
-
assert_equal @expected_message, subject
|
327
|
-
end
|
328
|
-
|
329
|
-
end
|
330
|
-
|
331
|
-
end
|
332
|
-
|
333
|
-
end
|
334
|
-
=end
|