assert 2.19.0 → 2.19.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/assert.gemspec +11 -6
  4. data/bin/assert +1 -0
  5. data/lib/assert.rb +20 -6
  6. data/lib/assert/actual_value.rb +11 -6
  7. data/lib/assert/assert_runner.rb +38 -17
  8. data/lib/assert/assertions.rb +85 -50
  9. data/lib/assert/cli.rb +32 -70
  10. data/lib/assert/clirb.rb +55 -0
  11. data/lib/assert/config.rb +22 -8
  12. data/lib/assert/config_helpers.rb +57 -22
  13. data/lib/assert/context.rb +16 -18
  14. data/lib/assert/context/let_dsl.rb +8 -2
  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 +9 -7
  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 +114 -62
  29. data/lib/assert/runner.rb +70 -51
  30. data/lib/assert/stub.rb +44 -3
  31. data/lib/assert/suite.rb +69 -28
  32. data/lib/assert/test.rb +43 -36
  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 +182 -144
  41. data/test/system/test_tests.rb +88 -60
  42. data/test/unit/actual_value_tests.rb +71 -50
  43. data/test/unit/assert_tests.rb +42 -23
  44. data/test/unit/assertions/assert_block_tests.rb +12 -10
  45. data/test/unit/assertions/assert_changes_tests.rb +27 -21
  46. data/test/unit/assertions/assert_empty_tests.rb +16 -12
  47. data/test/unit/assertions/assert_equal_tests.rb +28 -26
  48. data/test/unit/assertions/assert_file_exists_tests.rb +17 -13
  49. data/test/unit/assertions/assert_includes_tests.rb +12 -10
  50. data/test/unit/assertions/assert_instance_of_tests.rb +16 -14
  51. data/test/unit/assertions/assert_is_a_tests.rb +128 -0
  52. data/test/unit/assertions/assert_match_tests.rb +12 -10
  53. data/test/unit/assertions/assert_nil_tests.rb +18 -12
  54. data/test/unit/assertions/assert_raises_tests.rb +29 -20
  55. data/test/unit/assertions/assert_respond_to_tests.rb +12 -10
  56. data/test/unit/assertions/assert_same_tests.rb +26 -24
  57. data/test/unit/assertions/assert_true_false_tests.rb +34 -24
  58. data/test/unit/assertions_tests.rb +16 -9
  59. data/test/unit/config_helpers_tests.rb +17 -10
  60. data/test/unit/config_tests.rb +36 -9
  61. data/test/unit/context/let_dsl_tests.rb +2 -0
  62. data/test/unit/context/setup_dsl_tests.rb +26 -14
  63. data/test/unit/context/subject_dsl_tests.rb +5 -3
  64. data/test/unit/context/suite_dsl_tests.rb +6 -4
  65. data/test/unit/context/test_dsl_tests.rb +39 -17
  66. data/test/unit/context_info_tests.rb +6 -4
  67. data/test/unit/context_tests.rb +112 -54
  68. data/test/unit/default_runner_tests.rb +2 -0
  69. data/test/unit/default_suite_tests.rb +12 -6
  70. data/test/unit/factory_tests.rb +4 -2
  71. data/test/unit/file_line_tests.rb +9 -7
  72. data/test/unit/macro_tests.rb +13 -11
  73. data/test/unit/result_tests.rb +49 -41
  74. data/test/unit/runner_tests.rb +33 -18
  75. data/test/unit/suite_tests.rb +39 -15
  76. data/test/unit/test_tests.rb +65 -50
  77. data/test/unit/utils_tests.rb +52 -37
  78. data/test/unit/view_helpers_tests.rb +23 -14
  79. data/test/unit/view_tests.rb +7 -5
  80. metadata +26 -11
  81. data/test/unit/assertions/assert_kind_of_tests.rb +0 -66
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
 
3
5
  require "assert/config"
@@ -7,9 +9,9 @@ require "much-stub"
7
9
  module Assert
8
10
  class UnitTests < Assert::Context
9
11
  desc "Assert"
10
- subject { unit_class }
12
+ subject{ unit_class }
11
13
 
12
- let(:unit_class) { Assert }
14
+ let(:unit_class){ Assert }
13
15
 
14
16
  should have_imeths :config, :configure, :view, :suite, :runner
15
17
  should have_imeths :stubs, :stub, :unstub, :unstub!, :stub_send
@@ -29,15 +31,20 @@ module Assert
29
31
  end
30
32
 
31
33
  class StubTests < UnitTests
32
- let(:class1) {
34
+ let(:class1) do
33
35
  Class.new do
34
- def initialize(value); @value = value; end
35
- def mymeth; @value; end
36
+ def initialize(value)
37
+ @value = value
38
+ end
39
+
40
+ def mymeth
41
+ @value
42
+ end
36
43
  end
37
- }
38
- let(:object1) { class1.new(orig_value1) }
39
- let(:orig_value1) { Factory.string }
40
- let(:stub_value1) { Factory.string }
44
+ end
45
+ let(:object1){ class1.new(orig_value1) }
46
+ let(:orig_value1){ Factory.string }
47
+ let(:stub_value1){ Factory.string }
41
48
 
42
49
  should "build a stub" do
43
50
  stub1 = Assert.stub(object1, :mymeth)
@@ -47,9 +54,9 @@ module Assert
47
54
  should "build a stub with an on_call block" do
48
55
  my_meth_called_with = nil
49
56
  stub1 =
50
- Assert.stub_on_call(object1, :mymeth) { |call|
57
+ Assert.stub_on_call(object1, :mymeth) do |call|
51
58
  my_meth_called_with = call
52
- }
59
+ end
53
60
 
54
61
  object1.mymeth
55
62
  assert_kind_of MuchStub::Stub, stub1
@@ -64,7 +71,7 @@ module Assert
64
71
 
65
72
  should "set the stub's do block if given a block" do
66
73
  Assert.stub(object1, :mymeth)
67
- assert_that { object1.mymeth }.raises(MuchStub::NotStubbedError)
74
+ assert_that{ object1.mymeth }.raises(MuchStub::NotStubbedError)
68
75
  Assert.stub(object1, :mymeth){ stub_value1 }
69
76
  assert_that(object1.mymeth).equals(stub_value1)
70
77
  end
@@ -96,7 +103,7 @@ module Assert
96
103
  should "auto-unstub any stubs on teardown" do
97
104
  context_class = ::Factory.modes_off_context_class do
98
105
  setup do
99
- Assert.stub("1", :to_s){ "one" }
106
+ Assert.stub(+"1", :to_s){ "one" }
100
107
  end
101
108
  end
102
109
 
@@ -109,7 +116,7 @@ module Assert
109
116
 
110
117
  should "be able to call a stub's original method" do
111
118
  err =
112
- assert_that {
119
+ assert_that{
113
120
  Assert.stub_send(object1, :mymeth)
114
121
  }.raises(MuchStub::NotStubbedError)
115
122
  assert_that(err.message).includes("not stubbed.")
@@ -123,9 +130,9 @@ module Assert
123
130
 
124
131
  should "be able to add a stub tap" do
125
132
  my_meth_called_with = nil
126
- Assert.stub_tap(object1, :mymeth){ |value, *args, &block|
133
+ Assert.stub_tap(object1, :mymeth) do |_value, *args|
127
134
  my_meth_called_with = args
128
- }
135
+ end
129
136
 
130
137
  assert_that(object1.mymeth).equals(orig_value1)
131
138
  assert_that(my_meth_called_with).equals([])
@@ -133,9 +140,9 @@ module Assert
133
140
 
134
141
  should "be able to add a stub tap with an on_call block" do
135
142
  my_meth_called_with = nil
136
- Assert.stub_tap_on_call(object1, :mymeth){ |value, call|
143
+ Assert.stub_tap_on_call(object1, :mymeth) do |_value, call|
137
144
  my_meth_called_with = call
138
- }
145
+ end
139
146
 
140
147
  assert_that(object1.mymeth).equals(orig_value1)
141
148
  assert_that(my_meth_called_with.args).equals([])
@@ -143,10 +150,21 @@ module Assert
143
150
 
144
151
  should "be able to add a stubbed spy" do
145
152
  myclass = Class.new do
146
- def one; self; end
147
- def two(val); self; end
148
- def three; self; end
149
- def ready?; false; end
153
+ def one
154
+ self
155
+ end
156
+
157
+ def two(_val)
158
+ self
159
+ end
160
+
161
+ def three
162
+ self
163
+ end
164
+
165
+ def ready?
166
+ false
167
+ end
150
168
  end
151
169
  myobj = myclass.new
152
170
 
@@ -156,7 +174,8 @@ module Assert
156
174
  :one,
157
175
  :two,
158
176
  :three,
159
- ready?: true)
177
+ ready?: true,
178
+ )
160
179
 
161
180
  assert_that(myobj.one).equals(spy)
162
181
  assert_that(myobj.two("a")).equals(spy)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/assertions"
3
5
 
@@ -6,15 +8,15 @@ module Assert::Assertions
6
8
  include Assert::Test::TestHelpers
7
9
 
8
10
  desc "`assert_block`"
9
- subject {
11
+ subject do
10
12
  desc = desc1
11
13
  Factory.test do
12
- assert_block { true } # pass
13
- assert_block(desc) { false } # fail
14
+ assert_block{ true } # pass
15
+ assert_block(desc){ false } # fail
14
16
  end
15
- }
17
+ end
16
18
 
17
- let(:desc1) { "assert block fail desc" }
19
+ let(:desc1){ "assert block fail desc" }
18
20
 
19
21
  should "produce results as expected" do
20
22
  subject.run(&test_run_callback)
@@ -32,15 +34,15 @@ module Assert::Assertions
32
34
  include Assert::Test::TestHelpers
33
35
 
34
36
  desc "`assert_not_block`"
35
- subject {
37
+ subject do
36
38
  desc = desc1
37
39
  Factory.test do
38
- assert_not_block(desc) { true } # fail
39
- assert_not_block { false } # pass
40
+ assert_not_block(desc){ true } # fail
41
+ assert_not_block{ false } # pass
40
42
  end
41
- }
43
+ end
42
44
 
43
- let(:desc1) { "assert not block fail desc" }
45
+ let(:desc1){ "assert not block fail desc" }
44
46
 
45
47
  should "produce results as expected" do
46
48
  subject.run(&test_run_callback)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/assertions"
3
5
 
@@ -6,30 +8,30 @@ module Assert::Assertions
6
8
  include Assert::Test::TestHelpers
7
9
 
8
10
  desc "`assert_changes`"
9
- subject {
11
+ subject do
10
12
  desc = desc1
11
13
  Factory.test do
12
14
  @my_var = 1
13
- assert_changes("@my_var", from: 1, to: 2) { @my_var = 2 } # pass
15
+ assert_changes("@my_var", from: 1, to: 2){ @my_var = 2 } # pass
14
16
  @my_var = 1
15
- assert_changes("@my_var", from: 1) { @my_var = 2 } # pass
17
+ assert_changes("@my_var", from: 1){ @my_var = 2 } # pass
16
18
  @my_var = 1
17
- assert_changes("@my_var", to: 2) { @my_var = 2 } # pass
19
+ assert_changes("@my_var", to: 2){ @my_var = 2 } # pass
18
20
  @my_var = 1
19
- assert_changes("@my_var", desc: desc) { @my_var = 2 } # pass
21
+ assert_changes("@my_var", desc: desc){ @my_var = 2 } # pass
20
22
 
21
23
  @my_var = 1
22
- assert_changes("@my_var", from: 2, to: 1) { @my_var = 2 } # fail
24
+ assert_changes("@my_var", from: 2, to: 1){ @my_var = 2 } # fail
23
25
  @my_var = 1
24
- assert_changes("@my_var", from: 2) { @my_var = 2 } # fail
26
+ assert_changes("@my_var", from: 2){ @my_var = 2 } # fail
25
27
  @my_var = 1
26
- assert_changes("@my_var", to: 1) { @my_var = 2 } # fail
28
+ assert_changes("@my_var", to: 1){ @my_var = 2 } # fail
27
29
  @my_var = 1
28
- assert_changes("@my_var", desc: desc) { @my_var = 1 } # fail
30
+ assert_changes("@my_var", desc: desc){ @my_var = 1 } # fail
29
31
  end
30
- }
32
+ end
31
33
 
32
- let(:desc1) { "assert changes fail desc" }
34
+ let(:desc1){ "assert changes fail desc" }
33
35
 
34
36
  should "produce results as expected" do
35
37
  subject.run(&test_run_callback)
@@ -48,7 +50,9 @@ module Assert::Assertions
48
50
  "it was `1` and didn't change",
49
51
  ]
50
52
  messages = test_run_results(:fail).map(&:message)
51
- messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) }
53
+ messages.each_with_index do |msg, n|
54
+ assert_that(msg).matches(/^#{exp[n]}/)
55
+ end
52
56
  end
53
57
  end
54
58
 
@@ -56,24 +60,24 @@ module Assert::Assertions
56
60
  include Assert::Test::TestHelpers
57
61
 
58
62
  desc "`assert_changes`"
59
- subject {
63
+ subject do
60
64
  desc = desc1
61
65
  Factory.test do
62
66
  @my_var = 1
63
- assert_not_changes("@my_var", from: 1) { @my_var = 1 } # pass
67
+ assert_not_changes("@my_var", from: 1){ @my_var = 1 } # pass
64
68
  @my_var = 1
65
- assert_not_changes("@my_var", desc: desc) { @my_var = 1 } # pass
69
+ assert_not_changes("@my_var", desc: desc){ @my_var = 1 } # pass
66
70
 
67
71
  @my_var = 1
68
- assert_not_changes("@my_var", from: 2) { @my_var = 1 } # fail
72
+ assert_not_changes("@my_var", from: 2){ @my_var = 1 } # fail
69
73
  @my_var = 1
70
- assert_not_changes("@my_var", from: 1) { @my_var = 2 } # fail
74
+ assert_not_changes("@my_var", from: 1){ @my_var = 2 } # fail
71
75
  @my_var = 1
72
- assert_not_changes("@my_var", desc: desc) { @my_var = 2 } # fail
76
+ assert_not_changes("@my_var", desc: desc){ @my_var = 2 } # fail
73
77
  end
74
- }
78
+ end
75
79
 
76
- let(:desc1) { "assert not changes fail desc" }
80
+ let(:desc1){ "assert not changes fail desc" }
77
81
 
78
82
  should "produce results as expected" do
79
83
  subject.run(&test_run_callback)
@@ -91,7 +95,9 @@ module Assert::Assertions
91
95
  "it was `1` and changed to `2`",
92
96
  ]
93
97
  messages = test_run_results(:fail).map(&:message)
94
- messages.each_with_index{ |msg, n| assert_that(msg).matches(/^#{exp[n]}/) }
98
+ messages.each_with_index do |msg, n|
99
+ assert_that(msg).matches(/^#{exp[n]}/)
100
+ end
95
101
  end
96
102
  end
97
103
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/assertions"
3
5
 
@@ -8,17 +10,17 @@ module Assert::Assertions
8
10
  include Assert::Test::TestHelpers
9
11
 
10
12
  desc "`assert_empty`"
11
- subject {
13
+ subject do
12
14
  args = args1
13
15
  Factory.test do
14
16
  assert_empty([]) # pass
15
17
  assert_empty(*args) # fail
16
18
  end
17
- }
19
+ end
18
20
 
19
- let(:desc1) { "assert empty fail desc" }
20
- let(:args1) { [[1], desc1] }
21
- let(:config1) { subject.config }
21
+ let(:desc1){ "assert empty fail desc" }
22
+ let(:args1){ [[1], desc1] }
23
+ let(:config1){ subject.config }
22
24
 
23
25
  should "produce results as expected" do
24
26
  subject.run(&test_run_callback)
@@ -28,7 +30,8 @@ module Assert::Assertions
28
30
  assert_that(test_run_result_count(:fail)).equals(1)
29
31
 
30
32
  exp =
31
- "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to be empty."
33
+ "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to be "\
34
+ "empty."
32
35
  assert_that(test_run_results(:fail).first.message).equals(exp)
33
36
  end
34
37
  end
@@ -37,17 +40,17 @@ module Assert::Assertions
37
40
  include Assert::Test::TestHelpers
38
41
 
39
42
  desc "`assert_not_empty`"
40
- subject {
43
+ subject do
41
44
  args = args1
42
45
  Factory.test do
43
46
  assert_not_empty([1]) # pass
44
47
  assert_not_empty(*args) # fail
45
48
  end
46
- }
49
+ end
47
50
 
48
- let(:desc1) { "assert not empty fail desc" }
49
- let(:args1) { [[], desc1] }
50
- let(:config1) { subject.config }
51
+ let(:desc1){ "assert not empty fail desc" }
52
+ let(:args1){ [[], desc1] }
53
+ let(:config1){ subject.config }
51
54
 
52
55
  should "produce results as expected" do
53
56
  subject.run(&test_run_callback)
@@ -57,7 +60,8 @@ module Assert::Assertions
57
60
  assert_that(test_run_result_count(:fail)).equals(1)
58
61
 
59
62
  exp =
60
- "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to not be empty."
63
+ "#{args1[1]}\nExpected #{Assert::U.show(args1[0], config1)} to not "\
64
+ "be empty."
61
65
  assert_that(test_run_results(:fail).first.message).equals(exp)
62
66
  end
63
67
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "assert"
2
4
  require "assert/assertions"
3
5
 
@@ -8,17 +10,17 @@ module Assert::Assertions
8
10
  include Assert::Test::TestHelpers
9
11
 
10
12
  desc "`assert_equal`"
11
- subject {
13
+ subject do
12
14
  args = args1
13
15
  Factory.test do
14
16
  assert_equal(1, 1) # pass
15
17
  assert_equal(*args) # fail
16
18
  end
17
- }
19
+ end
18
20
 
19
- let(:desc1) { "assert equal fail desc" }
20
- let(:args1) { ["1", "2", desc1] }
21
- let(:config1) { subject.config }
21
+ let(:desc1){ "assert equal fail desc" }
22
+ let(:args1){ ["1", "2", desc1] }
23
+ let(:config1){ subject.config }
22
24
 
23
25
  should "produce results as expected" do
24
26
  subject.run(&test_run_callback)
@@ -38,17 +40,17 @@ module Assert::Assertions
38
40
  include Assert::Test::TestHelpers
39
41
 
40
42
  desc "`assert_not_equal`"
41
- subject {
43
+ subject do
42
44
  args = args1
43
45
  Factory.test do
44
46
  assert_not_equal(*args) # fail
45
47
  assert_not_equal(1, 2) # pass
46
48
  end
47
- }
49
+ end
48
50
 
49
- let(:desc1) { "assert not equal fail desc" }
50
- let(:args1) { ["1", "1", desc1] }
51
- let(:config1) { subject.config }
51
+ let(:desc1){ "assert not equal fail desc" }
52
+ let(:args1){ ["1", "1", desc1] }
53
+ let(:config1){ subject.config }
52
54
 
53
55
  should "produce results as expected" do
54
56
  subject.run(&test_run_callback)
@@ -69,7 +71,7 @@ module Assert::Assertions
69
71
 
70
72
  desc "with objects that define custom equality operators"
71
73
 
72
- let(:is_class) {
74
+ let(:is_class) do
73
75
  Class.new do
74
76
  def ==(other)
75
77
  if other.is_a?(Assert::ActualValue.not_given.class)
@@ -79,8 +81,8 @@ module Assert::Assertions
79
81
  end
80
82
  end
81
83
  end
82
- }
83
- let(:is_not_class) {
84
+ end
85
+ let(:is_not_class) do
84
86
  Class.new do
85
87
  def ==(other)
86
88
  if other.is_a?(Assert::ActualValue.not_given.class)
@@ -90,10 +92,10 @@ module Assert::Assertions
90
92
  end
91
93
  end
92
94
  end
93
- }
95
+ end
94
96
 
95
- let(:is1) { is_class.new }
96
- let(:is_not1) { is_not_class.new }
97
+ let(:is1){ is_class.new }
98
+ let(:is_not1){ is_not_class.new }
97
99
 
98
100
  should "use the equality operator of the exp value" do
99
101
  assert_that(is1).equals(is_not1)
@@ -106,27 +108,27 @@ module Assert::Assertions
106
108
 
107
109
  desc "with objects that should use diff when showing"
108
110
 
109
- let(:config1) {
111
+ let(:config1) do
110
112
  Factory.modes_off_config.tap do |config|
111
113
  config.use_diff_proc(Assert::U.default_use_diff_proc)
112
114
  config.run_diff_proc(Assert::U.syscmd_diff_proc)
113
115
  end
114
- }
116
+ end
115
117
 
116
- let(:exp_obj1) { "I'm a\nstring" }
117
- let(:act_obj1) { "I am a \nstring" }
118
- let(:exp_obj_show1) { Assert::U.show_for_diff(exp_obj1, config1) }
119
- let(:act_obj_show1) { Assert::U.show_for_diff(act_obj1, config1) }
118
+ let(:exp_obj1){ "I'm a\nstring" }
119
+ let(:act_obj1){ "I am a \nstring" }
120
+ let(:exp_obj_show1){ Assert::U.show_for_diff(exp_obj1, config1) }
121
+ let(:act_obj_show1){ Assert::U.show_for_diff(act_obj1, config1) }
120
122
  end
121
123
 
122
124
  class AssertEqualDiffTests < DiffTests
123
125
  desc "`assert_equal`"
124
- subject {
126
+ subject do
125
127
  exp_obj, act_obj = exp_obj1, act_obj1
126
128
  Factory.test(config1) do
127
129
  assert_equal(exp_obj, act_obj)
128
130
  end
129
- }
131
+ end
130
132
 
131
133
  should "include diff output in the fail messages" do
132
134
  subject.run(&test_run_callback)
@@ -140,12 +142,12 @@ module Assert::Assertions
140
142
 
141
143
  class AssertNotEqualDiffTests < DiffTests
142
144
  desc "`assert_not_equal`"
143
- subject {
145
+ subject do
144
146
  exp_obj = exp_obj1
145
147
  Factory.test(config1) do
146
148
  assert_not_equal(exp_obj, exp_obj)
147
149
  end
148
- }
150
+ end
149
151
 
150
152
  should "include diff output in the fail messages" do
151
153
  subject.run(&test_run_callback)