assert 2.18.3 → 2.18.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/assert/context.rb +5 -2
  3. data/lib/assert/context/let_dsl.rb +3 -3
  4. data/lib/assert/context/subject_dsl.rb +23 -24
  5. data/lib/assert/version.rb +1 -1
  6. data/test/system/stub_tests.rb +101 -117
  7. data/test/system/test_tests.rb +21 -33
  8. data/test/unit/assert_tests.rb +3 -1
  9. data/test/unit/assertions/assert_block_tests.rb +6 -8
  10. data/test/unit/assertions/assert_empty_tests.rb +10 -12
  11. data/test/unit/assertions/assert_equal_tests.rb +12 -18
  12. data/test/unit/assertions/assert_file_exists_tests.rb +10 -12
  13. data/test/unit/assertions/assert_includes_tests.rb +10 -12
  14. data/test/unit/assertions/assert_instance_of_tests.rb +10 -12
  15. data/test/unit/assertions/assert_kind_of_tests.rb +10 -12
  16. data/test/unit/assertions/assert_match_tests.rb +10 -12
  17. data/test/unit/assertions/assert_nil_tests.rb +10 -12
  18. data/test/unit/assertions/assert_raises_tests.rb +6 -8
  19. data/test/unit/assertions/assert_respond_to_tests.rb +10 -12
  20. data/test/unit/assertions/assert_same_tests.rb +16 -22
  21. data/test/unit/assertions/assert_true_false_tests.rb +20 -24
  22. data/test/unit/assertions_tests.rb +1 -2
  23. data/test/unit/config_helpers_tests.rb +8 -4
  24. data/test/unit/config_tests.rb +7 -2
  25. data/test/unit/context/setup_dsl_tests.rb +3 -3
  26. data/test/unit/context/subject_dsl_tests.rb +1 -2
  27. data/test/unit/context/suite_dsl_tests.rb +1 -2
  28. data/test/unit/context_info_tests.rb +9 -2
  29. data/test/unit/context_tests.rb +65 -73
  30. data/test/unit/default_suite_tests.rb +8 -2
  31. data/test/unit/factory_tests.rb +3 -1
  32. data/test/unit/file_line_tests.rb +8 -8
  33. data/test/unit/macro_tests.rb +10 -5
  34. data/test/unit/result_tests.rb +34 -45
  35. data/test/unit/runner_tests.rb +10 -10
  36. data/test/unit/suite_tests.rb +9 -9
  37. data/test/unit/test_tests.rb +32 -39
  38. data/test/unit/utils_tests.rb +3 -1
  39. data/test/unit/view_helpers_tests.rb +6 -7
  40. data/test/unit/view_tests.rb +4 -3
  41. metadata +2 -2
@@ -10,9 +10,14 @@ require "assert/runner"
10
10
  class Assert::Config
11
11
  class UnitTests < Assert::Context
12
12
  desc "Assert::Config"
13
- subject { config1 }
13
+ subject { unit_class }
14
14
 
15
- let(:config1) { Assert::Config.new }
15
+ let(:unit_class) { Assert::Config }
16
+ end
17
+
18
+ class InitTests < UnitTests
19
+ desc "when init"
20
+ subject { unit_class.new }
16
21
 
17
22
  should have_imeths :view, :suite, :runner
18
23
  should have_imeths :test_dir, :test_helper, :test_file_suffixes
@@ -4,10 +4,9 @@ require "assert/context/setup_dsl"
4
4
  module Assert::Context::SetupDSL
5
5
  class UnitTests < Assert::Context
6
6
  desc "Assert::Context::SetupDSL"
7
- subject { context_class1 }
7
+ subject { Factory.modes_off_context_class }
8
8
 
9
9
  let(:block1) { ::Proc.new {} }
10
- let(:context_class1) { Factory.modes_off_context_class }
11
10
  end
12
11
 
13
12
  class SetupTeardownOnceMethodsTests < UnitTests
@@ -49,8 +48,9 @@ module Assert::Context::SetupDSL
49
48
  end
50
49
 
51
50
  class ParentContextClassTests < UnitTests
51
+ subject { Factory.modes_off_context_class(parent_class1) }
52
+
52
53
  let(:parent_class1) { Factory.modes_off_context_class }
53
- let(:context_class1) { Factory.modes_off_context_class(parent_class1) }
54
54
  end
55
55
 
56
56
  class SetupTeardownMultipleTests < ParentContextClassTests
@@ -4,10 +4,9 @@ require "assert/context/subject_dsl"
4
4
  module Assert::Context::SubjectDSL
5
5
  class UnitTests < Assert::Context
6
6
  desc "Assert::Context::SubjectDSL"
7
- subject { context_class1 }
7
+ subject { Factory.modes_off_context_class(parent_class1) }
8
8
 
9
9
  let(:parent_class1) { Factory.modes_off_context_class }
10
- let(:context_class1) { Factory.modes_off_context_class(parent_class1) }
11
10
  let(:subject_block1) { Proc.new {} }
12
11
  end
13
12
 
@@ -6,10 +6,9 @@ require "assert/suite"
6
6
  module Assert::Context::SuiteDSL
7
7
  class UnitTests < Assert::Context
8
8
  desc "Assert::Context::SuiteDSL"
9
- subject { context_class1 }
9
+ subject { Factory.context_class(parent_class1) }
10
10
 
11
11
  let(:parent_class1) { Factory.context_class }
12
- let(:context_class1) { Factory.context_class(parent_class1) }
13
12
  let(:custom_suite1) { Factory.modes_off_suite }
14
13
 
15
14
  should "use `Assert.suite` by default" do
@@ -6,13 +6,20 @@ require "assert/context"
6
6
  class Assert::ContextInfo
7
7
  class UnitTests < Assert::Context
8
8
  desc "Assert::ContextInfo"
9
+ subject { unit_class }
10
+
11
+ let(:unit_class) { Assert::ContextInfo }
12
+ end
13
+
14
+ class InitTests < UnitTests
15
+ desc "when init"
16
+ subject { unit_class.new(context1, nil, @caller.first) }
17
+
9
18
  setup do
10
19
  @caller = caller
11
20
  end
12
- subject { info1 }
13
21
 
14
22
  let(:context1) { Assert::Context }
15
- let(:info1) { Assert::ContextInfo.new(context1, nil, @caller.first) }
16
23
 
17
24
  should have_readers :called_from, :klass, :file
18
25
  should have_imeths :test_name
@@ -8,7 +8,24 @@ require "assert/utils"
8
8
  class Assert::Context
9
9
  class UnitTests < Assert::Context
10
10
  desc "Assert::Context"
11
- subject { context1 }
11
+ subject { unit_class }
12
+
13
+ let(:unit_class) { Assert::Context }
14
+
15
+ # DSL methods
16
+ should have_imeths :description, :desc, :describe, :subject, :suite, :let
17
+ should have_imeths :setup_once, :before_once, :startup
18
+ should have_imeths :teardown_once, :after_once, :shutdown
19
+ should have_imeths :setup, :before, :setups, :run_setups
20
+ should have_imeths :teardown, :after, :teardowns, :run_teardowns
21
+ should have_imeths :around, :arounds, :run_arounds
22
+ should have_imeths :test, :test_eventually, :test_skip
23
+ should have_imeths :should, :should_eventually, :should_skip
24
+ end
25
+
26
+ class InitTests < UnitTests
27
+ desc "when init"
28
+ subject { context_class1.new(test1, test1.config, result_callback1) }
12
29
 
13
30
  setup do
14
31
  @callback_result = nil
@@ -20,20 +37,9 @@ class Assert::Context
20
37
  let(:result_callback1) {
21
38
  proc { |result| @callback_result = result; test_results1 << result }
22
39
  }
23
- let(:context1) { context_class1.new(test1, test1.config, result_callback1) }
24
40
  let(:halt_config1) { Assert::Config.new(:halt_on_fail => true) }
25
41
  let(:msg1) { Factory.string }
26
42
 
27
- # DSL methods
28
- should have_cmeths :description, :desc, :describe, :subject, :suite, :let
29
- should have_cmeths :setup_once, :before_once, :startup
30
- should have_cmeths :teardown_once, :after_once, :shutdown
31
- should have_cmeths :setup, :before, :setups, :run_setups
32
- should have_cmeths :teardown, :after, :teardowns, :run_teardowns
33
- should have_cmeths :around, :arounds, :run_arounds
34
- should have_cmeths :test, :test_eventually, :test_skip
35
- should have_cmeths :should, :should_eventually, :should_skip
36
-
37
43
  should have_imeths :assert, :assert_not, :refute, :assert_that
38
44
  should have_imeths :pass, :ignore, :fail, :flunk, :skip
39
45
  should have_imeths :pending, :with_backtrace, :subject
@@ -68,19 +74,18 @@ class Assert::Context
68
74
  end
69
75
  end
70
76
 
71
- class SkipTests < UnitTests
77
+ class SkipTests < InitTests
72
78
  desc "skip method"
73
- subject { @result }
74
79
 
75
80
  setup do
76
- begin; context1.skip(msg1); rescue StandardError => @exception; end
81
+ begin; subject.skip(msg1); rescue StandardError => @exception; end
77
82
  @result = Factory.skip_result(@exception)
78
83
  end
79
84
 
80
85
  should "raise a test skipped exception and set its message" do
81
86
  assert_that(@exception).is_kind_of(Assert::Result::TestSkipped)
82
87
  assert_that(@exception.message).equals(msg1)
83
- assert_that(subject.message).equals(msg1)
88
+ assert_that(@result.message).equals(msg1)
84
89
  end
85
90
 
86
91
  should "not call the result callback" do
@@ -91,23 +96,22 @@ class Assert::Context
91
96
  assert_that(@exception.backtrace.size).does_not_equal(1)
92
97
 
93
98
  called_from = Factory.string
94
- begin; context1.skip(msg1, called_from); rescue StandardError => exception; end
99
+ begin; subject.skip(msg1, called_from); rescue StandardError => exception; end
95
100
  assert_that(exception.backtrace.size).equals(1)
96
101
  assert_that(exception.backtrace.first).equals(called_from)
97
102
  end
98
103
  end
99
104
 
100
- class IgnoreTests < UnitTests
105
+ class IgnoreTests < InitTests
101
106
  desc "ignore method"
102
- subject { @result }
103
107
 
104
108
  setup do
105
- @result = context1.ignore(msg1)
109
+ @result = subject.ignore(msg1)
106
110
  end
107
111
 
108
112
  should "create an ignore result and set its message" do
109
- assert_that(subject).is_kind_of(Assert::Result::Ignore)
110
- assert_that(subject.message).equals(msg1)
113
+ assert_that(@result).is_kind_of(Assert::Result::Ignore)
114
+ assert_that(@result.message).equals(msg1)
111
115
  end
112
116
 
113
117
  should "call the result callback" do
@@ -115,17 +119,16 @@ class Assert::Context
115
119
  end
116
120
  end
117
121
 
118
- class PassTests < UnitTests
122
+ class PassTests < InitTests
119
123
  desc "pass method"
120
- subject { @result }
121
124
 
122
125
  setup do
123
- @result = context1.pass(msg1)
126
+ @result = subject.pass(msg1)
124
127
  end
125
128
 
126
129
  should "create a pass result and set its message" do
127
- assert_that(subject).is_kind_of(Assert::Result::Pass)
128
- assert_that(subject.message).equals(msg1)
130
+ assert_that(@result).is_kind_of(Assert::Result::Pass)
131
+ assert_that(@result.message).equals(msg1)
129
132
  end
130
133
 
131
134
  should "call the result callback" do
@@ -133,17 +136,16 @@ class Assert::Context
133
136
  end
134
137
  end
135
138
 
136
- class FlunkTests < UnitTests
139
+ class FlunkTests < InitTests
137
140
  desc "flunk method"
138
- subject { @result }
139
141
 
140
142
  setup do
141
- @result = context1.flunk(msg1)
143
+ @result = subject.flunk(msg1)
142
144
  end
143
145
 
144
146
  should "create a fail result and set its message" do
145
- assert_that(subject).is_kind_of(Assert::Result::Fail)
146
- assert_that(subject.message).equals(msg1)
147
+ assert_that(@result).is_kind_of(Assert::Result::Fail)
148
+ assert_that(@result.message).equals(msg1)
147
149
  end
148
150
 
149
151
  should "call the result callback" do
@@ -151,22 +153,21 @@ class Assert::Context
151
153
  end
152
154
  end
153
155
 
154
- class FailTests < UnitTests
156
+ class FailTests < InitTests
155
157
  desc "fail method"
156
- subject { @result }
157
158
 
158
159
  setup do
159
- @result = context1.fail
160
+ @result = subject.fail
160
161
  end
161
162
 
162
163
  should "create a fail result and set its backtrace" do
163
- assert_that(subject).is_kind_of(Assert::Result::Fail)
164
- assert_that(subject.trace).equals(subject.backtrace.filtered.first.to_s)
165
- assert_that(subject.backtrace).is_kind_of(Array)
164
+ assert_that(@result).is_kind_of(Assert::Result::Fail)
165
+ assert_that(@result.trace).equals(@result.backtrace.filtered.first.to_s)
166
+ assert_that(@result.backtrace).is_kind_of(Array)
166
167
  end
167
168
 
168
169
  should "set any given result message" do
169
- result = context1.fail(msg1)
170
+ result = subject.fail(msg1)
170
171
  assert_that(result.message).equals(msg1)
171
172
  end
172
173
 
@@ -175,14 +176,12 @@ class Assert::Context
175
176
  end
176
177
  end
177
178
 
178
- class HaltOnFailTests < UnitTests
179
+ class HaltOnFailTests < InitTests
179
180
  desc "failing when halting on fails"
180
- subject { @result }
181
-
182
- let(:context1) { context_class1.new(test1, halt_config1, result_callback1) }
181
+ subject { context_class1.new(test1, halt_config1, result_callback1) }
183
182
 
184
183
  should "raise an exception with the failure's message" do
185
- begin; context1.fail(msg1); rescue StandardError => err; end
184
+ begin; subject.fail(msg1); rescue StandardError => err; end
186
185
  assert_that(err).is_kind_of(Assert::Result::TestFailure)
187
186
  assert_that(err.message).equals(msg1)
188
187
 
@@ -195,7 +194,7 @@ class Assert::Context
195
194
  end
196
195
  end
197
196
 
198
- class AssertTests < UnitTests
197
+ class AssertTests < InitTests
199
198
  desc "assert method"
200
199
 
201
200
  let(:what_failed) { Factory.string }
@@ -232,7 +231,7 @@ class Assert::Context
232
231
  end
233
232
  end
234
233
 
235
- class AssertNotTests < UnitTests
234
+ class AssertNotTests < InitTests
236
235
  desc "assert_not method"
237
236
 
238
237
  should "return a pass result given a `false` assertion" do
@@ -262,7 +261,7 @@ class Assert::Context
262
261
  end
263
262
  end
264
263
 
265
- class AssertThatTests < UnitTests
264
+ class AssertThatTests < InitTests
266
265
  desc "`assert_that` method"
267
266
 
268
267
  setup do
@@ -276,39 +275,38 @@ class Assert::Context
276
275
  should "build an Assert::ActualValue" do
277
276
  assert_instance_of Assert::ActualValue, subject.assert_that(actual_value)
278
277
  assert_equal [actual_value], @actual_value_new_call.pargs
279
- assert_equal({ context: context1 }, @actual_value_new_call.kargs)
278
+ assert_equal({ context: subject }, @actual_value_new_call.kargs)
280
279
  end
281
280
  end
282
281
 
283
- class SubjectTests < UnitTests
282
+ class SubjectTests < InitTests
284
283
  desc "subject method"
285
- subject { @subject }
284
+ subject { context_class1.new(test1, test1.config, proc{ |result| }) }
286
285
 
287
286
  setup do
288
287
  expected = expected1
289
288
  context_class1.subject { @something = expected }
290
- @subject = context1.subject
289
+ @subject = subject.subject
291
290
  end
292
291
 
293
292
  let(:context_class1) { Factory.modes_off_context_class }
294
- let(:context1) { context_class1.new(test1, test1.config, proc{ |result| }) }
295
293
  let(:expected1) { Factory.string }
296
294
 
297
295
  should "instance evaluate the block set with the class setup method" do
298
- assert_that(subject).equals(expected1)
296
+ assert_that(@subject).equals(expected1)
299
297
  end
300
298
  end
301
299
 
302
- class PendingTests < UnitTests
300
+ class PendingTests < InitTests
303
301
  desc "`pending` method"
304
302
 
305
303
  let(:block2) { proc { fail; pass; } }
306
304
  let(:block1) { block = block2; proc { pending(&block) } } # test nesting
307
305
 
308
306
  should "make fails skips and make passes fails" do
309
- context1.fail "not affected"
310
- context1.pass
311
- context1.pending(&block1)
307
+ subject.fail "not affected"
308
+ subject.pass
309
+ subject.pending(&block1)
312
310
 
313
311
  assert_that(test_results1.size).equals(4)
314
312
  norm_fail, norm_pass, pending_fail, pending_pass = test_results1
@@ -326,12 +324,10 @@ class Assert::Context
326
324
 
327
325
  class PendingWithHaltOnFailTests < PendingTests
328
326
  desc "when halting on fails"
329
- subject { @result }
330
-
331
- let(:context1) { context_class1.new(test1, halt_config1, result_callback1) }
327
+ subject { context_class1.new(test1, halt_config1, result_callback1) }
332
328
 
333
329
  should "make fails skips and stop the test" do
334
- begin; context1.pending(&block1); rescue StandardError => err; end
330
+ begin; subject.pending(&block1); rescue StandardError => err; end
335
331
  assert_that(err).is_kind_of(Assert::Result::TestSkipped)
336
332
  assert_that(err.message).includes("Pending fail")
337
333
 
@@ -339,16 +335,16 @@ class Assert::Context
339
335
  end
340
336
  end
341
337
 
342
- class WithBacktraceTests < UnitTests
338
+ class WithBacktraceTests < InitTests
343
339
  desc "`with_backtrace` method"
344
340
 
345
341
  let(:from_bt1) { ["called_from_here", Factory.string] }
346
342
  let(:from_block1) { proc { ignore; fail; pass; skip "todo"; } }
347
343
 
348
344
  should "alter non-error block results' bt with given bt's first line" do
349
- context1.fail "not affected"
345
+ subject.fail "not affected"
350
346
  begin
351
- context1.with_backtrace(from_bt1, &from_block1)
347
+ subject.with_backtrace(from_bt1, &from_block1)
352
348
  rescue Assert::Result::TestSkipped => e
353
349
  test_results1 << Assert::Result::Skip.for_test(test1, e)
354
350
  end
@@ -366,7 +362,7 @@ class Assert::Context
366
362
  end
367
363
  end
368
364
 
369
- class WithNestedBacktraceTests < UnitTests
365
+ class WithNestedBacktraceTests < InitTests
370
366
  desc "`with_backtrace` method nested"
371
367
 
372
368
  let(:from_bt1) { ["called_from_here 1", Factory.string] }
@@ -379,9 +375,9 @@ class Assert::Context
379
375
  }
380
376
 
381
377
  should "alter non-error block results' bt with nested wbt accrued first lines" do
382
- context1.fail "not affected"
378
+ subject.fail "not affected"
383
379
  begin
384
- context1.with_backtrace(from_bt1, &from_block1)
380
+ subject.with_backtrace(from_bt1, &from_block1)
385
381
  rescue Assert::Result::TestSkipped => e
386
382
  test_results1 << Assert::Result::Skip.for_test(test1, e)
387
383
  end
@@ -399,15 +395,11 @@ class Assert::Context
399
395
  end
400
396
  end
401
397
 
402
- class InspectTests < UnitTests
398
+ class InspectTests < InitTests
403
399
  desc "inspect method"
404
- subject { inspect1 }
405
-
406
- let(:inspect1) { context1.inspect }
407
400
 
408
401
  should "just show the name of the class" do
409
- exp = "#<#{context1.class}>"
410
- assert_that(subject).equals(exp)
402
+ assert_that(subject.inspect).equals("#<#{subject.class}>")
411
403
  end
412
404
  end
413
405
  end
@@ -6,12 +6,18 @@ require "assert/suite"
6
6
  class Assert::DefaultSuite
7
7
  class UnitTests < Assert::Context
8
8
  desc "Assert::DefaultSuite"
9
- subject { suite1 }
9
+ subject { unit_class }
10
+
11
+ let(:unit_class) { Assert::DefaultSuite }
12
+ end
13
+
14
+ class InitTests < UnitTests
15
+ desc "when init"
16
+ subject { unit_class.new(config1) }
10
17
 
11
18
  let(:ci1) { Factory.context_info(Factory.modes_off_context_class) }
12
19
  let(:test1) { Factory.test(Factory.string, ci1) { } }
13
20
  let(:config1) { Factory.modes_off_config }
14
- let(:suite1) { Assert::DefaultSuite.new(config1) }
15
21
 
16
22
  should "be a Suite" do
17
23
  assert_that(subject).is_kind_of(Assert::Suite)
@@ -6,7 +6,9 @@ require "much-factory"
6
6
  module Assert::Factory
7
7
  class UnitTests < Assert::Context
8
8
  desc "Assert::Factory"
9
- subject { Assert::Factory }
9
+ subject { unit_class }
10
+
11
+ let(:unit_class) { Assert::Factory }
10
12
 
11
13
  should "include and extend MuchFactory" do
12
14
  assert_that(subject).includes(MuchFactory)