assert 2.0.0.rc.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Gemfile +1 -1
  2. data/{LICENSE → LICENSE.txt} +0 -0
  3. data/Rakefile +1 -3
  4. data/assert.gemspec +15 -15
  5. data/lib/assert.rb +1 -2
  6. data/lib/assert/assert_runner.rb +2 -1
  7. data/lib/assert/assertions.rb +153 -189
  8. data/lib/assert/version.rb +1 -1
  9. data/test/helper.rb +74 -51
  10. data/test/{fixtures → support}/inherited_stuff.rb +0 -0
  11. data/test/{test → system}/running_tests.rb +16 -43
  12. data/test/{assert_test.rb → unit/assert_tests.rb} +0 -0
  13. data/test/unit/assertions/assert_block_tests.rb +57 -0
  14. data/test/unit/assertions/assert_empty_tests.rb +58 -0
  15. data/test/unit/assertions/assert_equal_tests.rb +59 -0
  16. data/test/unit/assertions/assert_file_exists_tests.rb +59 -0
  17. data/test/unit/assertions/assert_includes_tests.rb +61 -0
  18. data/test/unit/assertions/assert_instance_of_tests.rb +61 -0
  19. data/test/unit/assertions/assert_kind_of_tests.rb +60 -0
  20. data/test/unit/assertions/assert_match_tests.rb +59 -0
  21. data/test/unit/assertions/assert_nil_tests.rb +59 -0
  22. data/test/unit/assertions/assert_raises_tests.rb +73 -0
  23. data/test/unit/assertions/assert_respond_to_tests.rb +63 -0
  24. data/test/unit/assertions/assert_same_tests.rb +65 -0
  25. data/test/unit/assertions_tests.rb +65 -0
  26. data/test/unit/context/basic_singleton_tests.rb +86 -0
  27. data/test/unit/context/setup_teardown_singleton_tests.rb +105 -0
  28. data/test/unit/context/test_should_singleton_tests.rb +134 -0
  29. data/test/{context_test.rb → unit/context_tests.rb} +53 -131
  30. data/test/{macro_test.rb → unit/macro_tests.rb} +15 -11
  31. data/test/{result_test.rb → unit/result_tests.rb} +27 -26
  32. data/test/{runner_test.rb → unit/runner_tests.rb} +1 -2
  33. data/test/{suite_test.rb → unit/suite_tests.rb} +63 -95
  34. data/test/{test_test.rb → unit/test_tests.rb} +45 -77
  35. data/test/{view/base_tests.rb → unit/view_tests.rb} +0 -1
  36. metadata +63 -104
  37. data/CHANGELOG.md +0 -33
  38. data/test/assertions/assert_block_test.rb +0 -39
  39. data/test/assertions/assert_empty_test.rb +0 -43
  40. data/test/assertions/assert_equal_test.rb +0 -43
  41. data/test/assertions/assert_file_exists_test.rb +0 -43
  42. data/test/assertions/assert_includes_test.rb +0 -44
  43. data/test/assertions/assert_instance_of_test.rb +0 -43
  44. data/test/assertions/assert_kind_of_test.rb +0 -43
  45. data/test/assertions/assert_match_test.rb +0 -43
  46. data/test/assertions/assert_nil_test.rb +0 -43
  47. data/test/assertions/assert_not_block_test.rb +0 -39
  48. data/test/assertions/assert_not_empty_test.rb +0 -43
  49. data/test/assertions/assert_not_equal_test.rb +0 -43
  50. data/test/assertions/assert_not_file_exists_test.rb +0 -43
  51. data/test/assertions/assert_not_included_test.rb +0 -44
  52. data/test/assertions/assert_not_instance_of_test.rb +0 -43
  53. data/test/assertions/assert_not_kind_of_test.rb +0 -43
  54. data/test/assertions/assert_not_match_test.rb +0 -43
  55. data/test/assertions/assert_not_nil_test.rb +0 -43
  56. data/test/assertions/assert_not_respond_to_test.rb +0 -43
  57. data/test/assertions/assert_not_same_test.rb +0 -45
  58. data/test/assertions/assert_nothing_raised_test.rb +0 -46
  59. data/test/assertions/assert_raises_test.rb +0 -49
  60. data/test/assertions/assert_respond_to_test.rb +0 -43
  61. data/test/assertions/assert_same_test.rb +0 -45
  62. data/test/assertions_test.rb +0 -60
  63. data/test/context/class_methods_test.rb +0 -531
  64. data/test/fixtures/sample_context.rb +0 -13
  65. data/test/fixtures/test_root/one_test.rb +0 -0
  66. data/test/fixtures/test_root/parent/area_one/area_test.rb +0 -0
  67. data/test/fixtures/test_root/shallow/deeply/nested_test.rb +0 -0
  68. data/test/fixtures/test_root/shallow/nested_test.rb +0 -0
  69. data/test/fixtures/test_root/shallow_test.rb +0 -0
  70. data/test/fixtures/test_root/two_test.rb +0 -0
  71. data/test/suite/context_info_test.rb +0 -42
@@ -1,8 +1,9 @@
1
1
  require 'assert'
2
+ require 'assert/context'
2
3
 
3
4
  class Assert::Context
4
5
 
5
- class BasicTest < Assert::Context
6
+ class BasicTests < Assert::Context
6
7
  desc "Assert context"
7
8
  setup do
8
9
  @test = Factory.test
@@ -14,46 +15,36 @@ class Assert::Context
14
15
  end
15
16
  subject{ @context }
16
17
 
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
18
+ should have_imeths :assert, :assert_not, :refute
19
+ should have_imeths :skip, :pass, :fail, :flunk, :ignore
20
+ should have_imeths :subject
20
21
 
21
22
  def test_should_collect_context_info
22
- assert_match /test\/context_test.rb$/, @__running_test__.context_info.file
23
- assert_equal self.class, @__running_test__.context_info.klass
23
+ this = @__running_test__
24
+ assert_match /test\/unit\/context_tests.rb$/, this.context_info.file
25
+ assert_equal self.class, this.context_info.klass
24
26
  end
25
27
 
26
28
  end
27
29
 
28
-
29
-
30
- class SkipTest < BasicTest
30
+ class SkipTests < BasicTests
31
31
  desc "skip method"
32
32
  setup do
33
33
  @skip_msg = "I need to implement this in the future."
34
- begin
35
- @context.skip(@skip_msg)
36
- rescue Exception => @exception
37
- end
34
+ begin; @context.skip(@skip_msg); rescue Exception => @exception; end
38
35
  @result = Factory.skip_result("something", @exception)
39
36
  end
40
37
  subject{ @result }
41
38
 
42
- should "raise a test skipped exception when called" do
39
+ should "raise a test skipped exception and set its message" do
43
40
  assert_kind_of Assert::Result::TestSkipped, @exception
44
- end
45
- should "raise the exception with the message passed to it" do
46
41
  assert_equal @skip_msg, @exception.message
47
- end
48
- should "set the message passed to it on the result" do
49
42
  assert_equal @skip_msg, subject.message
50
43
  end
51
44
 
52
45
  end
53
46
 
54
-
55
-
56
- class IgnoreTest < BasicTest
47
+ class IgnoreTests < BasicTests
57
48
  desc "ignore method"
58
49
  setup do
59
50
  @ignore_msg = "Ignore this for now, will do later."
@@ -61,18 +52,14 @@ class Assert::Context
61
52
  end
62
53
  subject{ @result }
63
54
 
64
- should "create an ignore result" do
55
+ should "create an ignore result and set its message" do
65
56
  assert_kind_of Assert::Result::Ignore, subject
66
- end
67
- should "set the messaged passed to it on the result" do
68
57
  assert_equal @ignore_msg, subject.message
69
58
  end
70
59
 
71
60
  end
72
61
 
73
-
74
-
75
- class PassTest < BasicTest
62
+ class PassTests < BasicTests
76
63
  desc "pass method"
77
64
  setup do
78
65
  @pass_msg = "That's right, it works."
@@ -80,18 +67,14 @@ class Assert::Context
80
67
  end
81
68
  subject{ @result }
82
69
 
83
- should "create a pass result" do
70
+ should "create a pass result and set its message" do
84
71
  assert_kind_of Assert::Result::Pass, subject
85
- end
86
- should "set the messaged passed to it on the result" do
87
72
  assert_equal @pass_msg, subject.message
88
73
  end
89
74
 
90
75
  end
91
76
 
92
-
93
-
94
- class FlunkTests < BasicTest
77
+ class FlunkTests < BasicTests
95
78
  desc "flunk method"
96
79
  setup do
97
80
  @flunk_msg = "It flunked."
@@ -99,53 +82,36 @@ class Assert::Context
99
82
  end
100
83
  subject{ @result }
101
84
 
102
- should "create a fail result" do
85
+ should "create a fail result and set its message" do
103
86
  assert_kind_of Assert::Result::Fail, subject
104
- end
105
- should "set the message passed to it on the result" do
106
87
  assert_equal @flunk_msg, subject.message
107
88
  end
108
89
 
109
90
  end
110
91
 
111
- class FailTests < BasicTest
92
+ class FailTests < BasicTests
112
93
  desc "fail method"
113
94
  setup do
114
95
  @result = @context.fail
115
96
  end
116
97
  subject{ @result }
117
98
 
118
- should "create a fail result" do
99
+ should "create a fail result and set its backtrace" do
119
100
  assert_kind_of Assert::Result::Fail, subject
120
- end
121
- should "set the calling backtrace on the result" do
122
- assert_kind_of Array, subject.backtrace
123
101
  assert_equal Factory.context_info_called_from, subject.trace
124
- end
125
- end
126
-
127
- class StringMessageTests < FailTests
128
- desc "with a string message"
129
- setup do
130
- @fail_msg = "Didn't work"
131
- @result = @context.fail(@fail_msg)
132
- end
133
-
134
- should "set the message passed to it on the result" do
135
- assert_equal @fail_msg, subject.message
102
+ assert_kind_of Array, subject.backtrace
136
103
  end
137
104
 
138
- end
139
-
140
- class ProcMessageTests < FailTests
141
- desc "with a proc message"
142
- setup do
143
- @fail_msg = ::Proc.new{ "Still didn't work" }
144
- @result = @context.fail(@fail_msg)
105
+ should "set any given result message" do
106
+ fail_msg = "Didn't work"
107
+ result = @context.fail(fail_msg)
108
+ assert_equal fail_msg, result.message
145
109
  end
146
110
 
147
- should "set the message passed to it on the result" do
148
- assert_equal @fail_msg.call, subject.message
111
+ should "set any given result message evaluated from a proc" do
112
+ fail_msg = ::Proc.new{ "Still didn't work" }
113
+ result = @context.fail(fail_msg)
114
+ assert_equal fail_msg.call, result.message
149
115
  end
150
116
 
151
117
  end
@@ -177,107 +143,65 @@ class Assert::Context
177
143
 
178
144
  end
179
145
 
180
-
181
-
182
- class AssertTest < BasicTest
146
+ class AssertTests < BasicTests
183
147
  desc "assert method"
184
148
  setup do
185
149
  @fail_desc = "my fail desc"
186
150
  @what_failed = "what failed"
187
151
  end
188
152
 
189
- class WithTruthyAssertionTest < AssertTest
190
- desc "with a truthy assertion"
191
- setup do
192
- @result = @context.assert(true, @fail_desc, @what_failed)
193
- end
194
- subject{ @result }
195
-
196
- should "return a pass result" do
197
- assert_kind_of Assert::Result::Pass, subject
198
- assert_nil subject.message
199
- end
200
-
153
+ should "return a pass result given a `true` assertion" do
154
+ result = subject.assert(true, @fail_desc, @what_failed)
155
+ assert_kind_of Assert::Result::Pass, result
156
+ assert_nil result.message
201
157
  end
202
158
 
203
- class WithFalseAssertionTest < AssertTest
204
- desc "with a false assertion"
205
- setup do
206
- @result = @context.assert(false, @fail_desc, @what_failed)
207
- end
208
- subject{ @result }
209
-
210
- should "return a fail result" do
211
- assert_kind_of Assert::Result::Fail, subject
212
- assert_equal [@fail_desc, @what_failed].join("\n"), subject.message
213
- end
214
-
159
+ should "return a fail result given a `false` assertion" do
160
+ result = subject.assert(false, @fail_desc, @what_failed)
161
+ assert_kind_of Assert::Result::Fail, result
162
+ assert_equal [@fail_desc, @what_failed].join("\n"), result.message
215
163
  end
216
164
 
217
- # extras
218
-
219
- should "return a pass result with a truthy (34) assertion" do
165
+ should "return a pass result given a \"truthy\" assertion" do
220
166
  assert_kind_of Assert::Result::Pass, subject.assert(34)
221
167
  end
222
168
 
223
- should "return a fail result with a nil assertion" do
169
+ should "return a fail result gievn a `nil` assertion" do
224
170
  assert_kind_of Assert::Result::Fail, subject.assert(nil)
225
171
  end
226
172
 
227
173
  end
228
174
 
229
-
230
-
231
- class AssertNotTest < BasicTest
175
+ class AssertNotTests < BasicTests
232
176
  desc "assert_not method"
233
177
  setup do
234
178
  @fail_desc = "my fail desc"
179
+ @what_failed = "Failed assert_not: assertion was <true>."
235
180
  end
236
181
 
237
- class WithTruthyAssertionTest < AssertNotTest
238
- desc "with a truthy assertion"
239
- setup do
240
- @what_failed = "Failed assert_not: assertion was <true>."
241
- @result = @context.assert_not(true, @fail_desc)
242
- end
243
- subject{ @result }
244
-
245
- should "return a fail result" do
246
- assert_kind_of Assert::Result::Fail, subject
247
- assert_equal [@fail_desc, @what_failed].join("\n"), subject.message
248
- end
249
-
182
+ should "return a fail result given a `true` assertion" do
183
+ result = subject.assert_not(true, @fail_desc)
184
+ assert_kind_of Assert::Result::Fail, result
185
+ assert_equal [@fail_desc, @what_failed].join("\n"), result.message
250
186
  end
251
187
 
252
- class WithFalseAssertionTest < AssertNotTest
253
- desc "with a false assertion"
254
- setup do
255
- @result = @context.assert_not(false, @fail_desc)
256
- end
257
- subject{ @result }
258
-
259
- should "return a pass result" do
260
- assert_kind_of Assert::Result::Pass, subject
261
- assert_nil subject.message
262
- end
263
-
188
+ should "return a pass result given a `false` assertion" do
189
+ result = subject.assert_not(false, @fail_desc)
190
+ assert_kind_of Assert::Result::Pass, result
191
+ assert_nil result.message
264
192
  end
265
193
 
266
- # extras
267
-
268
- should "return a fail result with a truthy (34) assertion" do
194
+ should "return a fail result given a \"truthy\" assertion" do
269
195
  assert_kind_of Assert::Result::Fail, subject.assert_not(34)
270
196
  end
271
197
 
272
- should "return a pass result with a nil assertion" do
198
+ should "return a pass result given a `nil` assertion" do
273
199
  assert_kind_of Assert::Result::Pass, subject.assert_not(nil)
274
200
  end
275
201
 
276
202
  end
277
203
 
278
-
279
-
280
- class SubjectTest < BasicTest
204
+ class SubjectTests < BasicTests
281
205
  desc "subject method"
282
206
  setup do
283
207
  expected = @expected = "amazing"
@@ -295,9 +219,7 @@ class Assert::Context
295
219
 
296
220
  end
297
221
 
298
-
299
-
300
- class InspectTest < BasicTest
222
+ class InspectTests < BasicTests
301
223
  desc "inspect method"
302
224
  setup do
303
225
  @expected = "#<#{@context.class}>"
@@ -1,12 +1,13 @@
1
1
  require 'assert'
2
-
3
2
  require 'assert/macro'
4
3
 
5
4
  class Assert::Macro
6
5
 
7
- class BaseTest < Assert::Context
6
+ class BaseTests < Assert::Context
8
7
  desc "a macro"
9
- setup { @macro = Assert::Macro.new {} }
8
+ setup do
9
+ @macro = Assert::Macro.new {}
10
+ end
10
11
  subject { @macro }
11
12
 
12
13
  should "have an accessor for its (optional) name" do
@@ -27,14 +28,12 @@ class Assert::Macro
27
28
  end
28
29
 
29
30
  should "complain if you create a macro without a block" do
30
- assert_raises ArgumentError do
31
- Assert::Macro.new
32
- end
31
+ assert_raises(ArgumentError) { Assert::Macro.new }
33
32
  end
34
33
 
35
34
  end
36
35
 
37
- class InstanceMethodsTest < Assert::Context
36
+ class InstanceMethodsTests < Assert::Context
38
37
  desc "a class with instance methods"
39
38
  subject do
40
39
  class ::InstExample
@@ -52,9 +51,10 @@ class Assert::Macro
52
51
  should not_have_instance_methods :method_8, :method_9
53
52
  should not_have_imeth :method_10
54
53
  should not_have_imeths :method_11, :method_12
54
+
55
55
  end
56
56
 
57
- class ClassMethodsTest < Assert::Context
57
+ class ClassMethodsTests < Assert::Context
58
58
  desc "a class with class methods"
59
59
  subject do
60
60
  class ::ClassExample
@@ -74,9 +74,10 @@ class Assert::Macro
74
74
  should not_have_class_methods :method_8, :method_9
75
75
  should not_have_cmeth :method_10
76
76
  should not_have_cmeths :method_11, :method_12
77
+
77
78
  end
78
79
 
79
- class ReadersTest < Assert::Context
80
+ class ReadersTests < Assert::Context
80
81
  desc "a class with readers"
81
82
  subject do
82
83
  class ::ReaderExample
@@ -94,9 +95,10 @@ class Assert::Macro
94
95
  should not_have_reader :method_8, :method_9
95
96
  should not_have_readers :method_10
96
97
  should not_have_readers :method_11, :method_12
98
+
97
99
  end
98
100
 
99
- class WritersTest < Assert::Context
101
+ class WritersTests < Assert::Context
100
102
  desc "a class with writers"
101
103
  subject do
102
104
  class ::WriterExample
@@ -114,9 +116,10 @@ class Assert::Macro
114
116
  should not_have_writer :method_8, :method_9
115
117
  should not_have_writers :method_10
116
118
  should not_have_writers :method_11, :method_12
119
+
117
120
  end
118
121
 
119
- class AccessorsTest < Assert::Context
122
+ class AccessorsTests < Assert::Context
120
123
  desc "a class with accessors"
121
124
  subject do
122
125
  class ::AccessorExample
@@ -134,6 +137,7 @@ class Assert::Macro
134
137
  should not_have_accessor :method_8, :method_9
135
138
  should not_have_accessors :method_10
136
139
  should not_have_accessors :method_11, :method_12
140
+
137
141
  end
138
142
 
139
143
  end
@@ -1,12 +1,13 @@
1
1
  require 'assert'
2
-
3
2
  require 'assert/result'
4
3
 
5
4
  module Assert::Result
6
5
 
7
- class BacktraceTest < Assert::Context
6
+ class BacktraceTests < Assert::Context
8
7
  desc "a result backtrace"
9
- setup{ @backtrace = Backtrace.new(caller) }
8
+ setup do
9
+ @backtrace = Backtrace.new(caller)
10
+ end
10
11
  subject { @backtrace }
11
12
 
12
13
  should have_instance_methods :to_s, :filtered
@@ -26,9 +27,10 @@ module Assert::Result
26
27
  should "default itself when created from nil" do
27
28
  assert_equal ["No backtrace"], Backtrace.new
28
29
  end
30
+
29
31
  end
30
32
 
31
- class BaseTest < Assert::Context
33
+ class BaseTests < Assert::Context
32
34
  desc "a base result"
33
35
  setup do
34
36
  @test = Factory.test("a test name")
@@ -37,7 +39,7 @@ module Assert::Result
37
39
  subject{ @result }
38
40
 
39
41
  should have_readers :test, :message, :backtrace
40
- should have_instance_methods :test_name, :name, :to_sym, :to_s, :trace
42
+ should have_imeths :test_name, :name, :to_sym, :to_s, :trace
41
43
 
42
44
  Assert::Result.types.keys.each do |type|
43
45
  should "respond to the instance method ##{type}?" do
@@ -58,12 +60,14 @@ module Assert::Result
58
60
  end
59
61
 
60
62
  should "show only its class and message when inspected" do
61
- assert_equal "#<#{subject.class} @message=#{subject.message.inspect}>", subject.inspect
63
+ exp = "#<#{subject.class} @message=#{subject.message.inspect}>"
64
+ assert_equal exp, subject.inspect
62
65
  end
63
66
 
64
67
  end
65
68
 
66
- class ToStringTest < BaseTest
69
+ class ToStringTests < BaseTests
70
+
67
71
  should "include its test context name in the to_s" do
68
72
  assert subject.to_s.include?(subject.test_name)
69
73
  end
@@ -85,7 +89,7 @@ module Assert::Result
85
89
  end
86
90
  end
87
91
 
88
- class PassTest < Assert::Context
92
+ class PassTests < Assert::Context
89
93
  desc "a pass result"
90
94
  setup do
91
95
  @test = Factory.test("a test name")
@@ -114,9 +118,10 @@ module Assert::Result
114
118
  should "include PASS in its to_s" do
115
119
  assert subject.to_s.include?("PASS")
116
120
  end
121
+
117
122
  end
118
123
 
119
- class IgnoreTest < Assert::Context
124
+ class IgnoreTests < Assert::Context
120
125
  desc "an ignore result"
121
126
  setup do
122
127
  @test = Factory.test("a test name")
@@ -145,17 +150,10 @@ module Assert::Result
145
150
  should "include IGNORE in its to_s" do
146
151
  assert subject.to_s.include?("IGNORE")
147
152
  end
148
- end
149
-
150
- class FailureRuntimeErrorTest < Assert::Context
151
-
152
- should "be a runtime error" do
153
- assert_kind_of RuntimeError, Assert::Result::TestFailure.new
154
- end
155
153
 
156
154
  end
157
155
 
158
- class FailTest < Assert::Context
156
+ class FailTests < Assert::Context
159
157
  desc "a fail result"
160
158
  setup do
161
159
  @test = Factory.test("a test name")
@@ -163,6 +161,10 @@ module Assert::Result
163
161
  end
164
162
  subject { @result }
165
163
 
164
+ should "use a runtime error (TestFailure) for controlling flow" do
165
+ assert_kind_of RuntimeError, Assert::Result::TestFailure.new
166
+ end
167
+
166
168
  should "be fail?" do
167
169
  assert_equal true, subject.fail?
168
170
  end
@@ -184,17 +186,10 @@ module Assert::Result
184
186
  should "include FAIL in its to_s" do
185
187
  assert subject.to_s.include?("FAIL")
186
188
  end
187
- end
188
-
189
- class SkippedRuntimeErrorTest < Assert::Context
190
-
191
- should "be a runtime error" do
192
- assert_kind_of RuntimeError, Assert::Result::TestSkipped.new
193
- end
194
189
 
195
190
  end
196
191
 
197
- class SkipTest < Assert::Context
192
+ class SkipTests < Assert::Context
198
193
  desc "a skip result"
199
194
  setup do
200
195
  @test = Factory.test("a test name")
@@ -208,6 +203,10 @@ module Assert::Result
208
203
  end
209
204
  subject { @result }
210
205
 
206
+ should "use a runtime error (TestSkipped) for controlling flow" do
207
+ assert_kind_of RuntimeError, Assert::Result::TestSkipped.new
208
+ end
209
+
211
210
  should "be skip?" do
212
211
  assert_equal true, subject.skip?
213
212
  end
@@ -229,9 +228,10 @@ module Assert::Result
229
228
  should "include SKIP in its to_s" do
230
229
  assert subject.to_s.include?("SKIP")
231
230
  end
231
+
232
232
  end
233
233
 
234
- class ErrorTest < Assert::Context
234
+ class ErrorTests < Assert::Context
235
235
  desc "an error result"
236
236
  setup do
237
237
  @test = Factory.test("a test name")
@@ -270,6 +270,7 @@ module Assert::Result
270
270
  should "have a trace created from the original exception's unfiltered backtrace" do
271
271
  assert_equal @exception.backtrace.join("\n"), subject.trace
272
272
  end
273
+
273
274
  end
274
275
 
275
276
  end