assert 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +17 -0
  4. data/README.rdoc +77 -0
  5. data/Rakefile +7 -0
  6. data/assert.gemspec +21 -0
  7. data/examples/empty_test.rb +5 -0
  8. data/examples/results_test.rb +25 -0
  9. data/examples/single_test.rb +9 -0
  10. data/lib/assert.rb +8 -0
  11. data/lib/assert/assertions.rb +253 -0
  12. data/lib/assert/context.rb +196 -0
  13. data/lib/assert/options.rb +43 -0
  14. data/lib/assert/rake_tasks.rb +95 -0
  15. data/lib/assert/result.rb +164 -0
  16. data/lib/assert/result_set.rb +14 -0
  17. data/lib/assert/runner.rb +60 -0
  18. data/lib/assert/setup/autorun.rb +34 -0
  19. data/lib/assert/setup/helpers.rb +62 -0
  20. data/lib/assert/setup/suite.rb +12 -0
  21. data/lib/assert/setup/view.rb +11 -0
  22. data/lib/assert/suite.rb +128 -0
  23. data/lib/assert/test.rb +90 -0
  24. data/lib/assert/version.rb +3 -0
  25. data/lib/assert/view/base.rb +54 -0
  26. data/lib/assert/view/terminal.rb +138 -0
  27. data/test/assertions/assert_block_test.rb +39 -0
  28. data/test/assertions/assert_instance_of_test.rb +43 -0
  29. data/test/assertions/assert_kind_of_test.rb +43 -0
  30. data/test/assertions/assert_not_block_test.rb +39 -0
  31. data/test/assertions/assert_not_instance_of_test.rb +43 -0
  32. data/test/assertions/assert_not_kind_of_test.rb +43 -0
  33. data/test/assertions/assert_not_respond_to_test.rb +43 -0
  34. data/test/assertions/assert_nothing_raised_test.rb +46 -0
  35. data/test/assertions/assert_raises_test.rb +49 -0
  36. data/test/assertions/assert_respond_to_test.rb +43 -0
  37. data/test/assertions_test.rb +334 -0
  38. data/test/context/class_methods_test.rb +314 -0
  39. data/test/context_test.rb +288 -0
  40. data/test/fixtures/inherited_stuff.rb +36 -0
  41. data/test/fixtures/sample_context.rb +13 -0
  42. data/test/helper.rb +52 -0
  43. data/test/irb.rb +10 -0
  44. data/test/options_test.rb +78 -0
  45. data/test/result_set_test.rb +89 -0
  46. data/test/result_test.rb +255 -0
  47. data/test/runner_test.rb +33 -0
  48. data/test/suite_test.rb +200 -0
  49. data/test/test/running_test.rb +327 -0
  50. data/test/test_test.rb +184 -0
  51. data/test/view_test.rb +35 -0
  52. metadata +155 -0
@@ -0,0 +1,327 @@
1
+ require 'assert'
2
+
3
+ class Assert::Test::RunningTest < Assert::Context
4
+ desc "Assert tests that are run"
5
+
6
+ class NothingTest < Assert::Test::RunningTest
7
+ desc "and does nothing"
8
+ setup do
9
+ @test = Factory.test
10
+ @test.run
11
+ end
12
+ subject{ @test }
13
+
14
+ should "have 0 results" do
15
+ assert_equal 0, subject.result_count
16
+ end
17
+
18
+ end
19
+
20
+
21
+
22
+ class PassTest < Assert::Test::RunningTest
23
+ desc "and passes a single assertion"
24
+ setup do
25
+ @test = Factory.test{ assert(1 == 1) }
26
+ @test.run
27
+ end
28
+ subject{ @test }
29
+
30
+ should "have 1 result" do
31
+ assert_equal 1, subject.result_count
32
+ end
33
+ should "have 1 pass result" do
34
+ assert_equal 1, subject.result_count(:pass)
35
+ end
36
+
37
+ end
38
+
39
+
40
+
41
+ class FailTest < Assert::Test::RunningTest
42
+ desc "and fails a single assertion"
43
+ setup do
44
+ @test = Factory.test{ assert(1 == 0) }
45
+ @test.run
46
+ end
47
+ subject{ @test }
48
+
49
+ should "have 1 result" do
50
+ assert_equal 1, subject.result_count
51
+ end
52
+ should "have 1 fail result" do
53
+ assert_equal 1, subject.result_count(:fail)
54
+ end
55
+
56
+ end
57
+
58
+
59
+
60
+ class SkipTest < Assert::Test::RunningTest
61
+ desc "and skips"
62
+ setup do
63
+ @test = Factory.test{ skip }
64
+ @test.run
65
+ end
66
+ subject{ @test }
67
+
68
+ should "have 1 result" do
69
+ assert_equal 1, subject.result_count
70
+ end
71
+ should "have 1 skip result" do
72
+ assert_equal 1, subject.result_count(:skip)
73
+ end
74
+
75
+ end
76
+
77
+
78
+
79
+ class ErrorTest < Assert::Test::RunningTest
80
+ desc "and errors"
81
+ setup do
82
+ @test = Factory.test{ raise("WHAT") }
83
+ @test.run
84
+ end
85
+ subject{ @test }
86
+
87
+ should "have 1 result" do
88
+ assert_equal 1, subject.result_count
89
+ end
90
+ should "have 1 error result" do
91
+ assert_equal 1, subject.result_count(:error)
92
+ end
93
+
94
+ end
95
+
96
+
97
+
98
+ class MixedTest < Assert::Test::RunningTest
99
+ desc "and has 1 pass and 1 fail assertion"
100
+ setup do
101
+ @test = Factory.test do
102
+ assert(1 == 1)
103
+ assert(1 == 0)
104
+ end
105
+ @test.run
106
+ end
107
+ subject{ @test }
108
+
109
+ should "have 2 total results" do
110
+ assert_equal 2, subject.result_count
111
+ end
112
+ should "have 1 pass result" do
113
+ assert_equal 1, subject.result_count(:pass)
114
+ end
115
+ should "have 1 fail result" do
116
+ assert_equal 1, subject.result_count(:fail)
117
+ end
118
+
119
+ end
120
+
121
+
122
+
123
+ class MixedSkipTest < Assert::Test::RunningTest
124
+ desc "and has 1 pass and 1 fail assertion with a skip call in between"
125
+ setup do
126
+ @test = Factory.test do
127
+ assert(1 == 1)
128
+ skip
129
+ assert(1 == 0)
130
+ end
131
+ @test.run
132
+ end
133
+ subject{ @test }
134
+
135
+ should "have 2 total results" do
136
+ assert_equal 2, subject.result_count
137
+ end
138
+ should "have a skip for its last result" do
139
+ assert_kind_of Assert::Result::Skip, subject.results.last
140
+ end
141
+ should "have 1 pass result" do
142
+ assert_equal 1, subject.result_count(:pass)
143
+ end
144
+ should "have 1 skip result" do
145
+ assert_equal 1, subject.result_count(:skip)
146
+ end
147
+ should "have 0 fail results" do
148
+ assert_equal 0, subject.result_count(:fail)
149
+ end
150
+
151
+ end
152
+
153
+
154
+
155
+ class MixedErrorTest < Assert::Test::RunningTest
156
+ desc "and has 1 pass and 1 fail assertion with an exception raised in between"
157
+ setup do
158
+ @test = Factory.test do
159
+ assert(1 == 1)
160
+ raise Exception, "something errored"
161
+ assert(1 == 0)
162
+ end
163
+ @test.run
164
+ end
165
+ subject{ @test }
166
+
167
+ should "have an error for its last result" do
168
+ assert_kind_of Assert::Result::Error, subject.results.last
169
+ end
170
+ should "have 2 total results" do
171
+ assert_equal 2, subject.result_count
172
+ end
173
+ should "have 1 pass result" do
174
+ assert_equal 1, subject.result_count(:pass)
175
+ end
176
+ should "have 1 error result" do
177
+ assert_equal 1, subject.result_count(:error)
178
+ end
179
+ should "have 0 fail results" do
180
+ assert_equal 0, subject.result_count(:fail)
181
+ end
182
+
183
+ end
184
+
185
+
186
+
187
+ class MixedPassTest < Assert::Test::RunningTest
188
+ desc "and has 1 pass and 1 fail assertion with a pass call in between"
189
+ setup do
190
+ @test = Factory.test do
191
+ assert(1 == 1)
192
+ pass
193
+ assert(1 == 0)
194
+ end
195
+ @test.run
196
+ end
197
+ subject{ @test }
198
+
199
+ should "have a pass for its last result" do
200
+ assert_kind_of Assert::Result::Fail, subject.results.last
201
+ end
202
+ should "have 3 total results" do
203
+ assert_equal 3, subject.result_count
204
+ end
205
+ should "have 2 pass results" do
206
+ assert_equal 2, subject.result_count(:pass)
207
+ end
208
+ should "have 1 fail results" do
209
+ assert_equal 1, subject.result_count(:fail)
210
+ end
211
+
212
+ end
213
+
214
+
215
+
216
+ class MixedFailTest < Assert::Test::RunningTest
217
+ desc "and has 1 pass and 1 fail assertion with a fail call in between"
218
+ setup do
219
+ @test = Factory.test do
220
+ assert(1 == 0)
221
+ fail
222
+ assert(1 == 1)
223
+ end
224
+ @test.run
225
+ end
226
+ subject{ @test }
227
+
228
+ should "have a fail for its last result" do
229
+ assert_kind_of Assert::Result::Pass, subject.results.last
230
+ end
231
+ should "have 3 total results" do
232
+ assert_equal 3, subject.result_count
233
+ end
234
+ should "have 1 pass results" do
235
+ assert_equal 1, subject.result_count(:pass)
236
+ end
237
+ should "have 2 fail results" do
238
+ assert_equal 2, subject.result_count(:fail)
239
+ end
240
+
241
+ end
242
+
243
+
244
+
245
+ class MixedFlunkTest < Assert::Test::RunningTest
246
+ desc "and has 1 pass and 1 fail assertion with a flunk call in between"
247
+ setup do
248
+ @test = Factory.test do
249
+ assert(1 == 0)
250
+ flunk
251
+ assert(1 == 1)
252
+ end
253
+ @test.run
254
+ end
255
+ subject{ @test }
256
+
257
+ should "have a fail for its last result" do
258
+ assert_kind_of Assert::Result::Pass, subject.results.last
259
+ end
260
+ should "have 3 total results" do
261
+ assert_equal 3, subject.result_count
262
+ end
263
+ should "have 1 pass results" do
264
+ assert_equal 1, subject.result_count(:pass)
265
+ end
266
+ should "have 2 fail results" do
267
+ assert_equal 2, subject.result_count(:fail)
268
+ end
269
+
270
+ end
271
+
272
+
273
+
274
+ class WithSetupTest < Assert::Test::RunningTest
275
+ desc "a Test that runs and has assertions that depend on a setup block"
276
+ setup do
277
+ @context_class = Factory.context_class do
278
+ setup{ @needed = true }
279
+ end
280
+ @test = Factory.test("something", @context_class) do
281
+ assert(@needed)
282
+ end
283
+ @test.run
284
+ end
285
+ subject{ @test }
286
+
287
+ should "have 1 total result" do
288
+ assert_equal 1, subject.result_count
289
+ end
290
+ should "have 1 pass result" do
291
+ assert_equal 1, subject.result_count(:pass)
292
+ end
293
+
294
+ end
295
+
296
+
297
+
298
+ class WithTeardownTest < Assert::Test::RunningTest
299
+ desc "a Test that runs and has assertions with a teardown block"
300
+ setup do
301
+ new_message = @new_message = "HOLLA"
302
+ @context_class = Factory.context_class do
303
+ teardown do
304
+ pass_result = @__running_test__.pass_results.first
305
+ pass_result.instance_variable_set("@message", new_message)
306
+ end
307
+ end
308
+ @test = Factory.test("something amazing", @context_class) do
309
+ assert(true)
310
+ end
311
+ @test.run
312
+ end
313
+ subject{ @test }
314
+
315
+ should "have 1 total result" do
316
+ assert_equal 1, subject.result_count
317
+ end
318
+ should "have 1 pass result" do
319
+ assert_equal 1, subject.result_count(:pass)
320
+ end
321
+ should "have modifed the message" do
322
+ assert_equal @new_message, subject.pass_results.first.message
323
+ end
324
+
325
+ end
326
+
327
+ end
@@ -0,0 +1,184 @@
1
+ require 'assert'
2
+
3
+ class Assert::Test::BasicTest < Assert::Context
4
+ desc "Assert test"
5
+ setup do
6
+ test_name = "test: should do something amazing"
7
+ @test_code = lambda{ assert(true) }
8
+ context_desc = "context class"
9
+ @context_class = Factory.context_class do
10
+ desc context_desc
11
+ end
12
+ @test = Factory.test(test_name, @context_class, @test_code)
13
+ @expected_name = [ context_desc, test_name.gsub(/^test:\s+should/, "should") ].join(" ")
14
+ end
15
+ subject{ @test }
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
27
+ end
28
+ end
29
+
30
+ should "set it's test name to the context description with the passed in name cleaned" do
31
+ assert_equal @expected_name, subject.name
32
+ end
33
+ should "set it's context class and code from its initialize" do
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
47
+
48
+ teardown do
49
+ TEST_ASSERT_SUITE.clear
50
+ end
51
+
52
+
53
+
54
+ # testing <type>_results methods and result_count(<type>)
55
+ class ResultsTest < Assert::Test::BasicTest
56
+ desc "methods from Assert::Result.types"
57
+
58
+ class PassFailIgnoreTest < ResultsTest
59
+ setup do
60
+ @test = Factory.test("pass fail ignore test", @context_class) do
61
+ ignore("something")
62
+ assert(true)
63
+ assert(false)
64
+ ignore("something else")
65
+ assert(34)
66
+ assert(nil)
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))
91
+ end
92
+ should "return the ignore results with #ignore_results" do
93
+ assert_kind_of Array, subject.ignore_results
94
+ assert_equal 2, subject.ignore_results.size
95
+ subject.ignore_results.each do |result|
96
+ assert_kind_of Assert::Result::Ignore, result
97
+ end
98
+ end
99
+ should "return the size of #ignore_results with #result_count(:ignore)" do
100
+ assert_equal(subject.ignore_results.size, subject.result_count(:ignore))
101
+ end
102
+ should "return the total number of tests with #result_count" do
103
+ assert_equal(6, subject.result_count)
104
+ end
105
+
106
+ end
107
+
108
+
109
+
110
+ class SkipTest < ResultsTest
111
+ setup do
112
+ @test = Factory.test("skip test", @context_class) do
113
+ skip
114
+ end
115
+ @test.run
116
+ end
117
+ subject{ @test }
118
+
119
+ should "return the skip results with #skip_results" do
120
+ assert_kind_of Array, subject.skip_results
121
+ assert_equal 1, subject.skip_results.size
122
+ subject.skip_results.each do |result|
123
+ assert_kind_of Assert::Result::Skip, result
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))
128
+ end
129
+
130
+ end
131
+
132
+
133
+
134
+ class ErrorTest < ResultsTest
135
+ setup do
136
+ @test = Factory.test("error test", @context_class) do
137
+ raise StandardError, "WHAT"
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
149
+ end
150
+ should "return the size of #error_results with #result_count(:error)" do
151
+ assert_equal(subject.error_results.size, subject.result_count(:error))
152
+ end
153
+
154
+ end
155
+
156
+ end
157
+
158
+
159
+
160
+ class ComparingTest < Assert::Test::BasicTest
161
+ desc "<=> another test"
162
+ setup do
163
+ @test = Factory.test("mmm")
164
+ end
165
+ subject{ @test }
166
+
167
+ should "return 1 with a test named 'aaa' (greater than it)" do
168
+ result = @test <=> Factory.test("aaa")
169
+ assert_equal(1, result)
170
+ end
171
+ should "return 0 with named the same" do
172
+ result = @test <=> Factory.test(@test.name)
173
+ assert_equal(0, result)
174
+ end
175
+ should "return -1 with a test named 'zzz' (less than it)" do
176
+ result = @test <=> Factory.test("zzz")
177
+ assert_equal(-1, result)
178
+ end
179
+
180
+ end
181
+
182
+
183
+
184
+ end