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