assert 2.18.3 → 2.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/assert.gemspec +11 -5
  4. data/bin/assert +1 -0
  5. data/lib/assert.rb +20 -6
  6. data/lib/assert/actual_value.rb +26 -8
  7. data/lib/assert/assert_runner.rb +38 -17
  8. data/lib/assert/assertions.rb +145 -41
  9. data/lib/assert/cli.rb +19 -66
  10. data/lib/assert/clirb.rb +55 -0
  11. data/lib/assert/config.rb +9 -7
  12. data/lib/assert/config_helpers.rb +57 -22
  13. data/lib/assert/context.rb +33 -49
  14. data/lib/assert/context/let_dsl.rb +10 -4
  15. data/lib/assert/context/method_missing.rb +3 -0
  16. data/lib/assert/context/setup_dsl.rb +24 -16
  17. data/lib/assert/context/subject_dsl.rb +26 -25
  18. data/lib/assert/context/suite_dsl.rb +5 -1
  19. data/lib/assert/context/test_dsl.rb +58 -19
  20. data/lib/assert/context_info.rb +2 -0
  21. data/lib/assert/default_runner.rb +2 -0
  22. data/lib/assert/default_suite.rb +27 -15
  23. data/lib/assert/default_view.rb +49 -30
  24. data/lib/assert/factory.rb +2 -0
  25. data/lib/assert/file_line.rb +8 -6
  26. data/lib/assert/macro.rb +3 -1
  27. data/lib/assert/macros/methods.rb +73 -45
  28. data/lib/assert/result.rb +117 -61
  29. data/lib/assert/runner.rb +70 -51
  30. data/lib/assert/stub.rb +44 -3
  31. data/lib/assert/suite.rb +76 -38
  32. data/lib/assert/test.rb +43 -44
  33. data/lib/assert/utils.rb +22 -11
  34. data/lib/assert/version.rb +3 -1
  35. data/lib/assert/view.rb +46 -18
  36. data/lib/assert/view_helpers.rb +102 -92
  37. data/test/helper.rb +8 -4
  38. data/test/support/factory.rb +40 -21
  39. data/test/support/inherited_stuff.rb +2 -0
  40. data/test/system/stub_tests.rb +272 -250
  41. data/test/system/test_tests.rb +89 -73
  42. data/test/unit/actual_value_tests.rb +103 -46
  43. data/test/unit/assert_tests.rb +49 -39
  44. data/test/unit/assertions/assert_block_tests.rb +14 -14
  45. data/test/unit/assertions/assert_changes_tests.rb +103 -0
  46. data/test/unit/assertions/assert_empty_tests.rb +18 -16
  47. data/test/unit/assertions/assert_equal_tests.rb +48 -32
  48. data/test/unit/assertions/assert_file_exists_tests.rb +19 -17
  49. data/test/unit/assertions/assert_includes_tests.rb +14 -14
  50. data/test/unit/assertions/assert_instance_of_tests.rb +18 -18
  51. data/test/unit/assertions/assert_is_a_tests.rb +128 -0
  52. data/test/unit/assertions/assert_match_tests.rb +14 -14
  53. data/test/unit/assertions/assert_nil_tests.rb +20 -16
  54. data/test/unit/assertions/assert_raises_tests.rb +36 -27
  55. data/test/unit/assertions/assert_respond_to_tests.rb +14 -14
  56. data/test/unit/assertions/assert_same_tests.rb +28 -32
  57. data/test/unit/assertions/assert_true_false_tests.rb +38 -32
  58. data/test/unit/assertions_tests.rb +25 -18
  59. data/test/unit/config_helpers_tests.rb +20 -9
  60. data/test/unit/config_tests.rb +16 -8
  61. data/test/unit/context/let_dsl_tests.rb +2 -0
  62. data/test/unit/context/setup_dsl_tests.rb +27 -15
  63. data/test/unit/context/subject_dsl_tests.rb +5 -4
  64. data/test/unit/context/suite_dsl_tests.rb +6 -5
  65. data/test/unit/context/test_dsl_tests.rb +43 -19
  66. data/test/unit/context_info_tests.rb +12 -3
  67. data/test/unit/context_tests.rb +166 -116
  68. data/test/unit/default_runner_tests.rb +2 -0
  69. data/test/unit/default_suite_tests.rb +17 -5
  70. data/test/unit/factory_tests.rb +5 -1
  71. data/test/unit/file_line_tests.rb +14 -12
  72. data/test/unit/macro_tests.rb +17 -10
  73. data/test/unit/result_tests.rb +72 -75
  74. data/test/unit/runner_tests.rb +38 -23
  75. data/test/unit/suite_tests.rb +48 -30
  76. data/test/unit/test_tests.rb +88 -102
  77. data/test/unit/utils_tests.rb +53 -36
  78. data/test/unit/view_helpers_tests.rb +25 -17
  79. data/test/unit/view_tests.rb +8 -5
  80. metadata +40 -9
  81. data/test/unit/assertions/assert_kind_of_tests.rb +0 -68
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/default_runner"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/default_suite"
3
5
 
@@ -6,12 +8,22 @@ require "assert/suite"
6
8
  class Assert::DefaultSuite
7
9
  class UnitTests < Assert::Context
8
10
  desc "Assert::DefaultSuite"
9
- subject { suite1 }
11
+ subject{ unit_class }
12
+
13
+ let(:unit_class){ Assert::DefaultSuite }
14
+ end
15
+
16
+ class InitTests < UnitTests
17
+ desc "when init"
18
+ subject{ unit_class.new(config1) }
19
+
20
+ let(:ci1){ Factory.context_info(Factory.modes_off_context_class) }
21
+ let(:test1){ Factory.test(Factory.string, ci1){} }
22
+ let(:config1){ Factory.modes_off_config }
10
23
 
11
- let(:ci1) { Factory.context_info(Factory.modes_off_context_class) }
12
- let(:test1) { Factory.test(Factory.string, ci1) { } }
13
- let(:config1) { Factory.modes_off_config }
14
- let(:suite1) { Assert::DefaultSuite.new(config1) }
24
+ should have_readers :test_count, :result_count, :pass_result_count
25
+ should have_readers :fail_result_count, :error_result_count
26
+ should have_readers :skip_result_count, :ignore_result_count
15
27
 
16
28
  should "be a Suite" do
17
29
  assert_that(subject).is_kind_of(Assert::Suite)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/factory"
3
5
 
@@ -6,7 +8,9 @@ require "much-factory"
6
8
  module Assert::Factory
7
9
  class UnitTests < Assert::Context
8
10
  desc "Assert::Factory"
9
- subject { Assert::Factory }
11
+ subject{ unit_class }
12
+
13
+ let(:unit_class){ Assert::Factory }
10
14
 
11
15
  should "include and extend MuchFactory" do
12
16
  assert_that(subject).includes(MuchFactory)
@@ -1,20 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/file_line"
3
5
 
4
6
  class Assert::FileLine
5
7
  class UnitTests < Assert::Context
6
8
  desc "Assert::FileLine"
7
- subject { Assert::FileLine }
9
+ subject{ unit_class }
10
+
11
+ let(:unit_class){ Assert::FileLine }
8
12
 
9
- let(:file1) { "#{Factory.path}_tests.rb" }
10
- let(:line1) { Factory.integer.to_s }
13
+ let(:file1){ "#{Factory.path}_tests.rb" }
14
+ let(:line1){ Factory.integer.to_s }
11
15
 
12
16
  should have_imeths :parse
13
17
 
14
18
  should "know how to parse and init from a file line path string" do
15
19
  file_line_path = [
16
20
  "#{file1}:#{line1}",
17
- "#{file1}:#{line1} #{Factory.string}"
21
+ "#{file1}:#{line1} #{Factory.string}",
18
22
  ].sample
19
23
  file_line = subject.parse(file_line_path)
20
24
 
@@ -43,9 +47,7 @@ class Assert::FileLine
43
47
 
44
48
  class InitTests < UnitTests
45
49
  desc "when init"
46
- subject { file_line1 }
47
-
48
- let(:file_line1) { Assert::FileLine.new(file1, line1) }
50
+ subject{ unit_class.new(file1, line1) }
49
51
 
50
52
  should have_readers :file, :line
51
53
 
@@ -53,11 +55,11 @@ class Assert::FileLine
53
55
  assert_that(subject.file).equals(file1)
54
56
  assert_that(subject.line).equals(line1)
55
57
 
56
- file_line = Assert::FileLine.new(file1)
58
+ file_line = unit_class.new(file1)
57
59
  assert_that(file_line.file).equals(file1)
58
60
  assert_that(file_line.line).equals("")
59
61
 
60
- file_line = Assert::FileLine.new
62
+ file_line = unit_class.new
61
63
  assert_that(file_line.file).equals("")
62
64
  assert_that(file_line.line).equals("")
63
65
  end
@@ -67,11 +69,11 @@ class Assert::FileLine
67
69
  end
68
70
 
69
71
  should "know if it is equal to another file line" do
70
- yes = Assert::FileLine.new(file1, line1)
71
- no = Assert::FileLine.new("#{Factory.path}_tests.rb", Factory.integer.to_s)
72
+ yes = unit_class.new(file1, line1)
73
+ no = unit_class.new("#{Factory.path}_tests.rb", Factory.integer.to_s)
72
74
 
73
75
  assert_that(subject).equals(yes)
74
- assert_not_equal no, subject
76
+ assert_not_equal no, subject
75
77
  end
76
78
  end
77
79
  end
@@ -1,12 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/macro"
3
5
 
4
6
  class Assert::Macro
5
7
  class UnitTests < Assert::Context
6
8
  desc "Assert::Macro"
7
- subject { macro1 }
9
+ subject{ unit_class }
10
+
11
+ let(:unit_class){ Assert::Macro }
12
+ end
8
13
 
9
- let(:macro1) { Assert::Macro.new {} }
14
+ class InitTests < UnitTests
15
+ desc "when init"
16
+ subject{ unit_class.new{} }
10
17
 
11
18
  should "have an accessor for its (optional) name" do
12
19
  assert_that(subject).responds_to(:name)
@@ -14,11 +21,11 @@ class Assert::Macro
14
21
  end
15
22
 
16
23
  should "default its name if no given" do
17
- assert_that((Assert::Macro.new {}).name).equals("run this macro")
24
+ assert_that((unit_class.new{}).name).equals("run this macro")
18
25
  end
19
26
 
20
27
  should "initialize with a given name" do
21
- assert_that((Assert::Macro.new("test") {}).name).equals("test")
28
+ assert_that((unit_class.new("test"){}).name).equals("test")
22
29
  end
23
30
 
24
31
  should "be a Proc" do
@@ -26,7 +33,7 @@ class Assert::Macro
26
33
  end
27
34
 
28
35
  should "complain if you create a macro without a block" do
29
- assert_that(-> { Assert::Macro.new }).raises(ArgumentError)
36
+ assert_that{ unit_class.new }.raises(ArgumentError)
30
37
  end
31
38
  end
32
39
 
@@ -34,7 +41,7 @@ class Assert::Macro
34
41
  desc "have_instance_methods macro: this class"
35
42
  subject do
36
43
  class ::InstExample
37
- (1..6).each {|i| define_method("method_#{i}") {}}
44
+ (1..6).each{ |i| define_method("method_#{i}"){} }
38
45
  end
39
46
  ::InstExample.new
40
47
  end
@@ -55,7 +62,7 @@ class Assert::Macro
55
62
  subject do
56
63
  class ::ClassExample
57
64
  class << self
58
- (1..6).each {|i| define_method("method_#{i}") {}}
65
+ (1..6).each{ |i| define_method("method_#{i}"){} }
59
66
  end
60
67
  end
61
68
  ::ClassExample.new
@@ -76,7 +83,7 @@ class Assert::Macro
76
83
  desc "have_readers macro: this class"
77
84
  subject do
78
85
  class ::ReaderExample
79
- (1..6).each {|i| attr_reader "method_#{i}"}
86
+ (1..6).each{ |i| attr_reader "method_#{i}" }
80
87
  end
81
88
  ::ReaderExample.new
82
89
  end
@@ -96,7 +103,7 @@ class Assert::Macro
96
103
  desc "have_writers macro: this class"
97
104
  subject do
98
105
  class ::WriterExample
99
- (1..6).each {|i| attr_writer "method_#{i}"}
106
+ (1..6).each{ |i| attr_writer "method_#{i}" }
100
107
  end
101
108
  ::WriterExample.new
102
109
  end
@@ -116,7 +123,7 @@ class Assert::Macro
116
123
  desc "have_accessors macro: this class"
117
124
  subject do
118
125
  class ::AccessorExample
119
- (1..6).each {|i| attr_accessor "method_#{i}"}
126
+ (1..6).each{ |i| attr_accessor "method_#{i}" }
120
127
  end
121
128
  ::AccessorExample.new
122
129
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/result"
3
5
 
@@ -6,20 +8,23 @@ require "assert/file_line"
6
8
  module Assert::Result
7
9
  class UnitTests < Assert::Context
8
10
  desc "Assert::Result"
9
- subject { Assert::Result }
11
+ subject{ unit_class }
12
+
13
+ let(:unit_class){ Assert::Result }
10
14
 
11
- let(:test1) { Factory.test("a test name") }
15
+ let(:test1){ Factory.test("a test name") }
12
16
 
13
17
  should have_imeths :types, :new
14
18
 
15
19
  should "know its types" do
16
- exp = {
17
- :pass => Pass,
18
- :fail => Fail,
19
- :ignore => Ignore,
20
- :skip => Skip,
21
- :error => Error
22
- }
20
+ exp =
21
+ {
22
+ pass: Pass,
23
+ fail: Fail,
24
+ ignore: Ignore,
25
+ skip: Skip,
26
+ error: Error,
27
+ }
23
28
  assert_that(subject.types).equals(exp)
24
29
 
25
30
  assert_that(subject.types[Factory.string]).equals(Base)
@@ -27,27 +32,26 @@ module Assert::Result
27
32
 
28
33
  should "create results from data hashes" do
29
34
  type = Assert::Result.types.keys.sample
30
- exp = Assert::Result.types[type].new(:type => type)
31
- assert_that(Assert::Result.new(:type => type)).equals(exp)
35
+ exp = Assert::Result.types[type].new(type: type)
36
+ assert_that(Assert::Result.new(type: type)).equals(exp)
32
37
  end
33
38
  end
34
39
 
35
- class BaseTests < UnitTests
36
- desc "Base"
37
- subject { result1 }
40
+ class InitBaseTests < UnitTests
41
+ desc "Base when init"
42
+ subject{ Base.new(given_data1) }
38
43
 
39
- let(:given_data1) {
44
+ let(:given_data1) do
40
45
  {
41
- :type => Factory.string,
42
- :name => Factory.string,
43
- :test_name => Factory.string,
44
- :test_file_line => Assert::FileLine.new(Factory.string, Factory.integer),
45
- :message => Factory.string,
46
- :output => Factory.text,
47
- :backtrace => Backtrace.new(Factory.backtrace)
46
+ type: Factory.string,
47
+ name: Factory.string,
48
+ test_name: Factory.string,
49
+ test_file_line: Assert::FileLine.new(Factory.string, Factory.integer),
50
+ message: Factory.string,
51
+ output: Factory.text,
52
+ backtrace: Backtrace.new(Factory.backtrace),
48
53
  }
49
- }
50
- let(:result1) { Base.new(given_data1) }
54
+ end
51
55
 
52
56
  should have_cmeths :type, :name, :for_test
53
57
  should have_imeths :type, :name, :test_name, :test_file_line
@@ -121,10 +125,11 @@ module Assert::Result
121
125
  assert_that(subject.trace).equals(exp_trace)
122
126
 
123
127
  # test that the first bt line is used if filtered is empty
124
- assert_lib_path = File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
125
- new_bt = (Factory.integer(3)+1).times.map{ assert_lib_path }
126
- exp_backtrace = Backtrace.new(new_bt)
127
- exp_trace = exp_backtrace.first.to_s
128
+ assert_lib_path =
129
+ File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
130
+ new_bt = (Factory.integer(3) + 1).times.map{ assert_lib_path }
131
+ exp_backtrace = Backtrace.new(new_bt)
132
+ exp_trace = exp_backtrace.first.to_s
128
133
  subject.set_backtrace(new_bt)
129
134
  assert_that(subject.backtrace).equals(exp_backtrace)
130
135
  assert_that(subject.trace).equals(exp_trace)
@@ -168,8 +173,9 @@ module Assert::Result
168
173
  assert_that(subject.line_num).equals(exp.line.to_i)
169
174
 
170
175
  # test that the first bt line is used if filtered is empty
171
- assert_lib_path = File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
172
- new_bt = (Factory.integer(3)+1).times.map{ assert_lib_path }
176
+ assert_lib_path =
177
+ File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
178
+ new_bt = (Factory.integer(3) + 1).times.map{ assert_lib_path }
173
179
  subject.set_backtrace(new_bt)
174
180
 
175
181
  exp = new_bt.first.to_s
@@ -226,11 +232,9 @@ module Assert::Result
226
232
  end
227
233
  end
228
234
 
229
- class PassTests < UnitTests
230
- desc "Pass"
231
- subject { result1 }
232
-
233
- let(:result1) { Pass.new({}) }
235
+ class InitPassTests < UnitTests
236
+ desc "Pass when init"
237
+ subject{ Pass.new({}) }
234
238
 
235
239
  should "know its type/name" do
236
240
  assert_that(subject.type).equals(:pass)
@@ -239,11 +243,9 @@ module Assert::Result
239
243
  end
240
244
  end
241
245
 
242
- class IgnoreTests < UnitTests
243
- desc "Ignore"
244
- subject { result1 }
245
-
246
- let(:result1) { Ignore.new({}) }
246
+ class InitIgnoreTests < UnitTests
247
+ desc "Ignore when init"
248
+ subject{ Ignore.new({}) }
247
249
 
248
250
  should "know its type/name" do
249
251
  assert_that(subject.type).equals(:ignore)
@@ -252,9 +254,9 @@ module Assert::Result
252
254
  end
253
255
  end
254
256
 
255
- class HaltingTestResultErrorTests < UnitTests
256
- desc "HaltingTestResultError"
257
- subject { HaltingTestResultError.new }
257
+ class InitHaltingTestResultErrorTests < UnitTests
258
+ desc "HaltingTestResultError when init"
259
+ subject{ HaltingTestResultError.new }
258
260
 
259
261
  should have_accessors :assert_with_bt
260
262
 
@@ -263,20 +265,18 @@ module Assert::Result
263
265
  end
264
266
  end
265
267
 
266
- class TestFailureTests < UnitTests
267
- desc "TestFailure"
268
- subject { TestFailure }
268
+ class InitTestFailureTests < UnitTests
269
+ desc "TestFailure when init"
270
+ subject{ TestFailure.new }
269
271
 
270
272
  should "be a halting test result error" do
271
- assert_that(subject.new).is_kind_of(HaltingTestResultError)
273
+ assert_that(subject).is_kind_of(HaltingTestResultError)
272
274
  end
273
275
  end
274
276
 
275
- class FailTests < UnitTests
276
- desc "Fail"
277
- subject { result1 }
278
-
279
- let(:result1) { Fail.new({}) }
277
+ class InitFailTests < UnitTests
278
+ desc "Fail when init"
279
+ subject{ Fail.new({}) }
280
280
 
281
281
  should "know its type/name" do
282
282
  assert_that(subject.type).equals(:fail)
@@ -307,24 +307,23 @@ module Assert::Result
307
307
  end
308
308
 
309
309
  should "not allow creating for a test with non-TestFailure exceptions" do
310
- assert_that(-> { Fail.for_test(test1, RuntimeError.new) }).raises(ArgumentError)
310
+ assert_that{ Fail.for_test(test1, RuntimeError.new) }
311
+ .raises(ArgumentError)
311
312
  end
312
313
  end
313
314
 
314
- class TestSkippedTests < UnitTests
315
- desc "TestSkipped"
316
- subject { TestSkipped }
315
+ class InitTestSkippedTests < UnitTests
316
+ desc "TestSkipped when init"
317
+ subject{ TestSkipped.new }
317
318
 
318
319
  should "be a halting test result error" do
319
- assert_that(subject.new).is_kind_of(HaltingTestResultError)
320
+ assert_that(subject).is_kind_of(HaltingTestResultError)
320
321
  end
321
322
  end
322
323
 
323
- class SkipTests < UnitTests
324
- desc "Skip"
325
- subject { result1 }
326
-
327
- let(:result1) { Skip.new({}) }
324
+ class InitSkipTests < UnitTests
325
+ desc "Skip when init"
326
+ subject{ Skip.new({}) }
328
327
 
329
328
  should "know its type/name" do
330
329
  assert_that(subject.type).equals(:skip)
@@ -355,15 +354,14 @@ module Assert::Result
355
354
  end
356
355
 
357
356
  should "not allow creating for a test with non-TestSkipped exceptions" do
358
- assert_that(-> { Skip.for_test(test1, RuntimeError.new) }).raises(ArgumentError)
357
+ assert_that{ Skip.for_test(test1, RuntimeError.new) }
358
+ .raises(ArgumentError)
359
359
  end
360
360
  end
361
361
 
362
- class ErrorTests < UnitTests
363
- desc "Error"
364
- subject { result1 }
365
-
366
- let(:result1) { Error.new({}) }
362
+ class InitErrorTests < UnitTests
363
+ desc "Error when init"
364
+ subject{ Error.new({}) }
367
365
 
368
366
  should "know its class-level type/name" do
369
367
  assert_that(subject.class.type).equals(:error)
@@ -384,15 +382,13 @@ module Assert::Result
384
382
  end
385
383
 
386
384
  should "not allow creating for a test without an exception" do
387
- assert_that(-> { Error.for_test(test1, Factory.string) }).raises(ArgumentError)
385
+ assert_that{ Error.for_test(test1, Factory.string) }.raises(ArgumentError)
388
386
  end
389
387
  end
390
388
 
391
- class BacktraceTests < UnitTests
392
- desc "Backtrace"
393
- subject { backtrace1 }
394
-
395
- let(:backtrace1) { Backtrace.new(Factory.backtrace) }
389
+ class InitBacktraceTests < UnitTests
390
+ desc "Backtrace when init"
391
+ subject{ Backtrace.new(Factory.backtrace) }
396
392
 
397
393
  should have_cmeths :parse, :to_s
398
394
  should have_imeths :filtered
@@ -402,7 +398,8 @@ module Assert::Result
402
398
  end
403
399
 
404
400
  should "render as a string by joining on the newline" do
405
- assert_that(Backtrace.to_s(subject)).equals(subject.join(Backtrace::DELIM))
401
+ assert_that(Backtrace.to_s(subject))
402
+ .equals(subject.join(Backtrace::DELIM))
406
403
  end
407
404
 
408
405
  should "be an Array" do