assert 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/Gemfile.lock +3 -1
  2. data/README.rdoc +6 -6
  3. data/Rakefile +2 -3
  4. data/assert.gemspec +1 -0
  5. data/lib/assert/assertions.rb +30 -30
  6. data/lib/assert/context.rb +71 -66
  7. data/lib/assert/macro.rb +14 -0
  8. data/lib/assert/macros/methods.rb +52 -0
  9. data/lib/assert/rake_tasks.rb +31 -13
  10. data/lib/assert/result.rb +12 -4
  11. data/lib/assert/result_set.rb +2 -2
  12. data/lib/assert/runner.rb +2 -6
  13. data/lib/assert/setup/autorun.rb +0 -1
  14. data/lib/assert/suite.rb +19 -15
  15. data/lib/assert/test.rb +6 -17
  16. data/lib/assert/version.rb +1 -1
  17. data/lib/assert/view/base.rb +1 -1
  18. data/lib/assert/view/terminal.rb +8 -30
  19. data/test/assertions/assert_block_test.rb +1 -1
  20. data/test/assertions/assert_empty_test.rb +43 -0
  21. data/test/assertions/assert_equal_test.rb +43 -0
  22. data/test/assertions/assert_includes_test.rb +44 -0
  23. data/test/assertions/assert_instance_of_test.rb +4 -4
  24. data/test/assertions/assert_kind_of_test.rb +3 -3
  25. data/test/assertions/assert_match_test.rb +43 -0
  26. data/test/assertions/assert_nil_test.rb +43 -0
  27. data/test/assertions/assert_not_block_test.rb +1 -1
  28. data/test/assertions/assert_not_empty_test.rb +43 -0
  29. data/test/assertions/assert_not_equal_test.rb +43 -0
  30. data/test/assertions/assert_not_included_test.rb +44 -0
  31. data/test/assertions/assert_not_instance_of_test.rb +4 -4
  32. data/test/assertions/assert_not_kind_of_test.rb +2 -2
  33. data/test/assertions/assert_not_match_test.rb +43 -0
  34. data/test/assertions/assert_not_nil_test.rb +43 -0
  35. data/test/assertions/assert_not_respond_to_test.rb +6 -6
  36. data/test/assertions/assert_not_same_test.rb +45 -0
  37. data/test/assertions/assert_respond_to_test.rb +6 -6
  38. data/test/assertions/assert_same_test.rb +45 -0
  39. data/test/assertions_test.rb +21 -298
  40. data/test/context/class_methods_test.rb +81 -112
  41. data/test/context_test.rb +35 -40
  42. data/test/helper.rb +5 -2
  43. data/test/irb.rb +2 -5
  44. data/test/macro_test.rb +99 -0
  45. data/test/options_test.rb +2 -2
  46. data/test/result_set_test.rb +47 -54
  47. data/test/result_test.rb +4 -17
  48. data/test/runner_test.rb +2 -10
  49. data/test/suite_test.rb +85 -13
  50. data/test/test/running_test.rb +19 -28
  51. data/test/test_test.rb +130 -128
  52. data/test/view_test.rb +3 -17
  53. metadata +50 -7
@@ -1,29 +1,21 @@
1
1
  require 'assert'
2
2
 
3
- class Assert::Context::ClassMethodsTest < Assert::Context
4
- desc "Assert context class"
5
- setup do
6
- @test = Factory.test
7
- @context_class = @test.context_class
8
- end
9
- subject{ @context_class }
10
-
11
- CLASS_METHODS = [
12
- :setup_once, :before_once, :teardown_once, :after_once,
13
- :setup, :before, :teardown, :after,
14
- :setup_blocks, :all_setup_blocks, :teardown_blocks, :all_teardown_blocks,
15
- :desc, :description, :descriptions, :full_description,
16
- :subject,
17
- :should
18
- ]
19
- CLASS_METHODS.each do |class_method|
20
- should "respond to the class method ##{class_method}" do
21
- assert_respond_to subject, class_method
3
+ class Assert::Context
4
+
5
+ class ClassMethodsTest < Assert::Context
6
+ desc "Assert context class"
7
+ setup do
8
+ @test = Factory.test
9
+ @context_class = @test.context_class
22
10
  end
23
- end
11
+ teardown do
12
+ TEST_ASSERT_SUITE.clear
13
+ end
14
+ subject{ @context_class }
24
15
 
25
- teardown do
26
- TEST_ASSERT_SUITE.clear
16
+ should have_instance_methods :setup_once, :before_once, :setup, :before, :setups
17
+ should have_instance_methods :teardown_once, :after_once, :teardown, :after, :teardowns
18
+ should have_instance_methods :description, :desc, :subject, :should, :should_eventually, :should_skip
27
19
  end
28
20
 
29
21
 
@@ -31,20 +23,19 @@ class Assert::Context::ClassMethodsTest < Assert::Context
31
23
  class SetupOnceTest < ClassMethodsTest
32
24
  desc "setup_once method"
33
25
  setup do
34
- setup_block = @setup_block = lambda{ something_once = true }
26
+ setup_block = @setup_block = ::Proc.new{ something_once = true }
35
27
  @context_class = Factory.context_class do
36
28
  setup_once(&setup_block)
37
29
  end
38
- @setup_blocks = Assert.suite.setup_blocks
30
+ @setup_blocks = Assert.suite.send(:setups)
31
+ end
32
+ teardown do
33
+ Assert.suite.send(:setups).reject!{|b| b == @setup_block }
39
34
  end
40
35
  subject{ @setup_blocks }
41
36
 
42
37
  should "add the block to the suite's collection of setup blocks" do
43
- assert_includes subject, @setup_block
44
- end
45
-
46
- teardown do
47
- Assert.suite.setup_blocks.reject!{|b| b == @setup_block }
38
+ assert_includes @setup_block, subject
48
39
  end
49
40
 
50
41
  end
@@ -54,20 +45,19 @@ class Assert::Context::ClassMethodsTest < Assert::Context
54
45
  class TeardownOnceTest < ClassMethodsTest
55
46
  desc "teardown_once method"
56
47
  setup do
57
- teardown_block = @teardown_block = lambda{ something_once = true }
48
+ teardown_block = @teardown_block = ::Proc.new{ something_once = true }
58
49
  @context_class = Factory.context_class do
59
50
  teardown_once(&teardown_block)
60
51
  end
61
- @teardown_blocks = Assert.suite.teardown_blocks
52
+ @teardown_blocks = Assert.suite.send(:teardowns)
53
+ end
54
+ teardown do
55
+ Assert.suite.send(:teardowns).reject!{|b| b == @teardown_block }
62
56
  end
63
57
  subject{ @teardown_blocks }
64
58
 
65
59
  should "add the block to the suite's collection of teardown blocks" do
66
- assert_includes subject, @teardown_block
67
- end
68
-
69
- teardown do
70
- Assert.suite.teardown_blocks.reject!{|b| b == @teardown_block }
60
+ assert_includes @teardown_block, subject
71
61
  end
72
62
 
73
63
  end
@@ -77,95 +67,85 @@ class Assert::Context::ClassMethodsTest < Assert::Context
77
67
  class SetupTest < ClassMethodsTest
78
68
  desc "setup method"
79
69
  setup do
80
- setup_block = @setup_block = lambda{ @something = true }
70
+ setup_block = @setup_block = ::Proc.new{ @something = true }
81
71
  @context_class = Factory.context_class do
82
72
  setup(&setup_block)
83
73
  end
84
- @setup_blocks = @context_class.setup_blocks
74
+ @setup_blocks = @context_class.send(:setups)
85
75
  end
86
76
  subject{ @setup_blocks }
87
77
 
88
78
  should "add the block to the context's collection of setup blocks" do
89
- assert_includes subject, @setup_block
90
- end
91
- should "raise an ArgumentError when no block is passed" do
92
- assert_raises ArgumentError do
93
- @context_class.setup
94
- end
79
+ assert_includes @setup_block, subject
95
80
  end
96
81
 
97
82
  end
98
83
 
99
84
 
100
85
 
101
- class TeardownTest < ClassMethodsTest
102
- desc "teardown method"
86
+ class MultipleSetupsTest < ClassMethodsTest
87
+ desc "a context class with multiple setups"
103
88
  setup do
104
- teardown_block = @teardown_block = lambda{ @something = false }
105
- @context_class = Factory.context_class do
106
- teardown(&teardown_block)
89
+ @object = (Class.new{ attr_accessor :status }).new
90
+ setup_block = @setup_block = ::Proc.new{ self.status = "the setup" }
91
+ @parent_class = Factory.context_class do
92
+ setup(&setup_block)
93
+ end
94
+ setup_block = @setup_block = ::Proc.new{ self.status += " has been run" }
95
+ @context_class = Factory.context_class(@parent_class) do
96
+ setup(&setup_block)
107
97
  end
108
- @teardown_blocks = @context_class.teardown_blocks
98
+ @context_class.setup(@object)
99
+ @expected = "the setup has been run"
109
100
  end
110
- subject{ @teardown_blocks }
101
+ subject{ @object }
111
102
 
112
- should "add the block to the context's collection of teardown blocks" do
113
- assert_includes subject, @teardown_block
114
- end
115
- should "raise an ArgumentError when no block is passed" do
116
- assert_raises ArgumentError do
117
- @context_class.teardown
118
- end
103
+ should "run it's parent and it's own setup blocks in the correct order" do
104
+ assert_equal @expected, subject.status
119
105
  end
120
106
 
121
107
  end
122
108
 
123
109
 
124
110
 
125
- class AllSetupBlocksTest < ClassMethodsTest
126
- desc "all_setup_blocks method"
111
+ class TeardownTest < ClassMethodsTest
112
+ desc "teardown method"
127
113
  setup do
128
- parent_block = @parent_block = lambda{ @parent_something = true }
129
- @parent_class = Factory.context_class do
130
- setup(&parent_block)
131
- end
132
- setup_block = @setup_block = lambda{ @something = true }
133
- @context_class = Factory.context_class(@parent_class) do
134
- setup(&setup_block)
114
+ teardown_block = @teardown_block = ::Proc.new{ @something = false }
115
+ @context_class = Factory.context_class do
116
+ teardown(&teardown_block)
135
117
  end
136
- @setup_blocks = @context_class.all_setup_blocks
118
+ @teardown_blocks = @context_class.send(:teardowns)
137
119
  end
138
- subject{ @setup_blocks }
120
+ subject{ @teardown_blocks }
139
121
 
140
- should "return a collection containing both context's setup blocks" do
141
- assert_kind_of Array, subject
142
- assert_includes subject, @parent_block
143
- assert_includes subject, @setup_block
122
+ should "add the block to the context's collection of teardown blocks" do
123
+ assert_includes @teardown_block, subject
144
124
  end
145
125
 
146
126
  end
147
127
 
148
128
 
149
129
 
150
- class AllTeardownBlocksTest < ClassMethodsTest
151
- desc "all_teardown_blocks method"
130
+ class MultipleTeardownsTest < ClassMethodsTest
131
+ desc "a context class with multiple teardowns"
152
132
  setup do
153
- parent_block = @parent_block = lambda{ @parent_something = false }
133
+ @object = (Class.new{ attr_accessor :status }).new
134
+ teardown_block = @teardown_block = ::Proc.new{ self.status += " has been run" }
154
135
  @parent_class = Factory.context_class do
155
- teardown(&parent_block)
136
+ teardown(&teardown_block)
156
137
  end
157
- teardown_block = @teardown_block = lambda{ @something = false }
138
+ teardown_block = @teardown_block = ::Proc.new{ self.status = "the teardown" }
158
139
  @context_class = Factory.context_class(@parent_class) do
159
140
  teardown(&teardown_block)
160
141
  end
161
- @teardown_blocks = @context_class.all_teardown_blocks
142
+ @context_class.teardown(@object)
143
+ @expected = "the teardown has been run"
162
144
  end
163
- subject{ @teardown_blocks }
145
+ subject{ @object }
164
146
 
165
- should "return a collection containing both context's setup blocks" do
166
- assert_kind_of Array, subject
167
- assert_includes subject, @parent_block
168
- assert_includes subject, @teardown_block
147
+ should "run it's parent and it's own teardown blocks in the correct order" do
148
+ assert_equal @expected, subject.status
169
149
  end
170
150
 
171
151
  end
@@ -173,7 +153,7 @@ class Assert::Context::ClassMethodsTest < Assert::Context
173
153
 
174
154
 
175
155
  class DescTest < ClassMethodsTest
176
- desc "desc method"
156
+ desc "desc method with an arg"
177
157
  setup do
178
158
  descs = @descs = [ "something amazing", "it really is" ]
179
159
  @context_class = Factory.context_class do
@@ -181,19 +161,13 @@ class Assert::Context::ClassMethodsTest < Assert::Context
181
161
  desc text
182
162
  end
183
163
  end
184
- @descriptions = @context_class.descriptions
185
164
  end
186
- subject{ @descriptions }
165
+ subject{ @context_class.send(:descriptions) }
187
166
 
188
167
  should "return a collection containing any descriptions defined on the class" do
189
168
  assert_kind_of Array, subject
190
169
  @descs.each do |text|
191
- assert_includes subject, text
192
- end
193
- end
194
- should "raise an error when no description is provided" do
195
- assert_raises ArgumentError do
196
- @context_class.desc
170
+ assert_includes text, subject
197
171
  end
198
172
  end
199
173
 
@@ -202,7 +176,7 @@ class Assert::Context::ClassMethodsTest < Assert::Context
202
176
 
203
177
 
204
178
  class FullDescriptionTest < ClassMethodsTest
205
- desc "full_description method"
179
+ desc "description method without an arg"
206
180
  setup do
207
181
  parent_text = @parent_desc = "parent description"
208
182
  @parent_class = Factory.context_class do
@@ -212,7 +186,7 @@ class Assert::Context::ClassMethodsTest < Assert::Context
212
186
  @context_class = Factory.context_class(@parent_class) do
213
187
  desc text
214
188
  end
215
- @full_description = @context_class.full_description
189
+ @full_description = @context_class.description
216
190
  end
217
191
  subject{ @full_description }
218
192
 
@@ -226,10 +200,10 @@ class Assert::Context::ClassMethodsTest < Assert::Context
226
200
 
227
201
 
228
202
 
229
- class SubjectTest < ClassMethodsTest
230
- desc "subject method"
203
+ class SubjectFromLocalTest < ClassMethodsTest
204
+ desc "subject method using local context"
231
205
  setup do
232
- subject_block = @subject_block = lambda{ @something }
206
+ subject_block = @subject_block = ::Proc.new{ @something }
233
207
  @context_class = Factory.context_class do
234
208
  subject(&subject_block)
235
209
  end
@@ -237,22 +211,17 @@ class Assert::Context::ClassMethodsTest < Assert::Context
237
211
  subject{ @subject_block }
238
212
 
239
213
  should "set the subject block on the context class" do
240
- assert_equal subject, @context_class.subject_block
241
- end
242
- should "raise an ArgumentError when no block is passed" do
243
- assert_raises ArgumentError do
244
- @context_class.subject
245
- end
214
+ assert_equal @context_class.subject, subject
246
215
  end
247
216
 
248
217
  end
249
218
 
250
219
 
251
220
 
252
- class SubjectBlockTest < ClassMethodsTest
253
- desc "subject_block method"
221
+ class SubjectFromParentTest < ClassMethodsTest
222
+ desc "subject method using parent context"
254
223
  setup do
255
- parent_block = @parent_block = lambda{ @something }
224
+ parent_block = @parent_block = ::Proc.new{ @something }
256
225
  @parent_class = Factory.context_class do
257
226
  subject(&parent_block)
258
227
  end
@@ -261,7 +230,7 @@ class Assert::Context::ClassMethodsTest < Assert::Context
261
230
  subject{ @parent_block }
262
231
 
263
232
  should "default to it's parents subject block" do
264
- assert_equal subject, @context_class.subject_block
233
+ assert_equal subject, @context_class.subject
265
234
  end
266
235
  end
267
236
 
@@ -271,7 +240,7 @@ class Assert::Context::ClassMethodsTest < Assert::Context
271
240
  desc "should method"
272
241
  setup do
273
242
  should_desc = "be true"
274
- should_block = @should_block = lambda{ assert(true) }
243
+ should_block = @should_block = ::Proc.new{ assert(true) }
275
244
  @context_class = Factory.context_class do
276
245
  should(should_desc, &should_block)
277
246
  end
@@ -281,7 +250,7 @@ class Assert::Context::ClassMethodsTest < Assert::Context
281
250
  subject{ @context }
282
251
 
283
252
  should "define a test method named after the should desc" do
284
- assert_respond_to subject, @method_name
253
+ assert_respond_to @method_name, subject
285
254
  assert_equal subject.instance_eval(&@should_block), subject.send(@method_name)
286
255
  end
287
256
 
@@ -293,7 +262,7 @@ class Assert::Context::ClassMethodsTest < Assert::Context
293
262
  desc "should_eventually method"
294
263
  setup do
295
264
  should_desc = @should_desc = "be true"
296
- should_block = @should_block = lambda{ assert(true) }
265
+ should_block = @should_block = ::Proc.new{ assert(true) }
297
266
  @context_class = Factory.context_class do
298
267
  should_eventually(should_desc, &should_block)
299
268
  end
@@ -303,7 +272,7 @@ class Assert::Context::ClassMethodsTest < Assert::Context
303
272
  subject{ @context }
304
273
 
305
274
  should "define a test method named after the should desc that raises a test skipped" do
306
- assert_respond_to subject, @method_name
275
+ assert_respond_to @method_name, subject
307
276
  assert_raises(Assert::Result::TestSkipped) do
308
277
  subject.send(@method_name)
309
278
  end
data/test/context_test.rb CHANGED
@@ -1,27 +1,23 @@
1
1
  require 'assert'
2
2
 
3
- class Assert::Context::BasicTest < Assert::Context
4
- desc "Assert context"
5
- setup do
6
- @test = Factory.test
7
- @context_class = @test.context_class
8
- @context = @context_class.new(@test)
9
- end
10
- subject{ @context }
3
+ class Assert::Context
11
4
 
12
- INSTANCE_METHODS = [
13
- :assert, :assert_not, :refute,
14
- :skip, :pass, :fail, :flunk, :ignore,
15
- :subject
16
- ]
17
- INSTANCE_METHODS.each do |method|
18
- should "respond to the instance method ##{method}" do
19
- assert_respond_to subject, method
5
+ class BasicTest < Assert::Context
6
+ desc "Assert context"
7
+ setup do
8
+ @test = Factory.test
9
+ @context_class = @test.context_class
10
+ @context = @context_class.new(@test)
20
11
  end
21
- end
12
+ teardown do
13
+ TEST_ASSERT_SUITE.clear
14
+ end
15
+ subject{ @context }
16
+
17
+ should have_instance_methods :assert, :assert_not, :refute
18
+ should have_instance_methods :skip, :pass, :fail, :flunk, :ignore
19
+ should have_instance_methods :subject
22
20
 
23
- teardown do
24
- TEST_ASSERT_SUITE.clear
25
21
  end
26
22
 
27
23
 
@@ -104,31 +100,30 @@ class Assert::Context::BasicTest < Assert::Context
104
100
  assert_kind_of Array, subject.backtrace
105
101
  assert_match /assert\/test\/context_test\.rb/, subject.trace
106
102
  end
103
+ end
107
104
 
108
- class StringMessageTest < FailTest
109
- desc "with a string message"
110
- setup do
111
- @fail_msg = "Didn't work"
112
- @result = @context.fail(@fail_msg)
113
- end
114
-
115
- should "set the message passed to it on the result" do
116
- assert_equal @fail_msg, subject.message
117
- end
105
+ class StringMessageTest < FailTest
106
+ desc "with a string message"
107
+ setup do
108
+ @fail_msg = "Didn't work"
109
+ @result = @context.fail(@fail_msg)
110
+ end
118
111
 
112
+ should "set the message passed to it on the result" do
113
+ assert_equal @fail_msg, subject.message
119
114
  end
120
115
 
121
- class ProcMessageTest < FailTest
122
- desc "with a proc message"
123
- setup do
124
- @fail_msg = lambda{ "Still didn't work" }
125
- @result = @context.fail(@fail_msg)
126
- end
116
+ end
127
117
 
128
- should "set the message passed to it on the result" do
129
- assert_equal @fail_msg.call, subject.message
130
- end
118
+ class ProcMessageTest < FailTest
119
+ desc "with a proc message"
120
+ setup do
121
+ @fail_msg = ::Proc.new{ "Still didn't work" }
122
+ @result = @context.fail(@fail_msg)
123
+ end
131
124
 
125
+ should "set the message passed to it on the result" do
126
+ assert_equal @fail_msg.call, subject.message
132
127
  end
133
128
 
134
129
  end
@@ -184,7 +179,7 @@ class Assert::Context::BasicTest < Assert::Context
184
179
 
185
180
  should "return a fail result" do
186
181
  assert_kind_of Assert::Result::Fail, subject
187
- assert_equal "#{@what_failed}\n#{@fail_desc}", subject.message
182
+ assert_equal [@fail_desc, @what_failed].join("\n"), subject.message
188
183
  end
189
184
 
190
185
  end
@@ -219,7 +214,7 @@ class Assert::Context::BasicTest < Assert::Context
219
214
 
220
215
  should "return a fail result" do
221
216
  assert_kind_of Assert::Result::Fail, subject
222
- assert_equal "#{@what_failed}\n#{@fail_desc}", subject.message
217
+ assert_equal [@fail_desc, @what_failed].join("\n"), subject.message
223
218
  end
224
219
 
225
220
  end