assert 2.19.0 → 2.19.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/assert.gemspec +11 -6
- data/bin/assert +1 -0
- data/lib/assert.rb +20 -6
- data/lib/assert/actual_value.rb +11 -6
- data/lib/assert/assert_runner.rb +38 -17
- data/lib/assert/assertions.rb +85 -50
- data/lib/assert/cli.rb +32 -70
- data/lib/assert/clirb.rb +55 -0
- data/lib/assert/config.rb +22 -8
- data/lib/assert/config_helpers.rb +57 -22
- data/lib/assert/context.rb +16 -18
- data/lib/assert/context/let_dsl.rb +8 -2
- data/lib/assert/context/method_missing.rb +3 -0
- data/lib/assert/context/setup_dsl.rb +24 -16
- data/lib/assert/context/subject_dsl.rb +9 -7
- data/lib/assert/context/suite_dsl.rb +5 -1
- data/lib/assert/context/test_dsl.rb +58 -19
- data/lib/assert/context_info.rb +2 -0
- data/lib/assert/default_runner.rb +2 -0
- data/lib/assert/default_suite.rb +27 -15
- data/lib/assert/default_view.rb +49 -30
- data/lib/assert/factory.rb +2 -0
- data/lib/assert/file_line.rb +8 -6
- data/lib/assert/macro.rb +3 -1
- data/lib/assert/macros/methods.rb +73 -45
- data/lib/assert/result.rb +114 -62
- data/lib/assert/runner.rb +70 -51
- data/lib/assert/stub.rb +44 -3
- data/lib/assert/suite.rb +69 -28
- data/lib/assert/test.rb +43 -36
- data/lib/assert/utils.rb +22 -11
- data/lib/assert/version.rb +3 -1
- data/lib/assert/view.rb +46 -18
- data/lib/assert/view_helpers.rb +102 -92
- data/test/helper.rb +8 -4
- data/test/support/factory.rb +40 -21
- data/test/support/inherited_stuff.rb +2 -0
- data/test/system/stub_tests.rb +182 -144
- data/test/system/test_tests.rb +88 -60
- data/test/unit/actual_value_tests.rb +71 -50
- data/test/unit/assert_tests.rb +42 -23
- data/test/unit/assertions/assert_block_tests.rb +12 -10
- data/test/unit/assertions/assert_changes_tests.rb +27 -21
- data/test/unit/assertions/assert_empty_tests.rb +16 -12
- data/test/unit/assertions/assert_equal_tests.rb +28 -26
- data/test/unit/assertions/assert_file_exists_tests.rb +17 -13
- data/test/unit/assertions/assert_includes_tests.rb +12 -10
- data/test/unit/assertions/assert_instance_of_tests.rb +16 -14
- data/test/unit/assertions/assert_is_a_tests.rb +128 -0
- data/test/unit/assertions/assert_match_tests.rb +12 -10
- data/test/unit/assertions/assert_nil_tests.rb +18 -12
- data/test/unit/assertions/assert_raises_tests.rb +29 -20
- data/test/unit/assertions/assert_respond_to_tests.rb +12 -10
- data/test/unit/assertions/assert_same_tests.rb +26 -24
- data/test/unit/assertions/assert_true_false_tests.rb +34 -24
- data/test/unit/assertions_tests.rb +16 -9
- data/test/unit/config_helpers_tests.rb +17 -10
- data/test/unit/config_tests.rb +36 -9
- data/test/unit/context/let_dsl_tests.rb +2 -0
- data/test/unit/context/setup_dsl_tests.rb +26 -14
- data/test/unit/context/subject_dsl_tests.rb +5 -3
- data/test/unit/context/suite_dsl_tests.rb +6 -4
- data/test/unit/context/test_dsl_tests.rb +39 -17
- data/test/unit/context_info_tests.rb +6 -4
- data/test/unit/context_tests.rb +112 -54
- data/test/unit/default_runner_tests.rb +2 -0
- data/test/unit/default_suite_tests.rb +12 -6
- data/test/unit/factory_tests.rb +4 -2
- data/test/unit/file_line_tests.rb +9 -7
- data/test/unit/macro_tests.rb +13 -11
- data/test/unit/result_tests.rb +49 -41
- data/test/unit/runner_tests.rb +33 -18
- data/test/unit/suite_tests.rb +39 -15
- data/test/unit/test_tests.rb +65 -50
- data/test/unit/utils_tests.rb +52 -37
- data/test/unit/view_helpers_tests.rb +23 -14
- data/test/unit/view_tests.rb +7 -5
- metadata +26 -11
- data/test/unit/assertions/assert_kind_of_tests.rb +0 -66
data/test/unit/test_tests.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/test"
|
3
5
|
|
@@ -8,14 +10,16 @@ require "assert/result"
|
|
8
10
|
class Assert::Test
|
9
11
|
class UnitTests < Assert::Context
|
10
12
|
desc "Assert::Test"
|
11
|
-
subject
|
13
|
+
subject{ unit_class }
|
12
14
|
|
13
|
-
let(:unit_class)
|
15
|
+
let(:unit_class){ Assert::Test }
|
14
16
|
|
15
|
-
let(:context_class1)
|
16
|
-
|
17
|
-
|
18
|
-
let(:
|
17
|
+
let(:context_class1) do
|
18
|
+
Factory.modes_off_context_class{ desc "context class" }
|
19
|
+
end
|
20
|
+
let(:context_info1){ Factory.context_info(context_class1) }
|
21
|
+
let(:config1){ Factory.modes_off_config }
|
22
|
+
let(:test_code1){ proc{ assert(true) } }
|
19
23
|
|
20
24
|
should have_imeths :name_file_line_context_data, :for_block
|
21
25
|
|
@@ -48,24 +52,26 @@ class Assert::Test
|
|
48
52
|
|
49
53
|
class InitWithDataTests < UnitTests
|
50
54
|
desc "when init with data"
|
51
|
-
subject
|
55
|
+
subject{ unit_class.new(meta_data1.merge(run_data1)) }
|
52
56
|
|
53
|
-
let(:file_line1)
|
54
|
-
|
57
|
+
let(:file_line1) do
|
58
|
+
Assert::FileLine.new(Factory.string, Factory.integer.to_s)
|
59
|
+
end
|
60
|
+
let(:meta_data1) do
|
55
61
|
{
|
56
|
-
:
|
57
|
-
:
|
58
|
-
:
|
59
|
-
:
|
62
|
+
file_line: file_line1.to_s,
|
63
|
+
name: Factory.string,
|
64
|
+
output: Factory.string,
|
65
|
+
run_time: Factory.float(1.0),
|
60
66
|
}
|
61
|
-
|
62
|
-
let(:run_data1)
|
67
|
+
end
|
68
|
+
let(:run_data1) do
|
63
69
|
{
|
64
|
-
:
|
65
|
-
:
|
66
|
-
:
|
70
|
+
context_info: context_info1,
|
71
|
+
config: config1,
|
72
|
+
code: test_code1,
|
67
73
|
}
|
68
|
-
|
74
|
+
end
|
69
75
|
|
70
76
|
should have_imeths :file_line, :file_name, :line_num
|
71
77
|
should have_imeths :name, :output, :run_time
|
@@ -105,9 +111,12 @@ class Assert::Test
|
|
105
111
|
end
|
106
112
|
|
107
113
|
should "have a custom inspect that only shows limited attributes" do
|
108
|
-
attrs =
|
109
|
-
|
110
|
-
|
114
|
+
attrs =
|
115
|
+
[:name, :context_info]
|
116
|
+
.map{ |method|
|
117
|
+
"@#{method}=#{subject.send(method).inspect}"
|
118
|
+
}
|
119
|
+
.join(" ")
|
111
120
|
exp = "#<#{subject.class}:#{"0x0%x" % (subject.object_id << 1)} #{attrs}>"
|
112
121
|
assert_that(subject.inspect).equals(exp)
|
113
122
|
end
|
@@ -116,13 +125,13 @@ class Assert::Test
|
|
116
125
|
class PassFailIgnoreHandlingTests < UnitTests
|
117
126
|
include Assert::Test::TestHelpers
|
118
127
|
|
119
|
-
subject
|
128
|
+
subject do
|
120
129
|
Factory.test("pass fail ignore test", context_info1) do
|
121
130
|
ignore("something")
|
122
131
|
assert(true)
|
123
132
|
assert(false)
|
124
133
|
end
|
125
|
-
|
134
|
+
end
|
126
135
|
|
127
136
|
setup do
|
128
137
|
subject.context_class.setup do
|
@@ -182,7 +191,7 @@ class Assert::Test
|
|
182
191
|
end
|
183
192
|
|
184
193
|
should "capture fails in the context setup" do
|
185
|
-
test = Factory.test("setup halt-on-fail test", context_info1){
|
194
|
+
test = Factory.test("setup halt-on-fail test", context_info1){}
|
186
195
|
test.context_class.setup{ raise Assert::Result::TestFailure }
|
187
196
|
test.run(&test_run_callback)
|
188
197
|
|
@@ -190,7 +199,7 @@ class Assert::Test
|
|
190
199
|
end
|
191
200
|
|
192
201
|
should "capture fails in the context teardown" do
|
193
|
-
test = Factory.test("teardown halt-on-fail test", context_info1){
|
202
|
+
test = Factory.test("teardown halt-on-fail test", context_info1){}
|
194
203
|
test.context_class.teardown{ raise Assert::Result::TestFailure }
|
195
204
|
test.run(&test_run_callback)
|
196
205
|
|
@@ -199,11 +208,13 @@ class Assert::Test
|
|
199
208
|
|
200
209
|
private
|
201
210
|
|
202
|
-
def assert_failed(
|
211
|
+
def assert_failed(_test)
|
203
212
|
with_backtrace(caller) do
|
204
|
-
assert_that(test_run_result_count)
|
213
|
+
assert_that(test_run_result_count)
|
214
|
+
.equals(1, "too many/few fail results")
|
205
215
|
test_run_results.each do |result|
|
206
|
-
assert_that(result)
|
216
|
+
assert_that(result)
|
217
|
+
.is_kind_of(Assert::Result::Fail, "not a fail result")
|
207
218
|
end
|
208
219
|
end
|
209
220
|
end
|
@@ -220,7 +231,7 @@ class Assert::Test
|
|
220
231
|
end
|
221
232
|
|
222
233
|
should "capture skips in the context setup" do
|
223
|
-
test = Factory.test("setup skip test", context_info1){
|
234
|
+
test = Factory.test("setup skip test", context_info1){}
|
224
235
|
test.context_class.setup{ skip }
|
225
236
|
test.run(&test_run_callback)
|
226
237
|
|
@@ -228,7 +239,7 @@ class Assert::Test
|
|
228
239
|
end
|
229
240
|
|
230
241
|
should "capture skips in the context teardown" do
|
231
|
-
test = Factory.test("teardown skip test", context_info1){
|
242
|
+
test = Factory.test("teardown skip test", context_info1){}
|
232
243
|
test.context_class.teardown{ skip }
|
233
244
|
test.run(&test_run_callback)
|
234
245
|
|
@@ -237,11 +248,13 @@ class Assert::Test
|
|
237
248
|
|
238
249
|
private
|
239
250
|
|
240
|
-
def assert_skipped(
|
251
|
+
def assert_skipped(_test)
|
241
252
|
with_backtrace(caller) do
|
242
|
-
assert_that(test_run_result_count)
|
253
|
+
assert_that(test_run_result_count)
|
254
|
+
.equals(1, "too many/few skip results")
|
243
255
|
test_run_results.each do |result|
|
244
|
-
assert_that(result)
|
256
|
+
assert_that(result)
|
257
|
+
.is_kind_of(Assert::Result::Skip, "not a skip result")
|
245
258
|
end
|
246
259
|
end
|
247
260
|
end
|
@@ -260,7 +273,7 @@ class Assert::Test
|
|
260
273
|
end
|
261
274
|
|
262
275
|
should "capture errors in the context setup" do
|
263
|
-
test = Factory.test("setup error test", context_info1){
|
276
|
+
test = Factory.test("setup error test", context_info1){}
|
264
277
|
test.context_class.setup{ raise "an error" }
|
265
278
|
test.run(&test_run_callback)
|
266
279
|
|
@@ -268,7 +281,7 @@ class Assert::Test
|
|
268
281
|
end
|
269
282
|
|
270
283
|
should "capture errors in the context teardown" do
|
271
|
-
test = Factory.test("teardown error test", context_info1){
|
284
|
+
test = Factory.test("teardown error test", context_info1){}
|
272
285
|
test.context_class.teardown{ raise "an error" }
|
273
286
|
test.run(&test_run_callback)
|
274
287
|
|
@@ -277,11 +290,13 @@ class Assert::Test
|
|
277
290
|
|
278
291
|
private
|
279
292
|
|
280
|
-
def assert_errored(
|
293
|
+
def assert_errored(_test)
|
281
294
|
with_backtrace(caller) do
|
282
|
-
assert_that(test_run_result_count)
|
295
|
+
assert_that(test_run_result_count)
|
296
|
+
.equals(1, "too many/few error results")
|
283
297
|
test_run_results.each do |result|
|
284
|
-
assert_that(result)
|
298
|
+
assert_that(result)
|
299
|
+
.is_kind_of(Assert::Result::Error, "not an error result")
|
285
300
|
end
|
286
301
|
end
|
287
302
|
end
|
@@ -293,27 +308,27 @@ class Assert::Test
|
|
293
308
|
raise SignalException, "USR1"
|
294
309
|
end
|
295
310
|
|
296
|
-
assert_that
|
311
|
+
assert_that{ test.run }.raises(SignalException)
|
297
312
|
end
|
298
313
|
|
299
314
|
should "raises signal exceptions in the context setup" do
|
300
|
-
test = Factory.test("setup signal test", context_info1){
|
315
|
+
test = Factory.test("setup signal test", context_info1){}
|
301
316
|
test.context_class.setup{ raise SignalException, "INT" }
|
302
317
|
|
303
|
-
assert_that
|
318
|
+
assert_that{ test.run }.raises(SignalException)
|
304
319
|
end
|
305
320
|
|
306
321
|
should "raises signal exceptions in the context teardown" do
|
307
|
-
test = Factory.test("teardown signal test", context_info1){
|
322
|
+
test = Factory.test("teardown signal test", context_info1){}
|
308
323
|
test.context_class.teardown{ raise SignalException, "TERM" }
|
309
324
|
|
310
|
-
assert_that
|
325
|
+
assert_that{ test.run }.raises(SignalException)
|
311
326
|
end
|
312
327
|
end
|
313
328
|
|
314
329
|
class ComparingTests < UnitTests
|
315
330
|
desc "<=> another test"
|
316
|
-
subject
|
331
|
+
subject{ Factory.test("mmm") }
|
317
332
|
|
318
333
|
should "return 1 with a test named 'aaa' (greater than it)" do
|
319
334
|
assert_that(subject <=> Factory.test("aaa")).equals(1)
|
@@ -330,14 +345,14 @@ class Assert::Test
|
|
330
345
|
|
331
346
|
class CaptureOutTests < UnitTests
|
332
347
|
desc "when capturing std out"
|
333
|
-
subject
|
348
|
+
subject do
|
334
349
|
Factory.test("stdout", capture_config1) do
|
335
350
|
puts "std out from the test"
|
336
351
|
assert true
|
337
352
|
end
|
338
|
-
|
353
|
+
end
|
339
354
|
|
340
|
-
let(:capture_config1)
|
355
|
+
let(:capture_config1){ Assert::Config.new(capture_output: true) }
|
341
356
|
|
342
357
|
should "capture any io from the test" do
|
343
358
|
subject.run
|
@@ -347,12 +362,12 @@ class Assert::Test
|
|
347
362
|
|
348
363
|
class FullCaptureOutTests < CaptureOutTests
|
349
364
|
desc "across setup, teardown, and meth calls"
|
350
|
-
subject
|
365
|
+
subject do
|
351
366
|
Factory.test("fullstdouttest", capture_config1) do
|
352
367
|
puts "std out from the test"
|
353
368
|
assert a_method_an_assert_calls
|
354
369
|
end
|
355
|
-
|
370
|
+
end
|
356
371
|
|
357
372
|
setup do
|
358
373
|
subject.context_class.setup{ puts "std out from the setup" }
|
data/test/unit/utils_tests.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/utils"
|
3
5
|
|
@@ -7,37 +9,40 @@ require "assert/config"
|
|
7
9
|
module Assert::Utils
|
8
10
|
class UnitTests < Assert::Context
|
9
11
|
desc "Assert::Utils"
|
10
|
-
subject
|
12
|
+
subject{ unit_class }
|
11
13
|
|
12
|
-
let(:unit_class)
|
14
|
+
let(:unit_class){ Assert::Utils }
|
13
15
|
|
14
|
-
let(:objs1)
|
16
|
+
let(:objs1){ [1, "hi there", {}, [:a, :b]] }
|
15
17
|
|
16
18
|
should have_imeths :show, :show_for_diff
|
17
19
|
should have_imeths :tempfile
|
18
|
-
should have_imeths :stdlib_pp_proc, :default_use_diff_proc
|
20
|
+
should have_imeths :stdlib_pp_proc, :default_use_diff_proc
|
21
|
+
should have_imeths :syscmd_diff_proc
|
19
22
|
should have_imeths :git_changed_proc
|
20
23
|
end
|
21
24
|
|
22
25
|
class ShowTests < UnitTests
|
23
26
|
desc "`show`"
|
24
27
|
|
25
|
-
let(:pp_config1)
|
28
|
+
let(:pp_config1) do
|
26
29
|
Assert::Config.new({
|
27
|
-
:
|
28
|
-
:
|
30
|
+
pp_objects: true,
|
31
|
+
pp_proc: Proc.new{ |_input| "herp derp" },
|
29
32
|
})
|
30
|
-
|
33
|
+
end
|
31
34
|
|
32
35
|
should "use `inspect` to show objs when `pp_objects` setting is false" do
|
33
36
|
objs1.each do |obj|
|
34
|
-
assert_that(subject.show(obj, Factory.modes_off_config))
|
37
|
+
assert_that(subject.show(obj, Factory.modes_off_config))
|
38
|
+
.equals(obj.inspect)
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
42
|
should "use `pp_proc` to show objs when `pp_objects` setting is true" do
|
39
43
|
objs1.each do |obj|
|
40
|
-
assert_that(subject.show(obj, pp_config1))
|
44
|
+
assert_that(subject.show(obj, pp_config1))
|
45
|
+
.equals(pp_config1.pp_proc.call(obj))
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
@@ -45,24 +50,27 @@ module Assert::Utils
|
|
45
50
|
class ShowForDiffTests < ShowTests
|
46
51
|
desc "`show_for_diff`"
|
47
52
|
|
48
|
-
let(:w_newlines1)
|
49
|
-
let(:w_obj_id1)
|
53
|
+
let(:w_newlines1){ { string: "herp derp, derp herp\nherpderpedia" } }
|
54
|
+
let(:w_obj_id1){ Class.new.new }
|
50
55
|
|
51
56
|
should "call show, escaping newlines" do
|
52
57
|
exp_out = "{:string=>\"herp derp, derp herp\nherpderpedia\"}"
|
53
|
-
assert_that(subject.show_for_diff(w_newlines1, Factory.modes_off_config))
|
58
|
+
assert_that(subject.show_for_diff(w_newlines1, Factory.modes_off_config))
|
59
|
+
.equals(exp_out)
|
54
60
|
end
|
55
61
|
|
56
62
|
should "make any obj ids generic" do
|
57
63
|
exp_out = "#<#<Class:0xXXXXXX>:0xXXXXXX>"
|
58
|
-
assert_that(subject.show_for_diff(w_obj_id1, Factory.modes_off_config))
|
64
|
+
assert_that(subject.show_for_diff(w_obj_id1, Factory.modes_off_config))
|
65
|
+
.equals(exp_out)
|
59
66
|
end
|
60
67
|
end
|
61
68
|
|
62
69
|
class TempfileTests < UnitTests
|
63
70
|
desc "`tempfile`"
|
64
71
|
|
65
|
-
should "require tempfile, open a tempfile, write the given content,
|
72
|
+
should "require tempfile, open a tempfile, write the given content, "\
|
73
|
+
"and yield it" do
|
66
74
|
subject.tempfile("a-name", "some-content") do |tmpfile|
|
67
75
|
assert_that((require "tempfile")).equals(false)
|
68
76
|
assert tmpfile
|
@@ -78,12 +86,12 @@ module Assert::Utils
|
|
78
86
|
desc "`stdlib_pp_proc`"
|
79
87
|
|
80
88
|
should "build a pp proc that uses stdlib `PP.pp` to pretty print objects" do
|
81
|
-
exp_obj_pps = objs1.map{ |o| PP.pp(o, "", 79).strip }
|
89
|
+
exp_obj_pps = objs1.map{ |o| PP.pp(o, +"", 79).strip }
|
82
90
|
act_obj_pps = objs1.map{ |o| subject.stdlib_pp_proc.call(o) }
|
83
91
|
assert_that(act_obj_pps).equals(exp_obj_pps)
|
84
92
|
|
85
93
|
cust_width = 1
|
86
|
-
exp_obj_pps = objs1.map{ |o| PP.pp(o, "", cust_width).strip }
|
94
|
+
exp_obj_pps = objs1.map{ |o| PP.pp(o, +"", cust_width).strip }
|
87
95
|
act_obj_pps = objs1.map{ |o| subject.stdlib_pp_proc(cust_width).call(o) }
|
88
96
|
assert_that(act_obj_pps).equals(exp_obj_pps)
|
89
97
|
end
|
@@ -92,8 +100,10 @@ module Assert::Utils
|
|
92
100
|
class DefaultUseDiffProcTests < UnitTests
|
93
101
|
desc "`default_use_diff_proc`"
|
94
102
|
|
95
|
-
let(:longer1)
|
96
|
-
|
103
|
+
let(:longer1) do
|
104
|
+
"i am a really long string output; use diff when working with me"
|
105
|
+
end
|
106
|
+
let(:newlines1){ "i have\n newlines" }
|
97
107
|
|
98
108
|
should "be true if either output has newlines or is bigger than 29 chars" do
|
99
109
|
proc = subject.default_use_diff_proc
|
@@ -110,28 +120,33 @@ module Assert::Utils
|
|
110
120
|
class SyscmdDiffProc < UnitTests
|
111
121
|
desc "`syscmd_diff_proc`"
|
112
122
|
|
113
|
-
let(:diff_a_file1)
|
114
|
-
let(:diff_b_file1)
|
115
|
-
let(:diff_a1)
|
116
|
-
let(:diff_b1)
|
117
|
-
|
118
|
-
should "use the diff syscmd to output the diff between the exp/act
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
123
|
+
let(:diff_a_file1){ File.join(ROOT_PATH, "test/support/diff_a.txt") }
|
124
|
+
let(:diff_b_file1){ File.join(ROOT_PATH, "test/support/diff_b.txt") }
|
125
|
+
let(:diff_a1){ File.read(diff_a_file1) }
|
126
|
+
let(:diff_b1){ File.read(diff_b_file1) }
|
127
|
+
|
128
|
+
should "use the diff syscmd to output the diff between the exp/act "\
|
129
|
+
"show output" do
|
130
|
+
exp_diff_out =
|
131
|
+
`diff --unified=-1 #{diff_a_file1} #{diff_b_file1}`.strip.tap do |out|
|
132
|
+
out.sub!(/^\-\-\- .+/, "--- expected")
|
133
|
+
out.sub!(/^\+\+\+ .+/, "+++ actual")
|
134
|
+
end
|
135
|
+
|
136
|
+
assert_that(subject.syscmd_diff_proc.call(diff_a1, diff_b1))
|
137
|
+
.equals(exp_diff_out)
|
125
138
|
end
|
126
139
|
|
127
140
|
should "allow you to specify a custom syscmd" do
|
128
141
|
cust_syscmd = "diff"
|
129
|
-
exp_diff_out =
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
142
|
+
exp_diff_out =
|
143
|
+
`#{cust_syscmd} #{diff_a_file1} #{diff_b_file1}`.strip.tap do |out|
|
144
|
+
out.sub!(/^\-\-\- .+/, "--- expected")
|
145
|
+
out.sub!(/^\+\+\+ .+/, "+++ actual")
|
146
|
+
end
|
147
|
+
|
148
|
+
assert_that(subject.syscmd_diff_proc(cust_syscmd).call(diff_a1, diff_b1))
|
149
|
+
.equals(exp_diff_out)
|
135
150
|
end
|
136
151
|
end
|
137
152
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/view_helpers"
|
3
5
|
|
@@ -10,9 +12,9 @@ require "assert/view"
|
|
10
12
|
module Assert::ViewHelpers
|
11
13
|
class UnitTests < Assert::Context
|
12
14
|
desc "Assert::ViewHelpers"
|
13
|
-
subject
|
15
|
+
subject{ unit_class }
|
14
16
|
|
15
|
-
let(:unit_class)
|
17
|
+
let(:unit_class) do
|
16
18
|
test_opt_val = test_opt_val1
|
17
19
|
Class.new do
|
18
20
|
include Assert::ViewHelpers
|
@@ -25,9 +27,9 @@ module Assert::ViewHelpers
|
|
25
27
|
@config ||= [Assert.config, Assert::Config.new].sample
|
26
28
|
end
|
27
29
|
end
|
28
|
-
|
30
|
+
end
|
29
31
|
|
30
|
-
let(:test_opt_val1)
|
32
|
+
let(:test_opt_val1){ Factory.string }
|
31
33
|
|
32
34
|
should have_imeths :option
|
33
35
|
|
@@ -51,7 +53,7 @@ module Assert::ViewHelpers
|
|
51
53
|
|
52
54
|
class InitTests < UnitTests
|
53
55
|
desc "when init"
|
54
|
-
subject
|
56
|
+
subject{ unit_class.new }
|
55
57
|
|
56
58
|
should have_imeths :captured_output, :re_run_test_cmd
|
57
59
|
should have_imeths :tests_to_run_count_statement, :result_count_statement
|
@@ -75,7 +77,9 @@ module Assert::ViewHelpers
|
|
75
77
|
end
|
76
78
|
|
77
79
|
should "know its tests-to-run count and result count statements" do
|
78
|
-
exp =
|
80
|
+
exp =
|
81
|
+
"#{subject.tests_to_run_count} "\
|
82
|
+
"test#{"s" if subject.tests_to_run_count != 1}"
|
79
83
|
assert_that(subject.tests_to_run_count_statement).equals(exp)
|
80
84
|
|
81
85
|
exp = "#{subject.result_count} result#{"s" if subject.result_count != 1}"
|
@@ -89,7 +93,7 @@ module Assert::ViewHelpers
|
|
89
93
|
items = 2.times.map{ Factory.string }
|
90
94
|
assert_that(subject.to_sentence(items)).equals(items.join(" and "))
|
91
95
|
|
92
|
-
items = (Factory.integer(3)+2).times.map{ Factory.string }
|
96
|
+
items = (Factory.integer(3) + 2).times.map{ Factory.string }
|
93
97
|
exp = [items[0..-2].join(", "), items.last].join(", and ")
|
94
98
|
assert_that(subject.to_sentence(items)).equals(exp)
|
95
99
|
end
|
@@ -101,7 +105,7 @@ module Assert::ViewHelpers
|
|
101
105
|
Assert.stub(subject, :result_count){ 1 }
|
102
106
|
assert_that(subject.all_pass_result_summary_msg).equals("pass")
|
103
107
|
|
104
|
-
Assert.stub(subject, :result_count){ Factory.integer(10)+1 }
|
108
|
+
Assert.stub(subject, :result_count){ Factory.integer(10) + 1 }
|
105
109
|
assert_that(subject.all_pass_result_summary_msg).equals("all pass")
|
106
110
|
end
|
107
111
|
|
@@ -113,7 +117,7 @@ module Assert::ViewHelpers
|
|
113
117
|
|
114
118
|
Assert.stub(subject, :all_pass?){ false }
|
115
119
|
res_type = [:pass, :ignore, :fail, :skip, :error].sample
|
116
|
-
exp = "#{subject.send("#{res_type}_result_count")} #{res_type
|
120
|
+
exp = "#{subject.send("#{res_type}_result_count")} #{res_type}"
|
117
121
|
assert_that(subject.result_summary_msg(res_type)).equals(exp)
|
118
122
|
end
|
119
123
|
|
@@ -137,7 +141,7 @@ module Assert::ViewHelpers
|
|
137
141
|
|
138
142
|
class AnsiTests < UnitTests
|
139
143
|
desc "Ansi"
|
140
|
-
subject
|
144
|
+
subject{ Ansi }
|
141
145
|
|
142
146
|
should have_imeths :code_for
|
143
147
|
|
@@ -160,10 +164,12 @@ module Assert::ViewHelpers
|
|
160
164
|
|
161
165
|
class AnsiInitTests < UnitTests
|
162
166
|
desc "when mixed in on a view"
|
163
|
-
subject
|
167
|
+
subject{ view1 }
|
164
168
|
|
165
|
-
let(:view_class1)
|
166
|
-
let(:view1)
|
169
|
+
let(:view_class1){ Class.new(Assert::View){ include Ansi } }
|
170
|
+
let(:view1) do
|
171
|
+
view_class1.new(Factory.modes_off_config, StringIO.new(+"", "w+"))
|
172
|
+
end
|
167
173
|
|
168
174
|
should have_imeths :ansi_styled_msg
|
169
175
|
|
@@ -188,7 +194,10 @@ module Assert::ViewHelpers
|
|
188
194
|
Assert.stub(subject, "#{result_type}_styles"){ [] }
|
189
195
|
assert_that(subject.ansi_styled_msg(msg, result_type)).equals(msg)
|
190
196
|
|
191
|
-
styles =
|
197
|
+
styles =
|
198
|
+
Factory.integer(3).times.map do
|
199
|
+
Assert::ViewHelpers::Ansi::CODES.keys.sample
|
200
|
+
end
|
192
201
|
Assert.stub(subject, "#{result_type}_styles"){ styles }
|
193
202
|
exp_code = Assert::ViewHelpers::Ansi.code_for(*styles)
|
194
203
|
exp = exp_code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
|