assert 2.18.4 → 2.19.4
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 -5
- data/bin/assert +1 -0
- data/lib/assert.rb +20 -6
- data/lib/assert/actual_value.rb +26 -8
- data/lib/assert/assert_runner.rb +38 -17
- data/lib/assert/assertions.rb +145 -41
- data/lib/assert/cli.rb +19 -66
- 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 +28 -47
- 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 +117 -61
- data/lib/assert/runner.rb +70 -51
- data/lib/assert/stub.rb +44 -3
- data/lib/assert/suite.rb +76 -38
- data/lib/assert/test.rb +43 -44
- 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 +103 -46
- data/test/unit/assert_tests.rb +48 -40
- data/test/unit/assertions/assert_block_tests.rb +12 -10
- data/test/unit/assertions/assert_changes_tests.rb +103 -0
- data/test/unit/assertions/assert_empty_tests.rb +16 -12
- data/test/unit/assertions/assert_equal_tests.rb +46 -24
- 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 +34 -23
- 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 +25 -17
- data/test/unit/config_helpers_tests.rb +15 -8
- 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 +43 -19
- 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 +42 -24
- data/test/unit/test_tests.rb +66 -73
- 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 +40 -9
- data/test/unit/assertions/assert_kind_of_tests.rb +0 -66
data/lib/assert/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
|
3
5
|
module Assert
|
@@ -10,18 +12,21 @@ module Assert
|
|
10
12
|
out
|
11
13
|
end
|
12
14
|
|
13
|
-
# show objects in a human-readable manner and make the output diff-able.
|
14
|
-
# expands on the basic `show` util by escaping newlines and making
|
15
|
-
# hex-values generic.
|
15
|
+
# show objects in a human-readable manner and make the output diff-able.
|
16
|
+
# This expands on the basic `show` util by escaping newlines and making
|
17
|
+
# object id hex-values generic.
|
16
18
|
def self.show_for_diff(obj, config)
|
17
|
-
show(obj, config)
|
19
|
+
show(obj, config)
|
20
|
+
.gsub(/\\n/, "\n")
|
21
|
+
.gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX")
|
18
22
|
end
|
19
23
|
|
20
24
|
# open a tempfile and yield it
|
21
25
|
def self.tempfile(name, content)
|
22
26
|
require "tempfile"
|
23
27
|
Tempfile.open(name) do |tmpfile|
|
24
|
-
tmpfile.puts(content)
|
28
|
+
tmpfile.puts(content)
|
29
|
+
tmpfile.flush
|
25
30
|
yield tmpfile if block_given?
|
26
31
|
end
|
27
32
|
end
|
@@ -29,10 +34,11 @@ module Assert
|
|
29
34
|
# Get a proc that uses stdlib `PP.pp` to pretty print objects
|
30
35
|
def self.stdlib_pp_proc(width = nil)
|
31
36
|
require "pp"
|
32
|
-
Proc.new{ |obj| PP.pp(obj, "", width || 79).strip }
|
37
|
+
Proc.new{ |obj| PP.pp(obj, +"", width || 79).strip }
|
33
38
|
end
|
34
39
|
|
35
|
-
# Return true if if either show output has newlines or is bigger than 29
|
40
|
+
# Return true if if either show output has newlines or is bigger than 29
|
41
|
+
# chars.
|
36
42
|
def self.default_use_diff_proc
|
37
43
|
Proc.new do |exp_show_output, act_show_output|
|
38
44
|
exp_show_output.include?("\n") || exp_show_output.size > 29 ||
|
@@ -60,10 +66,15 @@ module Assert
|
|
60
66
|
def self.git_changed_proc
|
61
67
|
Proc.new do |config, test_paths|
|
62
68
|
files = []
|
63
|
-
cmd =
|
64
|
-
|
65
|
-
|
66
|
-
|
69
|
+
cmd =
|
70
|
+
[
|
71
|
+
# changed files
|
72
|
+
"git diff --no-ext-diff --name-only #{config.changed_ref}",
|
73
|
+
# added files
|
74
|
+
"git ls-files --others --exclude-standard",
|
75
|
+
]
|
76
|
+
.map{ |c| "#{c} -- #{test_paths.join(" ")}" }
|
77
|
+
.join(" && ")
|
67
78
|
Assert::CLI.bench("Load only changed files") do
|
68
79
|
files = `#{cmd}`.split("\n")
|
69
80
|
end
|
data/lib/assert/version.rb
CHANGED
data/lib/assert/view.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert/config"
|
2
4
|
require "assert/config_helpers"
|
3
5
|
require "assert/suite"
|
@@ -14,16 +16,18 @@ module Assert
|
|
14
16
|
|
15
17
|
def self.require_user_view(view_name)
|
16
18
|
views_file = File.expand_path(
|
17
|
-
File.join("#{ENV["HOME"]}/.assert/views", view_name, "lib", view_name)
|
19
|
+
File.join("#{ENV["HOME"]}/.assert/views", view_name, "lib", view_name),
|
18
20
|
)
|
19
21
|
|
20
|
-
if File.
|
22
|
+
if File.exist?(view_name) || File.exist?(view_name + ".rb")
|
21
23
|
require view_name
|
22
|
-
elsif File.
|
24
|
+
elsif File.exist?(views_file + ".rb")
|
23
25
|
require views_file
|
24
26
|
else
|
25
|
-
msg = "[WARN] Can't find or require #{view_name.inspect} view."
|
26
|
-
|
27
|
+
msg = +"[WARN] Can't find or require #{view_name.inspect} view."
|
28
|
+
unless view_name.match(%r{\A/})
|
29
|
+
msg << " Did you install it in `~/.assert/views`?"
|
30
|
+
end
|
27
31
|
warn msg
|
28
32
|
end
|
29
33
|
end
|
@@ -46,11 +50,13 @@ module Assert
|
|
46
50
|
attr_reader :config
|
47
51
|
|
48
52
|
def initialize(config, output_io)
|
49
|
-
@config
|
53
|
+
@config, @output_io, = config, output_io
|
50
54
|
@output_io.sync = true if @output_io.respond_to?(:sync=)
|
51
55
|
end
|
52
56
|
|
53
|
-
def view
|
57
|
+
def view
|
58
|
+
self
|
59
|
+
end
|
54
60
|
|
55
61
|
def is_tty?
|
56
62
|
!!@output_io.isatty
|
@@ -77,19 +83,41 @@ module Assert
|
|
77
83
|
# the test suite
|
78
84
|
# * `on_interrupt`: called when the test suite is interrupted while running
|
79
85
|
# the interrupt exception is passed as an arg
|
80
|
-
def before_load(test_files)
|
81
|
-
|
82
|
-
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
def
|
87
|
-
|
88
|
-
|
86
|
+
def before_load(test_files)
|
87
|
+
end
|
88
|
+
|
89
|
+
def after_load
|
90
|
+
end
|
91
|
+
|
92
|
+
def on_start
|
93
|
+
end
|
94
|
+
|
95
|
+
def before_test(test)
|
96
|
+
end
|
97
|
+
|
98
|
+
def on_result(result)
|
99
|
+
end
|
100
|
+
|
101
|
+
def after_test(test)
|
102
|
+
end
|
103
|
+
|
104
|
+
def on_finish
|
105
|
+
end
|
106
|
+
|
107
|
+
def on_info(test)
|
108
|
+
end
|
109
|
+
|
110
|
+
def on_interrupt(err)
|
111
|
+
end
|
89
112
|
|
90
113
|
# IO capture
|
91
114
|
|
92
|
-
def puts(*args)
|
93
|
-
|
115
|
+
def puts(*args)
|
116
|
+
@output_io.puts(*args)
|
117
|
+
end
|
118
|
+
|
119
|
+
def print(*args)
|
120
|
+
@output_io.print(*args)
|
121
|
+
end
|
94
122
|
end
|
95
123
|
end
|
data/lib/assert/view_helpers.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert/config_helpers"
|
2
4
|
|
3
5
|
module Assert
|
@@ -14,7 +16,7 @@ module Assert
|
|
14
16
|
def option(name, *default_vals)
|
15
17
|
default = default_vals.size > 1 ? default_vals : default_vals.first
|
16
18
|
define_method(name) do |*args|
|
17
|
-
|
19
|
+
unless (value = args.size > 1 ? args : args.first).nil?
|
18
20
|
instance_variable_set("@#{name}", value)
|
19
21
|
end
|
20
22
|
(val = instance_variable_get("@#{name}")).nil? ? default : val
|
@@ -36,11 +38,11 @@ module Assert
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def tests_to_run_count_statement
|
39
|
-
"#{
|
41
|
+
"#{tests_to_run_count} test#{"s" if tests_to_run_count != 1}"
|
40
42
|
end
|
41
43
|
|
42
44
|
def result_count_statement
|
43
|
-
"#{
|
45
|
+
"#{result_count} result#{"s" if result_count != 1}"
|
44
46
|
end
|
45
47
|
|
46
48
|
# generate a comma-seperated sentence fragment given a list of items
|
@@ -54,9 +56,9 @@ module Assert
|
|
54
56
|
|
55
57
|
# generate an appropriate result summary msg for all tests passing
|
56
58
|
def all_pass_result_summary_msg
|
57
|
-
if
|
59
|
+
if result_count < 1
|
58
60
|
"uhh..."
|
59
|
-
elsif
|
61
|
+
elsif result_count == 1
|
60
62
|
"pass"
|
61
63
|
else
|
62
64
|
"all pass"
|
@@ -65,112 +67,120 @@ module Assert
|
|
65
67
|
|
66
68
|
# print a result summary message for a given result type
|
67
69
|
def result_summary_msg(result_type)
|
68
|
-
if result_type == :pass &&
|
69
|
-
|
70
|
+
if result_type == :pass && all_pass?
|
71
|
+
all_pass_result_summary_msg
|
70
72
|
else
|
71
|
-
"#{
|
73
|
+
"#{send("#{result_type}_result_count")} #{result_type}"
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
75
77
|
# generate a sentence fragment describing the breakdown of test results
|
76
|
-
# if a block is given, yield each msg in the breakdown for custom
|
78
|
+
# if a block is given, yield each msg in the breakdown for custom
|
79
|
+
# formatting.
|
77
80
|
def results_summary_sentence
|
78
|
-
summaries =
|
79
|
-
summary_msg =
|
81
|
+
summaries = ocurring_result_types.map do |result_type|
|
82
|
+
summary_msg = result_summary_msg(result_type)
|
80
83
|
block_given? ? yield(summary_msg, result_type) : summary_msg
|
81
84
|
end
|
82
|
-
|
85
|
+
to_sentence(summaries)
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
86
89
|
module Ansi
|
87
|
-
# Table of supported styles/codes
|
90
|
+
# Table of supported styles/codes
|
91
|
+
# (http://en.wikipedia.org/wiki/ANSI_escape_code).
|
88
92
|
CODES = {
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
94
|
-
:
|
95
|
-
:
|
96
|
-
:
|
97
|
-
:
|
98
|
-
:
|
99
|
-
:
|
100
|
-
:
|
101
|
-
:
|
102
|
-
:
|
103
|
-
:
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
:
|
111
|
-
|
112
|
-
:
|
113
|
-
:
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
117
|
-
:
|
118
|
-
:
|
119
|
-
:
|
120
|
-
:
|
121
|
-
:
|
122
|
-
:
|
123
|
-
:
|
124
|
-
:
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
135
|
-
:
|
136
|
-
:
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
140
|
-
|
141
|
-
:
|
142
|
-
:
|
143
|
-
:
|
144
|
-
:
|
145
|
-
:
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
|
150
|
-
:
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
154
|
-
:
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
|
159
|
-
:
|
160
|
-
:
|
161
|
-
:
|
162
|
-
:
|
163
|
-
:
|
164
|
-
:
|
93
|
+
clear: 0,
|
94
|
+
reset: 0,
|
95
|
+
bright: 1,
|
96
|
+
bold: 1,
|
97
|
+
faint: 2,
|
98
|
+
dark: 2,
|
99
|
+
italic: 3,
|
100
|
+
underline: 4,
|
101
|
+
underscore: 4,
|
102
|
+
blink: 5,
|
103
|
+
slow_blink: 5,
|
104
|
+
rapid: 6,
|
105
|
+
rapid_blink: 6,
|
106
|
+
invert: 7,
|
107
|
+
inverse: 7,
|
108
|
+
reverse: 7,
|
109
|
+
negative: 7,
|
110
|
+
swap: 7,
|
111
|
+
conceal: 8,
|
112
|
+
concealed: 8,
|
113
|
+
hide: 9,
|
114
|
+
strike: 9,
|
115
|
+
|
116
|
+
default_font: 10,
|
117
|
+
font_default: 10,
|
118
|
+
font0: 10,
|
119
|
+
font1: 11,
|
120
|
+
font2: 12,
|
121
|
+
font3: 13,
|
122
|
+
font4: 14,
|
123
|
+
font5: 15,
|
124
|
+
font6: 16,
|
125
|
+
font7: 17,
|
126
|
+
font8: 18,
|
127
|
+
font9: 19,
|
128
|
+
fraktur: 20,
|
129
|
+
bright_off: 21,
|
130
|
+
bold_off: 21,
|
131
|
+
double_underline: 21,
|
132
|
+
clean: 22,
|
133
|
+
italic_off: 23,
|
134
|
+
fraktur_off: 23,
|
135
|
+
underline_off: 24,
|
136
|
+
blink_off: 25,
|
137
|
+
inverse_off: 26,
|
138
|
+
positive: 26,
|
139
|
+
conceal_off: 27,
|
140
|
+
show: 27,
|
141
|
+
reveal: 27,
|
142
|
+
crossed_off: 29,
|
143
|
+
crossed_out_off: 29,
|
144
|
+
|
145
|
+
black: 30,
|
146
|
+
red: 31,
|
147
|
+
green: 32,
|
148
|
+
yellow: 33,
|
149
|
+
blue: 34,
|
150
|
+
magenta: 35,
|
151
|
+
cyan: 36,
|
152
|
+
white: 37,
|
153
|
+
|
154
|
+
on_black: 40,
|
155
|
+
on_red: 41,
|
156
|
+
on_green: 42,
|
157
|
+
on_yellow: 43,
|
158
|
+
on_blue: 44,
|
159
|
+
on_magenta: 45,
|
160
|
+
on_cyan: 46,
|
161
|
+
on_white: 47,
|
162
|
+
|
163
|
+
frame: 51,
|
164
|
+
encircle: 52,
|
165
|
+
overline: 53,
|
166
|
+
frame_off: 54,
|
167
|
+
encircle_off: 54,
|
168
|
+
overline_off: 55,
|
165
169
|
}
|
166
170
|
|
167
171
|
def self.code_for(*style_names)
|
168
|
-
style_names
|
172
|
+
style_names
|
173
|
+
.map{ |n| "\e[#{CODES[n]}m" if CODES.key?(n) }
|
174
|
+
.compact
|
175
|
+
.join("")
|
169
176
|
end
|
170
177
|
|
171
178
|
def ansi_styled_msg(msg, result_type)
|
172
|
-
return msg if !
|
173
|
-
code =
|
179
|
+
return msg if !is_tty? || !styled
|
180
|
+
code =
|
181
|
+
Assert::ViewHelpers::Ansi.code_for(
|
182
|
+
*send("#{result_type}_styles"),
|
183
|
+
)
|
174
184
|
return msg if code.empty?
|
175
185
|
code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
|
176
186
|
end
|
data/test/helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
#
|
2
|
-
# put any test helpers here
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
#
|
3
|
+
# This file is automatically required when you run `assert`; put any test
|
4
|
+
# helpers here.
|
5
|
+
|
6
|
+
# Add the root dir to the load path.
|
5
7
|
ROOT_PATH = File.expand_path("../..", __FILE__)
|
6
8
|
$LOAD_PATH.unshift(ROOT_PATH)
|
7
9
|
|
@@ -14,12 +16,13 @@ module Assert::Test::TestHelpers
|
|
14
16
|
receiver.class_eval do
|
15
17
|
setup do
|
16
18
|
@test_run_results = []
|
17
|
-
@run_callback = proc
|
19
|
+
@run_callback = proc{ |result| @test_run_results << result }
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
22
24
|
|
25
|
+
# rubocop:disable Lint/NestedMethodDefinition
|
23
26
|
def test_run_callback
|
24
27
|
@run_callback
|
25
28
|
end
|
@@ -40,5 +43,6 @@ module Assert::Test::TestHelpers
|
|
40
43
|
def last_test_run_result
|
41
44
|
@test_run_results.last
|
42
45
|
end
|
46
|
+
# rubocop:enable Lint/NestedMethodDefinition
|
43
47
|
end
|
44
48
|
end
|