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
data/test/test/running_test.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
require 'assert'
|
2
2
|
|
3
|
-
class Assert::Test
|
4
|
-
desc "Assert tests that are run"
|
3
|
+
class Assert::Test
|
5
4
|
|
6
|
-
class
|
5
|
+
class RunningTest < Assert::Context
|
6
|
+
desc "Assert tests that are run"
|
7
|
+
subject{ @test }
|
8
|
+
end
|
9
|
+
|
10
|
+
class NothingTest < RunningTest
|
7
11
|
desc "and does nothing"
|
8
12
|
setup do
|
9
13
|
@test = Factory.test
|
10
14
|
@test.run
|
11
15
|
end
|
12
|
-
subject{ @test }
|
13
16
|
|
14
17
|
should "have 0 results" do
|
15
18
|
assert_equal 0, subject.result_count
|
@@ -19,13 +22,12 @@ class Assert::Test::RunningTest < Assert::Context
|
|
19
22
|
|
20
23
|
|
21
24
|
|
22
|
-
class PassTest <
|
25
|
+
class PassTest < RunningTest
|
23
26
|
desc "and passes a single assertion"
|
24
27
|
setup do
|
25
28
|
@test = Factory.test{ assert(1 == 1) }
|
26
29
|
@test.run
|
27
30
|
end
|
28
|
-
subject{ @test }
|
29
31
|
|
30
32
|
should "have 1 result" do
|
31
33
|
assert_equal 1, subject.result_count
|
@@ -38,13 +40,12 @@ class Assert::Test::RunningTest < Assert::Context
|
|
38
40
|
|
39
41
|
|
40
42
|
|
41
|
-
class FailTest <
|
43
|
+
class FailTest < RunningTest
|
42
44
|
desc "and fails a single assertion"
|
43
45
|
setup do
|
44
46
|
@test = Factory.test{ assert(1 == 0) }
|
45
47
|
@test.run
|
46
48
|
end
|
47
|
-
subject{ @test }
|
48
49
|
|
49
50
|
should "have 1 result" do
|
50
51
|
assert_equal 1, subject.result_count
|
@@ -57,13 +58,12 @@ class Assert::Test::RunningTest < Assert::Context
|
|
57
58
|
|
58
59
|
|
59
60
|
|
60
|
-
class SkipTest <
|
61
|
+
class SkipTest < RunningTest
|
61
62
|
desc "and skips"
|
62
63
|
setup do
|
63
64
|
@test = Factory.test{ skip }
|
64
65
|
@test.run
|
65
66
|
end
|
66
|
-
subject{ @test }
|
67
67
|
|
68
68
|
should "have 1 result" do
|
69
69
|
assert_equal 1, subject.result_count
|
@@ -76,13 +76,12 @@ class Assert::Test::RunningTest < Assert::Context
|
|
76
76
|
|
77
77
|
|
78
78
|
|
79
|
-
class ErrorTest <
|
79
|
+
class ErrorTest < RunningTest
|
80
80
|
desc "and errors"
|
81
81
|
setup do
|
82
82
|
@test = Factory.test{ raise("WHAT") }
|
83
83
|
@test.run
|
84
84
|
end
|
85
|
-
subject{ @test }
|
86
85
|
|
87
86
|
should "have 1 result" do
|
88
87
|
assert_equal 1, subject.result_count
|
@@ -95,7 +94,7 @@ class Assert::Test::RunningTest < Assert::Context
|
|
95
94
|
|
96
95
|
|
97
96
|
|
98
|
-
class MixedTest <
|
97
|
+
class MixedTest < RunningTest
|
99
98
|
desc "and has 1 pass and 1 fail assertion"
|
100
99
|
setup do
|
101
100
|
@test = Factory.test do
|
@@ -104,7 +103,6 @@ class Assert::Test::RunningTest < Assert::Context
|
|
104
103
|
end
|
105
104
|
@test.run
|
106
105
|
end
|
107
|
-
subject{ @test }
|
108
106
|
|
109
107
|
should "have 2 total results" do
|
110
108
|
assert_equal 2, subject.result_count
|
@@ -120,7 +118,7 @@ class Assert::Test::RunningTest < Assert::Context
|
|
120
118
|
|
121
119
|
|
122
120
|
|
123
|
-
class MixedSkipTest <
|
121
|
+
class MixedSkipTest < RunningTest
|
124
122
|
desc "and has 1 pass and 1 fail assertion with a skip call in between"
|
125
123
|
setup do
|
126
124
|
@test = Factory.test do
|
@@ -130,7 +128,6 @@ class Assert::Test::RunningTest < Assert::Context
|
|
130
128
|
end
|
131
129
|
@test.run
|
132
130
|
end
|
133
|
-
subject{ @test }
|
134
131
|
|
135
132
|
should "have 2 total results" do
|
136
133
|
assert_equal 2, subject.result_count
|
@@ -152,7 +149,7 @@ class Assert::Test::RunningTest < Assert::Context
|
|
152
149
|
|
153
150
|
|
154
151
|
|
155
|
-
class MixedErrorTest <
|
152
|
+
class MixedErrorTest < RunningTest
|
156
153
|
desc "and has 1 pass and 1 fail assertion with an exception raised in between"
|
157
154
|
setup do
|
158
155
|
@test = Factory.test do
|
@@ -162,7 +159,6 @@ class Assert::Test::RunningTest < Assert::Context
|
|
162
159
|
end
|
163
160
|
@test.run
|
164
161
|
end
|
165
|
-
subject{ @test }
|
166
162
|
|
167
163
|
should "have an error for its last result" do
|
168
164
|
assert_kind_of Assert::Result::Error, subject.results.last
|
@@ -184,7 +180,7 @@ class Assert::Test::RunningTest < Assert::Context
|
|
184
180
|
|
185
181
|
|
186
182
|
|
187
|
-
class MixedPassTest <
|
183
|
+
class MixedPassTest < RunningTest
|
188
184
|
desc "and has 1 pass and 1 fail assertion with a pass call in between"
|
189
185
|
setup do
|
190
186
|
@test = Factory.test do
|
@@ -194,7 +190,6 @@ class Assert::Test::RunningTest < Assert::Context
|
|
194
190
|
end
|
195
191
|
@test.run
|
196
192
|
end
|
197
|
-
subject{ @test }
|
198
193
|
|
199
194
|
should "have a pass for its last result" do
|
200
195
|
assert_kind_of Assert::Result::Fail, subject.results.last
|
@@ -213,7 +208,7 @@ class Assert::Test::RunningTest < Assert::Context
|
|
213
208
|
|
214
209
|
|
215
210
|
|
216
|
-
class MixedFailTest <
|
211
|
+
class MixedFailTest < RunningTest
|
217
212
|
desc "and has 1 pass and 1 fail assertion with a fail call in between"
|
218
213
|
setup do
|
219
214
|
@test = Factory.test do
|
@@ -223,7 +218,6 @@ class Assert::Test::RunningTest < Assert::Context
|
|
223
218
|
end
|
224
219
|
@test.run
|
225
220
|
end
|
226
|
-
subject{ @test }
|
227
221
|
|
228
222
|
should "have a fail for its last result" do
|
229
223
|
assert_kind_of Assert::Result::Pass, subject.results.last
|
@@ -242,7 +236,7 @@ class Assert::Test::RunningTest < Assert::Context
|
|
242
236
|
|
243
237
|
|
244
238
|
|
245
|
-
class MixedFlunkTest <
|
239
|
+
class MixedFlunkTest < RunningTest
|
246
240
|
desc "and has 1 pass and 1 fail assertion with a flunk call in between"
|
247
241
|
setup do
|
248
242
|
@test = Factory.test do
|
@@ -252,7 +246,6 @@ class Assert::Test::RunningTest < Assert::Context
|
|
252
246
|
end
|
253
247
|
@test.run
|
254
248
|
end
|
255
|
-
subject{ @test }
|
256
249
|
|
257
250
|
should "have a fail for its last result" do
|
258
251
|
assert_kind_of Assert::Result::Pass, subject.results.last
|
@@ -271,7 +264,7 @@ class Assert::Test::RunningTest < Assert::Context
|
|
271
264
|
|
272
265
|
|
273
266
|
|
274
|
-
class WithSetupTest <
|
267
|
+
class WithSetupTest < RunningTest
|
275
268
|
desc "a Test that runs and has assertions that depend on a setup block"
|
276
269
|
setup do
|
277
270
|
@context_class = Factory.context_class do
|
@@ -282,7 +275,6 @@ class Assert::Test::RunningTest < Assert::Context
|
|
282
275
|
end
|
283
276
|
@test.run
|
284
277
|
end
|
285
|
-
subject{ @test }
|
286
278
|
|
287
279
|
should "have 1 total result" do
|
288
280
|
assert_equal 1, subject.result_count
|
@@ -295,7 +287,7 @@ class Assert::Test::RunningTest < Assert::Context
|
|
295
287
|
|
296
288
|
|
297
289
|
|
298
|
-
class WithTeardownTest <
|
290
|
+
class WithTeardownTest < RunningTest
|
299
291
|
desc "a Test that runs and has assertions with a teardown block"
|
300
292
|
setup do
|
301
293
|
new_message = @new_message = "HOLLA"
|
@@ -310,7 +302,6 @@ class Assert::Test::RunningTest < Assert::Context
|
|
310
302
|
end
|
311
303
|
@test.run
|
312
304
|
end
|
313
|
-
subject{ @test }
|
314
305
|
|
315
306
|
should "have 1 total result" do
|
316
307
|
assert_equal 1, subject.result_count
|
data/test/test_test.rb
CHANGED
@@ -1,163 +1,165 @@
|
|
1
1
|
require 'assert'
|
2
2
|
|
3
|
-
class Assert::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
INSTANCE_METHODS = [
|
18
|
-
:name, :code, :context_class,
|
19
|
-
:results, :results=,
|
20
|
-
:run, :run_setup, :run_teardown,
|
21
|
-
:result_count,
|
22
|
-
Assert::Result.types.keys.collect{|k| "#{k}_results".to_sym }
|
23
|
-
].flatten
|
24
|
-
INSTANCE_METHODS.each do |method|
|
25
|
-
should "respond to the instance method ##{method}" do
|
26
|
-
assert_respond_to subject, method
|
3
|
+
class Assert::Test
|
4
|
+
|
5
|
+
class BasicTest < Assert::Context
|
6
|
+
desc "Assert test"
|
7
|
+
setup do
|
8
|
+
test_name = "test: should do something amazing"
|
9
|
+
@test_code = lambda{ assert(true) }
|
10
|
+
context_desc = "context class"
|
11
|
+
@context_class = Factory.context_class do
|
12
|
+
desc context_desc
|
13
|
+
end
|
14
|
+
@test = Factory.test(test_name, @context_class, @test_code)
|
15
|
+
@expected_name = [ context_desc, test_name.gsub(/^test:\s+should/, "should") ].join(" ")
|
27
16
|
end
|
28
|
-
|
17
|
+
teardown do
|
18
|
+
TEST_ASSERT_SUITE.clear
|
19
|
+
end
|
20
|
+
subject{ @test }
|
29
21
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
assert_equal @context_class, subject.context_class
|
35
|
-
assert_equal @test_code, subject.code
|
36
|
-
end
|
37
|
-
should "have zero results before running" do
|
38
|
-
assert_equal 0, subject.result_count
|
39
|
-
end
|
40
|
-
should "have a custom inspect that only shows limited attributes" do
|
41
|
-
attributes_string = [ :name, :context_class, :results ].collect do |method|
|
42
|
-
"@#{method}=#{subject.send(method).inspect}"
|
43
|
-
end.join(" ")
|
44
|
-
expected = "#<#{subject.class} #{attributes_string}>"
|
45
|
-
assert_equal expected, subject.inspect
|
46
|
-
end
|
22
|
+
should have_readers :name, :code, :context_class
|
23
|
+
should have_accessor :results
|
24
|
+
should have_instance_methods :run, :result_count
|
25
|
+
should have_instance_methods *Assert::Result.types.keys.collect{|k| "#{k}_results".to_sym }
|
47
26
|
|
48
|
-
|
49
|
-
|
50
|
-
|
27
|
+
should "set it's test name to the context description with the passed in name cleaned" do
|
28
|
+
assert_equal @expected_name, subject.name
|
29
|
+
end
|
51
30
|
|
31
|
+
should "set it's context class and code from its initialize" do
|
32
|
+
assert_equal @context_class, subject.context_class
|
33
|
+
assert_equal @test_code, subject.code
|
34
|
+
end
|
35
|
+
|
36
|
+
should "have zero results before running" do
|
37
|
+
assert_equal 0, subject.result_count
|
38
|
+
end
|
39
|
+
|
40
|
+
should "have a custom inspect that only shows limited attributes" do
|
41
|
+
attributes_string = [ :name, :context_class, :results ].collect do |method|
|
42
|
+
"@#{method}=#{subject.send(method).inspect}"
|
43
|
+
end.join(" ")
|
44
|
+
expected = "#<#{subject.class} #{attributes_string}>"
|
45
|
+
assert_equal expected, subject.inspect
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
52
49
|
|
53
50
|
|
54
51
|
# testing <type>_results methods and result_count(<type>)
|
55
|
-
class ResultsTest <
|
52
|
+
class ResultsTest < BasicTest
|
56
53
|
desc "methods from Assert::Result.types"
|
54
|
+
end
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
@test.run
|
69
|
-
end
|
70
|
-
subject{ @test }
|
71
|
-
|
72
|
-
should "return the pass results with #pass_results" do
|
73
|
-
assert_kind_of Array, subject.pass_results
|
74
|
-
assert_equal 2, subject.pass_results.size
|
75
|
-
subject.pass_results.each do |result|
|
76
|
-
assert_kind_of Assert::Result::Pass, result
|
77
|
-
end
|
78
|
-
end
|
79
|
-
should "return the size of #pass_results with #result_count(:pass)" do
|
80
|
-
assert_equal(subject.pass_results.size, subject.result_count(:pass))
|
81
|
-
end
|
82
|
-
should "return the fail results with #fail_results" do
|
83
|
-
assert_kind_of Array, subject.fail_results
|
84
|
-
assert_equal 2, subject.fail_results.size
|
85
|
-
subject.fail_results.each do |result|
|
86
|
-
assert_kind_of Assert::Result::Fail, result
|
87
|
-
end
|
88
|
-
end
|
89
|
-
should "return the size of #fail_results with #result_count(:fail)" do
|
90
|
-
assert_equal(subject.fail_results.size, subject.result_count(:fail))
|
56
|
+
class PassFailIgnoreTest < ResultsTest
|
57
|
+
setup do
|
58
|
+
@test = Factory.test("pass fail ignore test", @context_class) do
|
59
|
+
ignore("something")
|
60
|
+
assert(true)
|
61
|
+
assert(false)
|
62
|
+
ignore("something else")
|
63
|
+
assert(34)
|
64
|
+
assert(nil)
|
91
65
|
end
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
66
|
+
@test.run
|
67
|
+
end
|
68
|
+
subject{ @test }
|
69
|
+
|
70
|
+
should "return the pass results with #pass_results" do
|
71
|
+
assert_kind_of Array, subject.pass_results
|
72
|
+
assert_equal 2, subject.pass_results.size
|
73
|
+
subject.pass_results.each do |result|
|
74
|
+
assert_kind_of Assert::Result::Pass, result
|
98
75
|
end
|
99
|
-
|
100
|
-
|
76
|
+
end
|
77
|
+
|
78
|
+
should "return the size of #pass_results with #result_count(:pass)" do
|
79
|
+
assert_equal(subject.pass_results.size, subject.result_count(:pass))
|
80
|
+
end
|
81
|
+
|
82
|
+
should "return the fail results with #fail_results" do
|
83
|
+
assert_kind_of Array, subject.fail_results
|
84
|
+
assert_equal 2, subject.fail_results.size
|
85
|
+
subject.fail_results.each do |result|
|
86
|
+
assert_kind_of Assert::Result::Fail, result
|
101
87
|
end
|
102
|
-
|
103
|
-
|
88
|
+
end
|
89
|
+
|
90
|
+
should "return the size of #fail_results with #result_count(:fail)" do
|
91
|
+
assert_equal(subject.fail_results.size, subject.result_count(:fail))
|
92
|
+
end
|
93
|
+
|
94
|
+
should "return the ignore results with #ignore_results" do
|
95
|
+
assert_kind_of Array, subject.ignore_results
|
96
|
+
assert_equal 2, subject.ignore_results.size
|
97
|
+
subject.ignore_results.each do |result|
|
98
|
+
assert_kind_of Assert::Result::Ignore, result
|
104
99
|
end
|
100
|
+
end
|
105
101
|
|
102
|
+
should "return the size of #ignore_results with #result_count(:ignore)" do
|
103
|
+
assert_equal(subject.ignore_results.size, subject.result_count(:ignore))
|
106
104
|
end
|
107
105
|
|
106
|
+
should "return the total number of tests with #result_count" do
|
107
|
+
assert_equal(6, subject.result_count)
|
108
|
+
end
|
108
109
|
|
110
|
+
end
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
end
|
126
|
-
should "return the size of #skip_results with #result_count(:skip)" do
|
127
|
-
assert_equal(subject.skip_results.size, subject.result_count(:skip))
|
112
|
+
|
113
|
+
|
114
|
+
class SkipHandlingTest < ResultsTest
|
115
|
+
setup do
|
116
|
+
@test = Factory.test("skip test", @context_class) { skip }
|
117
|
+
@test.run
|
118
|
+
end
|
119
|
+
subject{ @test }
|
120
|
+
|
121
|
+
should "return the skip results with #skip_results" do
|
122
|
+
assert_kind_of Array, subject.skip_results
|
123
|
+
assert_equal 1, subject.skip_results.size
|
124
|
+
subject.skip_results.each do |result|
|
125
|
+
assert_kind_of Assert::Result::Skip, result
|
128
126
|
end
|
127
|
+
end
|
129
128
|
|
129
|
+
should "return the size of #skip_results with #result_count(:skip)" do
|
130
|
+
assert_equal(subject.skip_results.size, subject.result_count(:skip))
|
130
131
|
end
|
131
132
|
|
133
|
+
end
|
134
|
+
|
132
135
|
|
133
136
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
139
|
-
@test.run
|
140
|
-
end
|
141
|
-
subject{ @test }
|
142
|
-
|
143
|
-
should "return the error results with #error_results" do
|
144
|
-
assert_kind_of Array, subject.error_results
|
145
|
-
assert_equal 1, subject.error_results.size
|
146
|
-
subject.error_results.each do |result|
|
147
|
-
assert_kind_of Assert::Result::Error, result
|
148
|
-
end
|
137
|
+
class ErrorHandlingTest < ResultsTest
|
138
|
+
setup do
|
139
|
+
@test = Factory.test("error test", @context_class) do
|
140
|
+
raise StandardError, "WHAT"
|
149
141
|
end
|
150
|
-
|
151
|
-
|
142
|
+
@test.run
|
143
|
+
end
|
144
|
+
subject{ @test }
|
145
|
+
|
146
|
+
should "return the error results with #error_results" do
|
147
|
+
assert_kind_of Array, subject.error_results
|
148
|
+
assert_equal 1, subject.error_results.size
|
149
|
+
subject.error_results.each do |result|
|
150
|
+
assert_kind_of Assert::Result::Error, result
|
152
151
|
end
|
152
|
+
end
|
153
153
|
|
154
|
+
should "return the size of #error_results with #result_count(:error)" do
|
155
|
+
assert_equal(subject.error_results.size, subject.result_count(:error))
|
154
156
|
end
|
155
157
|
|
156
158
|
end
|
157
159
|
|
158
160
|
|
159
161
|
|
160
|
-
class ComparingTest <
|
162
|
+
class ComparingTest < BasicTest
|
161
163
|
desc "<=> another test"
|
162
164
|
setup do
|
163
165
|
@test = Factory.test("mmm")
|
@@ -168,10 +170,12 @@ class Assert::Test::BasicTest < Assert::Context
|
|
168
170
|
result = @test <=> Factory.test("aaa")
|
169
171
|
assert_equal(1, result)
|
170
172
|
end
|
171
|
-
|
173
|
+
|
174
|
+
should "return 0 with a test named the same" do
|
172
175
|
result = @test <=> Factory.test(@test.name)
|
173
176
|
assert_equal(0, result)
|
174
177
|
end
|
178
|
+
|
175
179
|
should "return -1 with a test named 'zzz' (less than it)" do
|
176
180
|
result = @test <=> Factory.test("zzz")
|
177
181
|
assert_equal(-1, result)
|
@@ -179,6 +183,4 @@ class Assert::Test::BasicTest < Assert::Context
|
|
179
183
|
|
180
184
|
end
|
181
185
|
|
182
|
-
|
183
|
-
|
184
186
|
end
|