assert 2.19.1 → 2.19.6

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