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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffa19cd67672156c36573b10b2e25b2b18ffa6b291b763ee25aca8a36d10b5bb
|
4
|
+
data.tar.gz: 12ed7729dae14a838f02780ba66da65cd097a705d6746ce898525c9cffd5a7b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6be9346bf38ff9421f5663a18f4f3d2c020aa970245364db4df78100851feedaefae17fd2bc14bf21a2dc9d668efa5372fb1432402a587b6d79723e15e45179
|
7
|
+
data.tar.gz: 69b152a7ec1f5fcbf738246477d7d8085aae7805e064536f3134e7b4aca0c2d22f0f4ea03c65e78488ba426c1db0b05c1b74adafd979f73f23d7c78349293667
|
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,18 +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
|
-
|
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"])
|
25
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,9 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "much-not-given"
|
1
4
|
require "much-stub"
|
2
5
|
|
3
6
|
module Assert; end
|
7
|
+
|
4
8
|
class Assert::ActualValue
|
5
|
-
|
6
|
-
|
9
|
+
include MuchNotGiven
|
10
|
+
|
11
|
+
def initialize(value = self.class.not_given, context:, &value_block)
|
12
|
+
@value = self.class.given?(value) ? value : value_block
|
7
13
|
@context = context
|
8
14
|
end
|
9
15
|
|
@@ -23,15 +29,25 @@ class Assert::ActualValue
|
|
23
29
|
@context.assert_nothing_raised(*expected_exceptions, &@value)
|
24
30
|
end
|
25
31
|
|
26
|
-
def
|
27
|
-
@context.
|
32
|
+
def changes(*args)
|
33
|
+
@context.assert_changes(*args, &@value)
|
34
|
+
end
|
35
|
+
|
36
|
+
def does_not_change(*args)
|
37
|
+
@context.assert_not_changes(*args, &@value)
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_a(expected_class, *args)
|
41
|
+
@context.assert_is_a(expected_class, @value, *args)
|
28
42
|
end
|
29
|
-
alias_method :
|
43
|
+
alias_method :is_a_kind_of, :is_a
|
44
|
+
alias_method :is_kind_of, :is_a
|
30
45
|
|
31
|
-
def
|
32
|
-
@context.
|
46
|
+
def is_not_a(expected_class, *args)
|
47
|
+
@context.assert_is_not_a(expected_class, @value, *args)
|
33
48
|
end
|
34
|
-
alias_method :
|
49
|
+
alias_method :is_not_a_kind_of, :is_not_a
|
50
|
+
alias_method :is_not_kind_of, :is_not_a
|
35
51
|
|
36
52
|
def is_an_instance_of(expected_class, *args)
|
37
53
|
@context.assert_instance_of(expected_class, @value, *args)
|
@@ -54,10 +70,12 @@ class Assert::ActualValue
|
|
54
70
|
def is_the_same_as(expected_object, *args)
|
55
71
|
@context.assert_same(expected_object, @value, *args)
|
56
72
|
end
|
73
|
+
alias_method :is, :is_the_same_as
|
57
74
|
|
58
75
|
def is_not_the_same_as(expected_object, *args)
|
59
76
|
@context.assert_not_same(expected_object, @value, *args)
|
60
77
|
end
|
78
|
+
alias_method :is_not, :is_not_the_same_as
|
61
79
|
|
62
80
|
def equals(expected_value, *args)
|
63
81
|
@context.assert_equal(expected_value, @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,25 +206,95 @@ 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
|
198
213
|
alias_method :assert_not_raises, :assert_nothing_raised
|
199
214
|
alias_method :assert_not_raise, :assert_nothing_raised
|
200
215
|
|
216
|
+
def assert_changes(
|
217
|
+
ruby_string_to_eval,
|
218
|
+
desc: nil,
|
219
|
+
from: Assert::ActualValue.not_given,
|
220
|
+
to: Assert::ActualValue.not_given,
|
221
|
+
&block)
|
222
|
+
desc_msg = desc ? "#{desc}\n" : ""
|
223
|
+
from_eval = instance_eval(ruby_string_to_eval)
|
224
|
+
if Assert::ActualValue.given?(from)
|
225
|
+
assert_equal(
|
226
|
+
from,
|
227
|
+
from_eval,
|
228
|
+
"#{desc_msg}Expected `#{ruby_string_to_eval}` to "\
|
229
|
+
"change from `#{from.inspect}`.",
|
230
|
+
)
|
231
|
+
end
|
232
|
+
|
233
|
+
block.call
|
234
|
+
|
235
|
+
to_eval = instance_eval(ruby_string_to_eval)
|
236
|
+
if Assert::ActualValue.given?(to)
|
237
|
+
assert_equal(
|
238
|
+
to,
|
239
|
+
to_eval,
|
240
|
+
"#{desc_msg}Expected `#{ruby_string_to_eval}` to "\
|
241
|
+
"change to `#{to.inspect}`.",
|
242
|
+
)
|
243
|
+
end
|
244
|
+
|
245
|
+
if (
|
246
|
+
Assert::ActualValue.not_given?(from) &&
|
247
|
+
Assert::ActualValue.not_given?(to)
|
248
|
+
)
|
249
|
+
assert_not_equal(
|
250
|
+
from_eval,
|
251
|
+
to_eval,
|
252
|
+
"#{desc_msg}Expected `#{ruby_string_to_eval}` to change; "\
|
253
|
+
"it was `#{from_eval.inspect}` and didn't change.",
|
254
|
+
)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def assert_not_changes(
|
259
|
+
ruby_string_to_eval,
|
260
|
+
desc: nil,
|
261
|
+
from: Assert::ActualValue.not_given,
|
262
|
+
&block)
|
263
|
+
desc_msg = desc ? "#{desc}\n" : ""
|
264
|
+
from_eval = instance_eval(ruby_string_to_eval)
|
265
|
+
if Assert::ActualValue.given?(from)
|
266
|
+
assert_equal(
|
267
|
+
from,
|
268
|
+
from_eval,
|
269
|
+
"#{desc_msg}Expected `#{ruby_string_to_eval}` to "\
|
270
|
+
"not change from `#{from.inspect}`.",
|
271
|
+
)
|
272
|
+
end
|
273
|
+
|
274
|
+
block.call
|
275
|
+
|
276
|
+
to_eval = instance_eval(ruby_string_to_eval)
|
277
|
+
assert_equal(
|
278
|
+
from_eval,
|
279
|
+
to_eval,
|
280
|
+
"#{desc_msg}Expected `#{ruby_string_to_eval}` to not change; "\
|
281
|
+
"it was `#{from_eval.inspect}` and changed to `#{to_eval.inspect}`.",
|
282
|
+
)
|
283
|
+
end
|
284
|
+
alias_method :refute_changes, :assert_not_changes
|
285
|
+
|
201
286
|
def assert_respond_to(method, object, desc = nil)
|
202
287
|
assert(object.respond_to?(method), desc) do
|
203
|
-
"Expected #{Assert::U.show(object, __assert_config__)}
|
204
|
-
" to respond to `#{method}`."
|
288
|
+
"Expected #{Assert::U.show(object, __assert_config__)} "\
|
289
|
+
"(#{object.class}) to respond to `#{method}`."
|
205
290
|
end
|
206
291
|
end
|
207
292
|
alias_method :assert_responds_to, :assert_respond_to
|
208
293
|
|
209
294
|
def assert_not_respond_to(method, object, desc = nil)
|
210
295
|
assert(!object.respond_to?(method), desc) do
|
211
|
-
"Expected #{Assert::U.show(object, __assert_config__)}
|
212
|
-
" to not respond to `#{method}`."
|
296
|
+
"Expected #{Assert::U.show(object, __assert_config__)} "\
|
297
|
+
"(#{object.class}) to not respond to `#{method}`."
|
213
298
|
end
|
214
299
|
end
|
215
300
|
alias_method :assert_not_responds_to, :assert_not_respond_to
|
@@ -228,8 +313,8 @@ module Assert
|
|
228
313
|
"Expected #{act_id} to be the same as #{exp_id}, diff:\n"\
|
229
314
|
"#{c.run_diff_proc.call(exp_show, act_show)}"
|
230
315
|
else
|
231
|
-
"Expected #{Assert::U.show(act, c)} (#{act_id}) to
|
232
|
-
" #{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})."
|
233
318
|
end
|
234
319
|
end
|
235
320
|
end
|
@@ -246,8 +331,8 @@ module Assert
|
|
246
331
|
"Expected #{act_id} to not be the same as #{exp_id}, diff:\n"\
|
247
332
|
"#{c.run_diff_proc.call(exp_show, act_show)}"
|
248
333
|
else
|
249
|
-
"Expected #{Assert::U.show(act, c)} (#{act_id}) to
|
250
|
-
" #{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})."
|
251
336
|
end
|
252
337
|
end
|
253
338
|
end
|
@@ -266,7 +351,16 @@ module Assert
|
|
266
351
|
|
267
352
|
def initialize(exceptions, &block)
|
268
353
|
@exceptions = exceptions
|
269
|
-
|
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
|
270
364
|
@msg = "#{exceptions_sentence(@exceptions)} #{exception_details}"
|
271
365
|
end
|
272
366
|
|
@@ -278,7 +372,11 @@ module Assert
|
|
278
372
|
|
279
373
|
def is_one_of?(exception, exceptions)
|
280
374
|
exceptions.empty? || exceptions.any? do |exp|
|
281
|
-
exp.instance_of?(Module)
|
375
|
+
if exp.instance_of?(Module)
|
376
|
+
exception.is_a?(exp)
|
377
|
+
else
|
378
|
+
exception.class == exp
|
379
|
+
end
|
282
380
|
end
|
283
381
|
end
|
284
382
|
|
@@ -293,13 +391,16 @@ module Assert
|
|
293
391
|
def exception_details(raised_msg = nil, no_raised_msg = nil)
|
294
392
|
if @exception
|
295
393
|
backtrace = Assert::Result::Backtrace.new(@exception.backtrace)
|
296
|
-
[
|
394
|
+
[
|
395
|
+
raised_msg,
|
297
396
|
"Class: `#{@exception.class}`",
|
298
397
|
"Message: `#{@exception.message.inspect}`",
|
299
398
|
"---Backtrace---",
|
300
399
|
backtrace.filtered.to_s,
|
301
|
-
"---------------"
|
302
|
-
]
|
400
|
+
"---------------",
|
401
|
+
]
|
402
|
+
.compact
|
403
|
+
.join("\n")
|
303
404
|
else
|
304
405
|
no_raised_msg
|
305
406
|
end
|
@@ -308,7 +409,10 @@ module Assert
|
|
308
409
|
|
309
410
|
class RaisedException < CheckException
|
310
411
|
def exception_details
|
311
|
-
super(
|
412
|
+
super(
|
413
|
+
"exception expected, not:",
|
414
|
+
"exception expected but nothing raised."
|
415
|
+
)
|
312
416
|
end
|
313
417
|
end
|
314
418
|
|