assert 2.19.1 → 2.19.6
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.
- checksums.yaml +4 -4
- data/assert.gemspec +10 -7
- data/lib/assert.rb +18 -6
- data/lib/assert/actual_value.rb +8 -6
- data/lib/assert/assert_runner.rb +36 -17
- data/lib/assert/assertions.rb +83 -50
- data/lib/assert/cli.rb +30 -70
- data/lib/assert/clirb.rb +55 -0
- data/lib/assert/config.rb +20 -8
- data/lib/assert/config_helpers.rb +55 -22
- data/lib/assert/context.rb +14 -18
- data/lib/assert/context/let_dsl.rb +5 -2
- data/lib/assert/context/setup_dsl.rb +21 -16
- data/lib/assert/context/subject_dsl.rb +6 -7
- data/lib/assert/context/suite_dsl.rb +2 -1
- data/lib/assert/context/test_dsl.rb +55 -19
- data/lib/assert/default_suite.rb +25 -15
- data/lib/assert/default_view.rb +47 -30
- data/lib/assert/file_line.rb +6 -6
- data/lib/assert/macro.rb +1 -1
- data/lib/assert/macros/methods.rb +71 -45
- data/lib/assert/result.rb +111 -62
- data/lib/assert/runner.rb +68 -51
- data/lib/assert/stub.rb +42 -3
- data/lib/assert/suite.rb +67 -28
- data/lib/assert/test.rb +40 -35
- data/lib/assert/utils.rb +19 -10
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +44 -18
- data/lib/assert/view_helpers.rb +100 -92
- data/test/helper.rb +3 -1
- data/test/support/factory.rb +38 -21
- data/test/system/stub_tests.rb +180 -144
- data/test/system/test_tests.rb +86 -60
- data/test/unit/actual_value_tests.rb +69 -50
- data/test/unit/assert_tests.rb +39 -22
- data/test/unit/assertions/assert_block_tests.rb +10 -10
- data/test/unit/assertions/assert_changes_tests.rb +25 -21
- data/test/unit/assertions/assert_empty_tests.rb +14 -12
- data/test/unit/assertions/assert_equal_tests.rb +26 -26
- data/test/unit/assertions/assert_file_exists_tests.rb +15 -13
- data/test/unit/assertions/assert_includes_tests.rb +10 -10
- data/test/unit/assertions/assert_instance_of_tests.rb +14 -14
- data/test/unit/assertions/assert_is_a_tests.rb +128 -0
- data/test/unit/assertions/assert_match_tests.rb +10 -10
- data/test/unit/assertions/assert_nil_tests.rb +16 -12
- data/test/unit/assertions/assert_raises_tests.rb +27 -20
- data/test/unit/assertions/assert_respond_to_tests.rb +10 -10
- data/test/unit/assertions/assert_same_tests.rb +24 -24
- data/test/unit/assertions/assert_true_false_tests.rb +32 -24
- data/test/unit/assertions_tests.rb +14 -9
- data/test/unit/config_helpers_tests.rb +15 -10
- data/test/unit/config_tests.rb +34 -9
- data/test/unit/context/setup_dsl_tests.rb +24 -14
- data/test/unit/context/subject_dsl_tests.rb +3 -3
- data/test/unit/context/suite_dsl_tests.rb +4 -4
- data/test/unit/context/test_dsl_tests.rb +37 -17
- data/test/unit/context_info_tests.rb +4 -4
- data/test/unit/context_tests.rb +110 -54
- data/test/unit/default_suite_tests.rb +10 -6
- data/test/unit/factory_tests.rb +2 -2
- data/test/unit/file_line_tests.rb +7 -7
- data/test/unit/macro_tests.rb +11 -11
- data/test/unit/result_tests.rb +47 -41
- data/test/unit/runner_tests.rb +29 -16
- data/test/unit/suite_tests.rb +37 -15
- data/test/unit/test_tests.rb +63 -50
- data/test/unit/utils_tests.rb +48 -35
- data/test/unit/view_helpers_tests.rb +21 -14
- data/test/unit/view_tests.rb +5 -5
- metadata +26 -11
- data/test/unit/assertions/assert_kind_of_tests.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd449dd7b34b86306e82212ebe0f487381bfceb1f5bebe4b33267287c1042ccf
|
4
|
+
data.tar.gz: 84993c54ea74a3ee84e955466e3a778d46ef9a746a7c6d1775994e99c2f218f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21c6d4fa31ed751d2e39989f9adfa4c7b3e127aed9de394e5cec9679d7e8abc1be3967702e0e7b5dff0e277e673d92ec5b8c0839902dfeaf12b329d3943cb65
|
7
|
+
data.tar.gz: b4273af162ac77362407cedb18bfbb79c55a014ef57cb3dcf8341ec901a40df4effe570b148b1ec86968c21dff637d50e99de11e7db67acba8b60b6cf38829df
|
data/assert.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
|
-
# -*- encoding: utf-8 -*-
|
4
4
|
lib = File.expand_path("../lib", __FILE__)
|
5
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
6
|
require "assert/version"
|
@@ -10,19 +10,22 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.version = Assert::VERSION
|
11
11
|
gem.authors = ["Kelly Redding", "Collin Redding"]
|
12
12
|
gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
|
13
|
-
gem.summary =
|
14
|
-
gem.description =
|
13
|
+
gem.summary = "Assertion style testing framework."
|
14
|
+
gem.description = "Assertion style testing framework."
|
15
15
|
gem.homepage = "http://github.com/redding/assert"
|
16
16
|
gem.license = "MIT"
|
17
17
|
|
18
|
-
gem.files
|
18
|
+
gem.files = `git ls-files | grep "^[^.]"`.split($INPUT_RECORD_SEPARATOR)
|
19
|
+
|
19
20
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
21
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
22
|
gem.require_paths = ["lib"]
|
22
23
|
|
23
24
|
gem.required_ruby_version = "~> 2.5"
|
24
25
|
|
25
|
-
gem.
|
26
|
-
|
27
|
-
gem.add_dependency("much-
|
26
|
+
gem.add_development_dependency("much-style-guide", ["~> 0.6.1"])
|
27
|
+
|
28
|
+
gem.add_dependency("much-factory", ["~> 0.2.2"])
|
29
|
+
gem.add_dependency("much-not-given", ["~> 0.1.2"])
|
30
|
+
gem.add_dependency("much-stub", ["~> 0.1.7"])
|
28
31
|
end
|
data/lib/assert.rb
CHANGED
@@ -11,16 +11,28 @@ require "assert/utils"
|
|
11
11
|
require "assert/view"
|
12
12
|
|
13
13
|
module Assert
|
14
|
-
def self.config
|
15
|
-
|
14
|
+
def self.config
|
15
|
+
@config ||= Config.new
|
16
|
+
end
|
16
17
|
|
17
|
-
def self.
|
18
|
-
|
19
|
-
|
18
|
+
def self.configure
|
19
|
+
yield config if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.view
|
23
|
+
config.view
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.suite
|
27
|
+
config.suite
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.runner
|
31
|
+
config.runner
|
32
|
+
end
|
20
33
|
|
21
34
|
# unstub all stubs automatically (see stub.rb)
|
22
35
|
class Context
|
23
36
|
teardown{ Assert.unstub! }
|
24
37
|
end
|
25
38
|
end
|
26
|
-
|
data/lib/assert/actual_value.rb
CHANGED
@@ -37,15 +37,17 @@ class Assert::ActualValue
|
|
37
37
|
@context.assert_not_changes(*args, &@value)
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
@context.
|
40
|
+
def is_a(expected_class, *args)
|
41
|
+
@context.assert_is_a(expected_class, @value, *args)
|
42
42
|
end
|
43
|
-
alias_method :
|
43
|
+
alias_method :is_a_kind_of, :is_a
|
44
|
+
alias_method :is_kind_of, :is_a
|
44
45
|
|
45
|
-
def
|
46
|
-
@context.
|
46
|
+
def is_not_a(expected_class, *args)
|
47
|
+
@context.assert_is_not_a(expected_class, @value, *args)
|
47
48
|
end
|
48
|
-
alias_method :
|
49
|
+
alias_method :is_not_a_kind_of, :is_not_a
|
50
|
+
alias_method :is_not_kind_of, :is_not_a
|
49
51
|
|
50
52
|
def is_an_instance_of(expected_class, *args)
|
51
53
|
@context.assert_instance_of(expected_class, @value, *args)
|
data/lib/assert/assert_runner.rb
CHANGED
@@ -25,24 +25,29 @@ module Assert
|
|
25
25
|
|
26
26
|
def init(test_files, test_dir)
|
27
27
|
# load any test helper file
|
28
|
-
if
|
28
|
+
if (
|
29
|
+
test_dir &&
|
30
|
+
(h = File.join(test_dir, config.test_helper)) &&
|
31
|
+
File.exist?(h)
|
32
|
+
)
|
29
33
|
Assert::CLI.bench("Requiring test helper"){ require h }
|
30
34
|
end
|
31
35
|
|
32
|
-
if
|
36
|
+
if config.list
|
33
37
|
$stdout.puts test_files
|
34
38
|
halt
|
35
39
|
end
|
36
40
|
|
37
41
|
# load the test files
|
38
|
-
runner, suite, view =
|
42
|
+
runner, suite, view =
|
43
|
+
config.runner, config.suite, config.view
|
39
44
|
runner.before_load(test_files)
|
40
45
|
suite.before_load(test_files)
|
41
46
|
view.before_load(test_files)
|
42
47
|
Assert::CLI.bench("Requiring #{test_files.size} test files") do
|
43
48
|
test_files.each{ |p| require p }
|
44
49
|
end
|
45
|
-
if
|
50
|
+
if config.debug
|
46
51
|
puts Assert::CLI.debug_msg("Test files:")
|
47
52
|
test_files.each{ |f| puts Assert::CLI.debug_msg(" #{f}") }
|
48
53
|
end
|
@@ -52,7 +57,7 @@ module Assert
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def run
|
55
|
-
|
60
|
+
config.runner.run
|
56
61
|
end
|
57
62
|
|
58
63
|
private
|
@@ -66,22 +71,27 @@ module Assert
|
|
66
71
|
end
|
67
72
|
|
68
73
|
def apply_local_settings
|
69
|
-
safe_require(
|
74
|
+
safe_require(
|
75
|
+
ENV["ASSERT_LOCALFILE"] ||
|
76
|
+
path_of(LOCAL_SETTINGS_FILE, Dir.pwd),
|
77
|
+
)
|
70
78
|
end
|
71
79
|
|
72
80
|
def apply_env_settings
|
73
|
-
|
81
|
+
if ENV["ASSERT_RUNNER_SEED"]
|
82
|
+
config.runner_seed ENV["ASSERT_RUNNER_SEED"].to_i
|
83
|
+
end
|
74
84
|
end
|
75
85
|
|
76
86
|
def apply_option_settings(options)
|
77
|
-
|
87
|
+
config.apply(options)
|
78
88
|
end
|
79
89
|
|
80
90
|
def lookup_test_files(test_paths)
|
81
|
-
file_paths = if
|
91
|
+
file_paths = if config.changed_only
|
82
92
|
changed_test_files(test_paths)
|
83
|
-
elsif
|
84
|
-
globbed_test_files([
|
93
|
+
elsif config.single_test?
|
94
|
+
globbed_test_files([config.single_test_file_path])
|
85
95
|
else
|
86
96
|
globbed_test_files(test_paths)
|
87
97
|
end
|
@@ -90,33 +100,42 @@ module Assert
|
|
90
100
|
end
|
91
101
|
|
92
102
|
def changed_test_files(test_paths)
|
93
|
-
globbed_test_files(
|
103
|
+
globbed_test_files(config.changed_proc.call(config, test_paths))
|
94
104
|
end
|
95
105
|
|
96
106
|
def globbed_test_files(test_paths)
|
97
107
|
test_paths.inject(Set.new) do |paths, path|
|
98
108
|
p = File.expand_path(path, Dir.pwd)
|
99
|
-
paths
|
109
|
+
paths + Dir.glob("#{p}*") + Dir.glob("#{p}*/**/*")
|
100
110
|
end
|
101
111
|
end
|
102
112
|
|
103
113
|
def is_test_file?(path)
|
104
|
-
|
114
|
+
config.test_file_suffixes.inject(false) do |result, suffix|
|
105
115
|
result || path =~ /#{suffix}$/
|
106
116
|
end
|
107
117
|
end
|
108
118
|
|
109
119
|
def safe_require(settings_file)
|
110
|
-
require settings_file if File.
|
120
|
+
require settings_file if File.exist?(settings_file)
|
111
121
|
end
|
112
122
|
|
113
123
|
def path_of(segment, a_path)
|
114
124
|
# this method inspects a test path and finds the test dir path.
|
115
125
|
full_path = File.expand_path(a_path || ".", Dir.pwd)
|
116
126
|
seg_pos = full_path.index(segment_regex(segment))
|
117
|
-
File.join(
|
127
|
+
File.join(
|
128
|
+
if seg_pos && (seg_pos > 0)
|
129
|
+
full_path[0..(seg_pos - 1)]
|
130
|
+
else
|
131
|
+
full_path
|
132
|
+
end,
|
133
|
+
segment,
|
134
|
+
)
|
118
135
|
end
|
119
136
|
|
120
|
-
def segment_regex(seg)
|
137
|
+
def segment_regex(seg)
|
138
|
+
%r{^#{seg}$|^#{seg}/|/#{seg}/|/#{seg}$}
|
139
|
+
end
|
121
140
|
end
|
122
141
|
end
|
data/lib/assert/assertions.rb
CHANGED
@@ -6,11 +6,15 @@ module Assert
|
|
6
6
|
module Assertions
|
7
7
|
IGNORED_ASSERTION_HELPERS =
|
8
8
|
[
|
9
|
-
:assert_throws,
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
9
|
+
:assert_throws,
|
10
|
+
:assert_nothing_thrown,
|
11
|
+
:assert_operator,
|
12
|
+
:refute_operator,
|
13
|
+
:assert_in_epsilon,
|
14
|
+
:refute_in_epsilon,
|
15
|
+
:assert_in_delta,
|
16
|
+
:refute_in_delta,
|
17
|
+
:assert_send,
|
14
18
|
]
|
15
19
|
|
16
20
|
def assert_block(desc = nil)
|
@@ -24,13 +28,15 @@ module Assert
|
|
24
28
|
|
25
29
|
def assert_empty(collection, desc = nil)
|
26
30
|
assert(collection.empty?, desc) do
|
27
|
-
"Expected #{Assert::U.show(collection, __assert_config__)} to
|
31
|
+
"Expected #{Assert::U.show(collection, __assert_config__)} to "\
|
32
|
+
"be empty."
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
36
|
def assert_not_empty(collection, desc = nil)
|
32
37
|
assert(!collection.empty?, desc) do
|
33
|
-
"Expected #{Assert::U.show(collection, __assert_config__)} to
|
38
|
+
"Expected #{Assert::U.show(collection, __assert_config__)} to "\
|
39
|
+
"not be empty."
|
34
40
|
end
|
35
41
|
end
|
36
42
|
alias_method :refute_empty, :assert_not_empty
|
@@ -45,7 +51,8 @@ module Assert
|
|
45
51
|
"Expected does not equal actual, diff:\n"\
|
46
52
|
"#{c.run_diff_proc.call(exp_show, act_show)}"
|
47
53
|
else
|
48
|
-
"Expected #{Assert::U.show(act, c)} to
|
54
|
+
"Expected #{Assert::U.show(act, c)} to "\
|
55
|
+
"be equal to #{Assert::U.show(exp, c)}."
|
49
56
|
end
|
50
57
|
end
|
51
58
|
end
|
@@ -60,20 +67,21 @@ module Assert
|
|
60
67
|
"Expected equals actual, diff:\n"\
|
61
68
|
"#{c.run_diff_proc.call(exp_show, act_show)}"
|
62
69
|
else
|
63
|
-
"Expected #{Assert::U.show(act, c)} to
|
70
|
+
"Expected #{Assert::U.show(act, c)} to "\
|
71
|
+
"not be equal to #{Assert::U.show(exp, c)}."
|
64
72
|
end
|
65
73
|
end
|
66
74
|
end
|
67
75
|
alias_method :refute_equal, :assert_not_equal
|
68
76
|
|
69
77
|
def assert_file_exists(file_path, desc = nil)
|
70
|
-
assert(File.
|
78
|
+
assert(File.exist?(File.expand_path(file_path)), desc) do
|
71
79
|
"Expected #{Assert::U.show(file_path, __assert_config__)} to exist."
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
75
83
|
def assert_not_file_exists(file_path, desc = nil)
|
76
|
-
assert(!File.
|
84
|
+
assert(!File.exist?(File.expand_path(file_path)), desc) do
|
77
85
|
"Expected #{Assert::U.show(file_path, __assert_config__)} to not exist."
|
78
86
|
end
|
79
87
|
end
|
@@ -99,36 +107,41 @@ module Assert
|
|
99
107
|
|
100
108
|
def assert_instance_of(klass, instance, desc = nil)
|
101
109
|
assert(instance.instance_of?(klass), desc) do
|
102
|
-
"Expected #{Assert::U.show(instance, __assert_config__)}
|
103
|
-
" to be an instance of #{klass}."
|
110
|
+
"Expected #{Assert::U.show(instance, __assert_config__)} "\
|
111
|
+
"(#{instance.class}) to be an instance of #{klass}."
|
104
112
|
end
|
105
113
|
end
|
106
114
|
|
107
115
|
def assert_not_instance_of(klass, instance, desc = nil)
|
108
116
|
assert(!instance.instance_of?(klass), desc) do
|
109
|
-
"Expected #{Assert::U.show(instance, __assert_config__)}
|
110
|
-
" to not be an instance of #{klass}."
|
117
|
+
"Expected #{Assert::U.show(instance, __assert_config__)} "\
|
118
|
+
"(#{instance.class}) to not be an instance of #{klass}."
|
111
119
|
end
|
112
120
|
end
|
113
121
|
alias_method :refute_instance_of, :assert_not_instance_of
|
114
122
|
|
115
|
-
def
|
116
|
-
assert(instance.
|
117
|
-
"Expected #{Assert::U.show(instance, __assert_config__)}
|
118
|
-
" to be a
|
123
|
+
def assert_is_a(klass, instance, desc = nil)
|
124
|
+
assert(instance.is_a?(klass), desc) do
|
125
|
+
"Expected #{Assert::U.show(instance, __assert_config__)} "\
|
126
|
+
"(#{instance.class}) to be a `#{klass}`."
|
119
127
|
end
|
120
128
|
end
|
129
|
+
alias_method :assert_kind_of, :assert_is_a
|
121
130
|
|
122
|
-
def
|
123
|
-
assert(!instance.
|
124
|
-
"Expected #{Assert::U.show(instance, __assert_config__)}
|
125
|
-
" to not be a
|
131
|
+
def assert_is_not_a(klass, instance, desc = nil)
|
132
|
+
assert(!instance.is_a?(klass), desc) do
|
133
|
+
"Expected #{Assert::U.show(instance, __assert_config__)} "\
|
134
|
+
"(#{instance.class}) to not be a `#{klass}`."
|
126
135
|
end
|
127
136
|
end
|
128
|
-
alias_method :
|
137
|
+
alias_method :assert_not_a, :assert_is_not_a
|
138
|
+
alias_method :assert_not_kind_of, :assert_is_not_a
|
139
|
+
alias_method :refute_is_a, :assert_is_not_a
|
140
|
+
alias_method :refute_kind_of, :assert_is_not_a
|
129
141
|
|
130
142
|
def assert_match(exp, act, desc = nil)
|
131
|
-
exp_regex =
|
143
|
+
exp_regex =
|
144
|
+
String === exp && String === act ? /#{Regexp.escape(exp)}/ : exp
|
132
145
|
assert(act =~ exp_regex, desc) do
|
133
146
|
"Expected #{Assert::U.show(act, __assert_config__)}"\
|
134
147
|
" to match #{Assert::U.show(exp, __assert_config__)}."
|
@@ -185,7 +198,7 @@ module Assert
|
|
185
198
|
alias_method :refute_false, :assert_not_false
|
186
199
|
|
187
200
|
def assert_raises(*exceptions, &block)
|
188
|
-
desc = exceptions.last.
|
201
|
+
desc = exceptions.last.is_a?(String) ? exceptions.pop : nil
|
189
202
|
err = RaisedException.new(exceptions, &block)
|
190
203
|
assert(err.raised?, desc){ err.msg }
|
191
204
|
err.exception
|
@@ -193,7 +206,7 @@ module Assert
|
|
193
206
|
alias_method :assert_raise, :assert_raises
|
194
207
|
|
195
208
|
def assert_nothing_raised(*exceptions, &block)
|
196
|
-
desc = exceptions.last.
|
209
|
+
desc = exceptions.last.is_a?(String) ? exceptions.pop : nil
|
197
210
|
err = NoRaisedException.new(exceptions, &block)
|
198
211
|
assert(!err.raised?, desc){ err.msg }
|
199
212
|
end
|
@@ -205,15 +218,15 @@ module Assert
|
|
205
218
|
desc: nil,
|
206
219
|
from: Assert::ActualValue.not_given,
|
207
220
|
to: Assert::ActualValue.not_given,
|
208
|
-
&block
|
209
|
-
)
|
221
|
+
&block)
|
210
222
|
desc_msg = desc ? "#{desc}\n" : ""
|
211
223
|
from_eval = instance_eval(ruby_string_to_eval)
|
212
224
|
if Assert::ActualValue.given?(from)
|
213
225
|
assert_equal(
|
214
226
|
from,
|
215
227
|
from_eval,
|
216
|
-
"#{desc_msg}Expected `#{ruby_string_to_eval}` to
|
228
|
+
"#{desc_msg}Expected `#{ruby_string_to_eval}` to "\
|
229
|
+
"change from `#{from.inspect}`.",
|
217
230
|
)
|
218
231
|
end
|
219
232
|
|
@@ -224,7 +237,8 @@ module Assert
|
|
224
237
|
assert_equal(
|
225
238
|
to,
|
226
239
|
to_eval,
|
227
|
-
"#{desc_msg}Expected `#{ruby_string_to_eval}` to
|
240
|
+
"#{desc_msg}Expected `#{ruby_string_to_eval}` to "\
|
241
|
+
"change to `#{to.inspect}`.",
|
228
242
|
)
|
229
243
|
end
|
230
244
|
|
@@ -236,7 +250,7 @@ module Assert
|
|
236
250
|
from_eval,
|
237
251
|
to_eval,
|
238
252
|
"#{desc_msg}Expected `#{ruby_string_to_eval}` to change; "\
|
239
|
-
"it was `#{from_eval.inspect}` and didn't change."
|
253
|
+
"it was `#{from_eval.inspect}` and didn't change.",
|
240
254
|
)
|
241
255
|
end
|
242
256
|
end
|
@@ -245,15 +259,15 @@ module Assert
|
|
245
259
|
ruby_string_to_eval,
|
246
260
|
desc: nil,
|
247
261
|
from: Assert::ActualValue.not_given,
|
248
|
-
&block
|
249
|
-
)
|
262
|
+
&block)
|
250
263
|
desc_msg = desc ? "#{desc}\n" : ""
|
251
264
|
from_eval = instance_eval(ruby_string_to_eval)
|
252
265
|
if Assert::ActualValue.given?(from)
|
253
266
|
assert_equal(
|
254
267
|
from,
|
255
268
|
from_eval,
|
256
|
-
"#{desc_msg}Expected `#{ruby_string_to_eval}` to
|
269
|
+
"#{desc_msg}Expected `#{ruby_string_to_eval}` to "\
|
270
|
+
"not change from `#{from.inspect}`.",
|
257
271
|
)
|
258
272
|
end
|
259
273
|
|
@@ -264,23 +278,23 @@ module Assert
|
|
264
278
|
from_eval,
|
265
279
|
to_eval,
|
266
280
|
"#{desc_msg}Expected `#{ruby_string_to_eval}` to not change; "\
|
267
|
-
"it was `#{from_eval.inspect}` and changed to `#{to_eval.inspect}`."
|
281
|
+
"it was `#{from_eval.inspect}` and changed to `#{to_eval.inspect}`.",
|
268
282
|
)
|
269
283
|
end
|
270
284
|
alias_method :refute_changes, :assert_not_changes
|
271
285
|
|
272
286
|
def assert_respond_to(method, object, desc = nil)
|
273
287
|
assert(object.respond_to?(method), desc) do
|
274
|
-
"Expected #{Assert::U.show(object, __assert_config__)}
|
275
|
-
" to respond to `#{method}`."
|
288
|
+
"Expected #{Assert::U.show(object, __assert_config__)} "\
|
289
|
+
"(#{object.class}) to respond to `#{method}`."
|
276
290
|
end
|
277
291
|
end
|
278
292
|
alias_method :assert_responds_to, :assert_respond_to
|
279
293
|
|
280
294
|
def assert_not_respond_to(method, object, desc = nil)
|
281
295
|
assert(!object.respond_to?(method), desc) do
|
282
|
-
"Expected #{Assert::U.show(object, __assert_config__)}
|
283
|
-
" to not respond to `#{method}`."
|
296
|
+
"Expected #{Assert::U.show(object, __assert_config__)} "\
|
297
|
+
"(#{object.class}) to not respond to `#{method}`."
|
284
298
|
end
|
285
299
|
end
|
286
300
|
alias_method :assert_not_responds_to, :assert_not_respond_to
|
@@ -299,8 +313,8 @@ module Assert
|
|
299
313
|
"Expected #{act_id} to be the same as #{exp_id}, diff:\n"\
|
300
314
|
"#{c.run_diff_proc.call(exp_show, act_show)}"
|
301
315
|
else
|
302
|
-
"Expected #{Assert::U.show(act, c)} (#{act_id}) to
|
303
|
-
" #{Assert::U.show(exp, c)} (#{exp_id})."
|
316
|
+
"Expected #{Assert::U.show(act, c)} (#{act_id}) to "\
|
317
|
+
"be the same as #{Assert::U.show(exp, c)} (#{exp_id})."
|
304
318
|
end
|
305
319
|
end
|
306
320
|
end
|
@@ -317,8 +331,8 @@ module Assert
|
|
317
331
|
"Expected #{act_id} to not be the same as #{exp_id}, diff:\n"\
|
318
332
|
"#{c.run_diff_proc.call(exp_show, act_show)}"
|
319
333
|
else
|
320
|
-
"Expected #{Assert::U.show(act, c)} (#{act_id}) to
|
321
|
-
" #{Assert::U.show(exp, c)} (#{exp_id})."
|
334
|
+
"Expected #{Assert::U.show(act, c)} (#{act_id}) to "\
|
335
|
+
"not be the same as #{Assert::U.show(exp, c)} (#{exp_id})."
|
322
336
|
end
|
323
337
|
end
|
324
338
|
end
|
@@ -337,7 +351,16 @@ module Assert
|
|
337
351
|
|
338
352
|
def initialize(exceptions, &block)
|
339
353
|
@exceptions = exceptions
|
340
|
-
|
354
|
+
# rubocop:disable Lint/SuppressedException
|
355
|
+
# rubocop:disable Lint/RescueException
|
356
|
+
# rubocop:disable Naming/RescuedExceptionsVariableName
|
357
|
+
begin
|
358
|
+
block.call
|
359
|
+
rescue Exception => @exception
|
360
|
+
end
|
361
|
+
# rubocop:enable Lint/SuppressedException
|
362
|
+
# rubocop:enable Lint/RescueException
|
363
|
+
# rubocop:enable Naming/RescuedExceptionsVariableName
|
341
364
|
@msg = "#{exceptions_sentence(@exceptions)} #{exception_details}"
|
342
365
|
end
|
343
366
|
|
@@ -349,7 +372,11 @@ module Assert
|
|
349
372
|
|
350
373
|
def is_one_of?(exception, exceptions)
|
351
374
|
exceptions.empty? || exceptions.any? do |exp|
|
352
|
-
exp.instance_of?(Module)
|
375
|
+
if exp.instance_of?(Module)
|
376
|
+
exception.is_a?(exp)
|
377
|
+
else
|
378
|
+
exception.class == exp
|
379
|
+
end
|
353
380
|
end
|
354
381
|
end
|
355
382
|
|
@@ -364,13 +391,16 @@ module Assert
|
|
364
391
|
def exception_details(raised_msg = nil, no_raised_msg = nil)
|
365
392
|
if @exception
|
366
393
|
backtrace = Assert::Result::Backtrace.new(@exception.backtrace)
|
367
|
-
[
|
394
|
+
[
|
395
|
+
raised_msg,
|
368
396
|
"Class: `#{@exception.class}`",
|
369
397
|
"Message: `#{@exception.message.inspect}`",
|
370
398
|
"---Backtrace---",
|
371
399
|
backtrace.filtered.to_s,
|
372
|
-
"---------------"
|
373
|
-
]
|
400
|
+
"---------------",
|
401
|
+
]
|
402
|
+
.compact
|
403
|
+
.join("\n")
|
374
404
|
else
|
375
405
|
no_raised_msg
|
376
406
|
end
|
@@ -379,7 +409,10 @@ module Assert
|
|
379
409
|
|
380
410
|
class RaisedException < CheckException
|
381
411
|
def exception_details
|
382
|
-
super(
|
412
|
+
super(
|
413
|
+
"exception expected, not:",
|
414
|
+
"exception expected but nothing raised."
|
415
|
+
)
|
383
416
|
end
|
384
417
|
end
|
385
418
|
|