assert 2.16.5 → 2.18.3
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 +7 -7
- data/Gemfile +3 -1
- data/README.md +79 -54
- data/assert.gemspec +6 -5
- data/bin/assert +4 -4
- data/lib/assert.rb +8 -18
- data/lib/assert/actual_value.rb +127 -0
- data/lib/assert/assert_runner.rb +7 -10
- data/lib/assert/assertions.rb +15 -28
- data/lib/assert/cli.rb +41 -57
- data/lib/assert/config.rb +8 -12
- data/lib/assert/config_helpers.rb +6 -10
- data/lib/assert/context.rb +30 -24
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/setup_dsl.rb +0 -4
- data/lib/assert/context/subject_dsl.rb +0 -4
- data/lib/assert/context/suite_dsl.rb +0 -4
- data/lib/assert/context/test_dsl.rb +5 -9
- data/lib/assert/context_info.rb +2 -6
- data/lib/assert/default_runner.rb +1 -5
- data/lib/assert/default_suite.rb +1 -6
- data/lib/assert/default_view.rb +8 -12
- data/lib/assert/factory.rb +1 -4
- data/lib/assert/file_line.rb +0 -4
- data/lib/assert/macro.rb +1 -4
- data/lib/assert/macros/methods.rb +5 -11
- data/lib/assert/result.rb +19 -34
- data/lib/assert/runner.rb +12 -11
- data/lib/assert/stub.rb +16 -2
- data/lib/assert/suite.rb +3 -7
- data/lib/assert/test.rb +13 -18
- data/lib/assert/utils.rb +8 -12
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +18 -21
- data/lib/assert/view_helpers.rb +6 -17
- data/log/{.gitkeep → .keep} +0 -0
- data/test/helper.rb +26 -41
- data/test/support/factory.rb +20 -6
- data/test/support/inherited_stuff.rb +0 -2
- data/test/system/stub_tests.rb +350 -354
- data/test/system/test_tests.rb +119 -133
- data/test/unit/actual_value_tests.rb +335 -0
- data/test/unit/assert_tests.rb +125 -52
- data/test/unit/assertions/assert_block_tests.rb +34 -37
- data/test/unit/assertions/assert_empty_tests.rb +38 -38
- data/test/unit/assertions/assert_equal_tests.rb +84 -86
- data/test/unit/assertions/assert_file_exists_tests.rb +37 -39
- data/test/unit/assertions/assert_includes_tests.rb +45 -46
- data/test/unit/assertions/assert_instance_of_tests.rb +39 -40
- data/test/unit/assertions/assert_kind_of_tests.rb +39 -40
- data/test/unit/assertions/assert_match_tests.rb +39 -40
- data/test/unit/assertions/assert_nil_tests.rb +35 -38
- data/test/unit/assertions/assert_raises_tests.rb +58 -62
- data/test/unit/assertions/assert_respond_to_tests.rb +41 -42
- data/test/unit/assertions/assert_same_tests.rb +94 -90
- data/test/unit/assertions/assert_true_false_tests.rb +67 -69
- data/test/unit/assertions_tests.rb +17 -19
- data/test/unit/config_helpers_tests.rb +41 -43
- data/test/unit/config_tests.rb +42 -46
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +72 -91
- data/test/unit/context/subject_dsl_tests.rb +18 -51
- data/test/unit/context/suite_dsl_tests.rb +19 -23
- data/test/unit/context/test_dsl_tests.rb +52 -59
- data/test/unit/context_info_tests.rb +19 -21
- data/test/unit/context_tests.rb +175 -178
- data/test/unit/default_runner_tests.rb +4 -10
- data/test/unit/default_suite_tests.rb +54 -59
- data/test/unit/factory_tests.rb +6 -9
- data/test/unit/file_line_tests.rb +34 -40
- data/test/unit/macro_tests.rb +11 -20
- data/test/unit/result_tests.rb +156 -182
- data/test/unit/runner_tests.rb +72 -79
- data/test/unit/suite_tests.rb +62 -63
- data/test/unit/test_tests.rb +143 -147
- data/test/unit/utils_tests.rb +49 -62
- data/test/unit/view_helpers_tests.rb +67 -70
- data/test/unit/view_tests.rb +26 -32
- metadata +54 -47
- data/.assert.rb +0 -3
- data/.gitignore +0 -19
data/lib/assert/assert_runner.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require "assert/cli"
|
2
2
|
|
3
3
|
module Assert
|
4
|
-
|
5
4
|
class AssertRunner
|
6
5
|
USER_SETTINGS_FILE = ".assert/init.rb"
|
7
6
|
LOCAL_SETTINGS_FILE = ".assert.rb"
|
@@ -10,7 +9,7 @@ module Assert
|
|
10
9
|
|
11
10
|
def initialize(config, test_paths, test_options)
|
12
11
|
@config = config
|
13
|
-
Assert::CLI.bench(
|
12
|
+
Assert::CLI.bench("Applying settings") do
|
14
13
|
apply_user_settings
|
15
14
|
apply_local_settings
|
16
15
|
apply_env_settings
|
@@ -25,7 +24,7 @@ module Assert
|
|
25
24
|
def init(test_files, test_dir)
|
26
25
|
# load any test helper file
|
27
26
|
if test_dir && (h = File.join(test_dir, self.config.test_helper)) && File.exists?(h)
|
28
|
-
Assert::CLI.bench(
|
27
|
+
Assert::CLI.bench("Requiring test helper"){ require h }
|
29
28
|
end
|
30
29
|
|
31
30
|
if self.config.list
|
@@ -61,15 +60,15 @@ module Assert
|
|
61
60
|
end
|
62
61
|
|
63
62
|
def apply_user_settings
|
64
|
-
safe_require("#{ENV[
|
63
|
+
safe_require("#{ENV["HOME"]}/#{USER_SETTINGS_FILE}") if ENV["HOME"]
|
65
64
|
end
|
66
65
|
|
67
66
|
def apply_local_settings
|
68
|
-
safe_require(ENV[
|
67
|
+
safe_require(ENV["ASSERT_LOCALFILE"] || path_of(LOCAL_SETTINGS_FILE, Dir.pwd))
|
69
68
|
end
|
70
69
|
|
71
70
|
def apply_env_settings
|
72
|
-
self.config.runner_seed ENV[
|
71
|
+
self.config.runner_seed ENV["ASSERT_RUNNER_SEED"].to_i if ENV["ASSERT_RUNNER_SEED"]
|
73
72
|
end
|
74
73
|
|
75
74
|
def apply_option_settings(options)
|
@@ -111,13 +110,11 @@ module Assert
|
|
111
110
|
|
112
111
|
def path_of(segment, a_path)
|
113
112
|
# this method inspects a test path and finds the test dir path.
|
114
|
-
full_path = File.expand_path(a_path ||
|
113
|
+
full_path = File.expand_path(a_path || ".", Dir.pwd)
|
115
114
|
seg_pos = full_path.index(segment_regex(segment))
|
116
115
|
File.join(seg_pos && (seg_pos > 0) ? full_path[0..(seg_pos-1)] : full_path, segment)
|
117
116
|
end
|
118
117
|
|
119
118
|
def segment_regex(seg); /^#{seg}$|^#{seg}\/|\/#{seg}\/|\/#{seg}$/; end
|
120
|
-
|
121
119
|
end
|
122
|
-
|
123
120
|
end
|
data/lib/assert/assertions.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "assert/utils"
|
2
2
|
|
3
3
|
module Assert
|
4
|
-
|
5
4
|
module Assertions
|
5
|
+
IGNORED_ASSERTION_HELPERS =
|
6
|
+
[
|
7
|
+
:assert_throws, :assert_nothing_thrown,
|
8
|
+
:assert_operator, :refute_operator,
|
9
|
+
:assert_in_epsilon, :refute_in_epsilon,
|
10
|
+
:assert_in_delta, :refute_in_delta,
|
11
|
+
:assert_send
|
12
|
+
]
|
6
13
|
|
7
14
|
def assert_block(desc = nil)
|
8
15
|
assert(yield, desc){ "Expected block to return a true value." }
|
@@ -27,7 +34,7 @@ module Assert
|
|
27
34
|
alias_method :refute_empty, :assert_not_empty
|
28
35
|
|
29
36
|
def assert_equal(exp, act, desc = nil)
|
30
|
-
assert(
|
37
|
+
assert(act == exp, desc) do
|
31
38
|
c = __assert_config__
|
32
39
|
exp_show = Assert::U.show_for_diff(exp, c)
|
33
40
|
act_show = Assert::U.show_for_diff(act, c)
|
@@ -42,7 +49,7 @@ module Assert
|
|
42
49
|
end
|
43
50
|
|
44
51
|
def assert_not_equal(exp, act, desc = nil)
|
45
|
-
assert(
|
52
|
+
assert(act != exp, desc) do
|
46
53
|
c = __assert_config__
|
47
54
|
exp_show = Assert::U.show_for_diff(exp, c)
|
48
55
|
act_show = Assert::U.show_for_diff(act, c)
|
@@ -214,8 +221,8 @@ module Assert
|
|
214
221
|
c = __assert_config__
|
215
222
|
exp_show = Assert::U.show_for_diff(exp, c)
|
216
223
|
act_show = Assert::U.show_for_diff(act, c)
|
217
|
-
exp_id = "#<#{exp.class}:#{
|
218
|
-
act_id = "#<#{act.class}:#{
|
224
|
+
exp_id = "#<#{exp.class}:#{"0x0%x" % (exp.object_id << 1)}>"
|
225
|
+
act_id = "#<#{act.class}:#{"0x0%x" % (act.object_id << 1)}>"
|
219
226
|
|
220
227
|
if c.use_diff_proc.call(exp_show, act_show)
|
221
228
|
"Expected #{act_id} to be the same as #{exp_id}, diff:\n"\
|
@@ -232,8 +239,8 @@ module Assert
|
|
232
239
|
c = __assert_config__
|
233
240
|
exp_show = Assert::U.show_for_diff(exp, c)
|
234
241
|
act_show = Assert::U.show_for_diff(act, c)
|
235
|
-
exp_id = "#<#{exp.class}:#{
|
236
|
-
act_id = "#<#{act.class}:#{
|
242
|
+
exp_id = "#<#{exp.class}:#{"0x0%x" % (exp.object_id << 1)}>"
|
243
|
+
act_id = "#<#{act.class}:#{"0x0%x" % (act.object_id << 1)}>"
|
237
244
|
|
238
245
|
if c.use_diff_proc.call(exp_show, act_show)
|
239
246
|
"Expected #{act_id} to not be the same as #{exp_id}, diff:\n"\
|
@@ -246,24 +253,6 @@ module Assert
|
|
246
253
|
end
|
247
254
|
alias_method :refute_same, :assert_not_same
|
248
255
|
|
249
|
-
# ignored assertion helpers
|
250
|
-
|
251
|
-
IGNORED_ASSERTION_HELPERS = [
|
252
|
-
:assert_throws, :assert_nothing_thrown,
|
253
|
-
:assert_operator, :refute_operator,
|
254
|
-
:assert_in_epsilon, :refute_in_epsilon,
|
255
|
-
:assert_in_delta, :refute_in_delta,
|
256
|
-
:assert_send
|
257
|
-
]
|
258
|
-
def method_missing(method, *args, &block)
|
259
|
-
if IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
|
260
|
-
ignore "The assertion `#{method}` is not supported."\
|
261
|
-
" Please use another assertion or the basic `assert`."
|
262
|
-
else
|
263
|
-
super
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
256
|
private
|
268
257
|
|
269
258
|
def __assert_config__
|
@@ -328,7 +317,5 @@ module Assert
|
|
328
317
|
super("exception not expected, but raised:")
|
329
318
|
end
|
330
319
|
end
|
331
|
-
|
332
320
|
end
|
333
|
-
|
334
321
|
end
|
data/lib/assert/cli.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "benchmark"
|
2
|
+
require "set"
|
3
|
+
require "assert/assert_runner"
|
4
|
+
require "assert/version"
|
5
5
|
|
6
6
|
module Assert
|
7
|
-
|
8
7
|
class CLI
|
9
|
-
|
10
8
|
def self.debug?(args)
|
11
|
-
args.include?(
|
9
|
+
args.include?("-d") || args.include?("--debug")
|
12
10
|
end
|
13
11
|
|
14
12
|
def self.debug_msg(msg)
|
@@ -36,40 +34,29 @@ module Assert
|
|
36
34
|
def initialize(*args)
|
37
35
|
@args = args
|
38
36
|
@cli = CLIRB.new do
|
39
|
-
option
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
option
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
option
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
option
|
58
|
-
|
59
|
-
|
60
|
-
option 'profile', 'output test profile info', {
|
61
|
-
:abbrev => 'e'
|
62
|
-
}
|
63
|
-
option 'verbose', 'output verbose runtime test info', {
|
64
|
-
:abbrev => 'v'
|
65
|
-
}
|
66
|
-
option 'list', 'list test files on $stdout', {
|
67
|
-
:abbrev => 'l'
|
68
|
-
}
|
37
|
+
option "runner_seed", "use a given seed to run tests",
|
38
|
+
abbrev: "s", value: Integer
|
39
|
+
option "changed_only", "only run test files with changes",
|
40
|
+
abbrev: "c"
|
41
|
+
option "changed_ref", "reference for changes, use with `-c` opt",
|
42
|
+
abbrev: "r", value: ""
|
43
|
+
option "single_test", "only run the test on the given file/line",
|
44
|
+
abbrev: "t", value: ""
|
45
|
+
option "pp_objects", "pretty-print objects in fail messages",
|
46
|
+
abbrev: "p"
|
47
|
+
option "capture_output", "capture stdout and display in result details",
|
48
|
+
abbrev: "o"
|
49
|
+
option "halt_on_fail", "halt a test when it fails",
|
50
|
+
abbrev: "h"
|
51
|
+
option "profile", "output test profile info",
|
52
|
+
abbrev: "e"
|
53
|
+
option "verbose", "output verbose runtime test info",
|
54
|
+
abbrev: "v"
|
55
|
+
option "list", "list test files on $stdout",
|
56
|
+
abbrev: "l"
|
57
|
+
|
69
58
|
# show loaded test files, cli err backtraces, etc
|
70
|
-
option
|
71
|
-
:abbrev => 'd'
|
72
|
-
}
|
59
|
+
option "debug", "run in debug mode", abbrev: "d"
|
73
60
|
end
|
74
61
|
end
|
75
62
|
|
@@ -100,7 +87,6 @@ module Assert
|
|
100
87
|
"Options:"\
|
101
88
|
"#{@cli}"
|
102
89
|
end
|
103
|
-
|
104
90
|
end
|
105
91
|
|
106
92
|
module RoundedMillisecondTime
|
@@ -111,20 +97,20 @@ module Assert
|
|
111
97
|
end
|
112
98
|
end
|
113
99
|
|
114
|
-
class CLIRB # Version 1.
|
100
|
+
class CLIRB # Version 1.1.0, https://github.com/redding/cli.rb
|
115
101
|
Error = Class.new(RuntimeError);
|
116
102
|
HelpExit = Class.new(RuntimeError); VersionExit = Class.new(RuntimeError)
|
117
103
|
attr_reader :argv, :args, :opts, :data
|
118
104
|
|
119
105
|
def initialize(&block)
|
120
106
|
@options = []; instance_eval(&block) if block
|
121
|
-
require
|
107
|
+
require "optparse"
|
122
108
|
@data, @args, @opts = [], [], {}; @parser = OptionParser.new do |p|
|
123
|
-
p.banner =
|
109
|
+
p.banner = ""; @options.each do |o|
|
124
110
|
@opts[o.name] = o.value; p.on(*o.parser_args){ |v| @opts[o.name] = v }
|
125
111
|
end
|
126
|
-
p.on_tail(
|
127
|
-
p.on_tail(
|
112
|
+
p.on_tail("--version", ""){ |v| raise VersionExit, v.to_s }
|
113
|
+
p.on_tail("--help", ""){ |v| raise HelpExit, v.to_s }
|
128
114
|
end
|
129
115
|
end
|
130
116
|
|
@@ -137,33 +123,31 @@ module Assert
|
|
137
123
|
end
|
138
124
|
def to_s; @parser.to_s; end
|
139
125
|
def inspect
|
140
|
-
"#<#{self.class}:#{
|
126
|
+
"#<#{self.class}:#{"0x0%x" % (object_id << 1)} @data=#{@data.inspect}>"
|
141
127
|
end
|
142
128
|
|
143
129
|
class Option
|
144
130
|
attr_reader :name, :opt_name, :desc, :abbrev, :value, :klass, :parser_args
|
145
131
|
|
146
|
-
def initialize(name,
|
147
|
-
|
148
|
-
@
|
149
|
-
@value, @klass = gvalinfo(
|
132
|
+
def initialize(name, desc = nil, abbrev: nil, value: nil)
|
133
|
+
@name, @desc = name, desc || ""
|
134
|
+
@opt_name, @abbrev = parse_name_values(name, abbrev)
|
135
|
+
@value, @klass = gvalinfo(value)
|
150
136
|
@parser_args = if [TrueClass, FalseClass, NilClass].include?(@klass)
|
151
137
|
["-#{@abbrev}", "--[no-]#{@opt_name}", @desc]
|
152
138
|
else
|
153
|
-
["-#{@abbrev}", "--#{@opt_name}
|
139
|
+
["-#{@abbrev}", "--#{@opt_name} VALUE", @klass, @desc]
|
154
140
|
end
|
155
141
|
end
|
156
142
|
|
157
143
|
private
|
158
144
|
|
159
145
|
def parse_name_values(name, custom_abbrev)
|
160
|
-
[ (processed_name = name.to_s.strip.downcase)
|
161
|
-
custom_abbrev || processed_name.gsub(/[^a-z]/,
|
146
|
+
[ (processed_name = name.to_s.strip.downcase).gsub("_", "-"),
|
147
|
+
custom_abbrev || processed_name.gsub(/[^a-z]/, "").chars.first || "a"
|
162
148
|
]
|
163
149
|
end
|
164
|
-
def gvalinfo(v); v.kind_of?(Class) ? [nil,
|
165
|
-
def gklass(k); k == Fixnum ? Integer : k; end
|
150
|
+
def gvalinfo(v); v.kind_of?(Class) ? [nil,v] : [v,v.class]; end
|
166
151
|
end
|
167
152
|
end
|
168
|
-
|
169
153
|
end
|
data/lib/assert/config.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "assert/default_runner"
|
2
|
+
require "assert/default_suite"
|
3
|
+
require "assert/default_view"
|
4
|
+
require "assert/file_line"
|
5
|
+
require "assert/utils"
|
6
6
|
|
7
7
|
module Assert
|
8
|
-
|
9
8
|
class Config
|
10
|
-
|
11
9
|
def self.settings(*items)
|
12
10
|
items.each do |item|
|
13
11
|
define_method(item) do |*args|
|
@@ -33,7 +31,7 @@ module Assert
|
|
33
31
|
|
34
32
|
@test_dir = "test"
|
35
33
|
@test_helper = "helper.rb"
|
36
|
-
@test_file_suffixes = [
|
34
|
+
@test_file_suffixes = ["_tests.rb", "_test.rb"]
|
37
35
|
|
38
36
|
@changed_proc = Assert::U.git_changed_proc
|
39
37
|
@pp_proc = Assert::U.stdlib_pp_proc
|
@@ -43,8 +41,8 @@ module Assert
|
|
43
41
|
# option settings
|
44
42
|
@runner_seed = begin; srand; srand % 0xFFFF; end.to_i
|
45
43
|
@changed_only = false
|
46
|
-
@changed_ref =
|
47
|
-
@single_test =
|
44
|
+
@changed_ref = ""
|
45
|
+
@single_test = ""
|
48
46
|
@pp_objects = false
|
49
47
|
@capture_output = false
|
50
48
|
@halt_on_fail = true
|
@@ -78,7 +76,5 @@ module Assert
|
|
78
76
|
def single_test_file_path
|
79
77
|
self.single_test_file_line.file if self.single_test_file_line
|
80
78
|
end
|
81
|
-
|
82
79
|
end
|
83
|
-
|
84
80
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module Assert
|
2
|
-
|
3
2
|
module ConfigHelpers
|
4
|
-
|
5
3
|
def runner; self.config.runner; end
|
6
4
|
def suite; self.config.suite; end
|
7
5
|
def view; self.config.view; end
|
@@ -33,27 +31,27 @@ module Assert
|
|
33
31
|
self.pass_result_count == self.result_count
|
34
32
|
end
|
35
33
|
|
36
|
-
def formatted_run_time(run_time, format =
|
34
|
+
def formatted_run_time(run_time, format = "%.6f")
|
37
35
|
format % run_time
|
38
36
|
end
|
39
37
|
|
40
|
-
def formatted_test_rate(test_rate, format =
|
38
|
+
def formatted_test_rate(test_rate, format = "%.6f")
|
41
39
|
format % test_rate
|
42
40
|
end
|
43
41
|
|
44
|
-
def formatted_result_rate(result_rate, format =
|
42
|
+
def formatted_result_rate(result_rate, format = "%.6f")
|
45
43
|
format % result_rate
|
46
44
|
end
|
47
45
|
|
48
|
-
def formatted_suite_run_time(format =
|
46
|
+
def formatted_suite_run_time(format = "%.6f")
|
49
47
|
formatted_run_time(self.config.suite.run_time, format)
|
50
48
|
end
|
51
49
|
|
52
|
-
def formatted_suite_test_rate(format =
|
50
|
+
def formatted_suite_test_rate(format = "%.6f")
|
53
51
|
formatted_test_rate(self.config.suite.test_rate, format)
|
54
52
|
end
|
55
53
|
|
56
|
-
def formatted_suite_result_rate(format =
|
54
|
+
def formatted_suite_result_rate(format = "%.6f")
|
57
55
|
formatted_result_rate(self.config.suite.result_rate, format)
|
58
56
|
end
|
59
57
|
|
@@ -77,7 +75,5 @@ module Assert
|
|
77
75
|
def get_rate(count, time)
|
78
76
|
time == 0 ? 0.0 : (count.to_f / time.to_f)
|
79
77
|
end
|
80
|
-
|
81
78
|
end
|
82
|
-
|
83
79
|
end
|
data/lib/assert/context.rb
CHANGED
@@ -1,22 +1,26 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
1
|
+
require "assert/actual_value"
|
2
|
+
require "assert/assertions"
|
3
|
+
require "assert/context/let_dsl"
|
4
|
+
require "assert/context/method_missing"
|
5
|
+
require "assert/context/setup_dsl"
|
6
|
+
require "assert/context/subject_dsl"
|
7
|
+
require "assert/context/suite_dsl"
|
8
|
+
require "assert/context/test_dsl"
|
9
|
+
require "assert/context_info"
|
10
|
+
require "assert/macros/methods"
|
11
|
+
require "assert/result"
|
12
|
+
require "assert/suite"
|
13
|
+
require "assert/utils"
|
11
14
|
|
12
15
|
module Assert
|
13
|
-
|
14
16
|
class Context
|
15
17
|
# put all logic in DSL methods to keep context instances pure for running tests
|
16
18
|
extend SetupDSL
|
17
19
|
extend SubjectDSL
|
18
20
|
extend SuiteDSL
|
19
21
|
extend TestDSL
|
22
|
+
extend LetDSL
|
23
|
+
include MethodMissing
|
20
24
|
include Assert::Assertions
|
21
25
|
include Assert::Macros::Methods
|
22
26
|
|
@@ -33,7 +37,7 @@ module Assert
|
|
33
37
|
klass_method_name = "#{self}##{method_name}"
|
34
38
|
|
35
39
|
if self.suite.test_methods.include?(klass_method_name)
|
36
|
-
puts "WARNING: redefining
|
40
|
+
puts "WARNING: redefining "#{klass_method_name}""
|
37
41
|
puts " from: #{caller_locations(1,1)}"
|
38
42
|
else
|
39
43
|
self.suite.test_methods << klass_method_name
|
@@ -62,9 +66,8 @@ module Assert
|
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
65
|
-
#
|
66
|
-
#
|
67
|
-
# all other assertion helpers use this one in the end
|
69
|
+
# Check if the result is true. If so, create a new pass result, Otherwise
|
70
|
+
# create a new fail result with the desc and fail msg.
|
68
71
|
def assert(assertion, desc = nil)
|
69
72
|
if assertion
|
70
73
|
pass
|
@@ -79,8 +82,8 @@ module Assert
|
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
82
|
-
#
|
83
|
-
# result
|
85
|
+
# The opposite of assert. Check if the result is false. If so, create a new
|
86
|
+
# pass result. Otherwise create a new fail result with the desc and fail msg.
|
84
87
|
def assert_not(assertion, fail_desc = nil)
|
85
88
|
assert(!assertion, fail_desc) do
|
86
89
|
"Failed assert_not: assertion was "\
|
@@ -89,6 +92,10 @@ module Assert
|
|
89
92
|
end
|
90
93
|
alias_method :refute, :assert_not
|
91
94
|
|
95
|
+
def assert_that(actual_value)
|
96
|
+
Assert::ActualValue.new(actual_value, context: self)
|
97
|
+
end
|
98
|
+
|
92
99
|
# adds a Pass result to the end of the test's results
|
93
100
|
# does not break test execution
|
94
101
|
def pass(pass_msg = nil)
|
@@ -111,15 +118,15 @@ module Assert
|
|
111
118
|
def fail(message = nil)
|
112
119
|
if @__assert_pending__ == 0
|
113
120
|
if halt_on_fail?
|
114
|
-
raise Result::TestFailure, message ||
|
121
|
+
raise Result::TestFailure, message || ""
|
115
122
|
else
|
116
|
-
capture_result(Assert::Result::Fail, message ||
|
123
|
+
capture_result(Assert::Result::Fail, message || "")
|
117
124
|
end
|
118
125
|
else
|
119
126
|
if halt_on_fail?
|
120
|
-
raise Result::TestSkipped, "Pending fail: #{message ||
|
127
|
+
raise Result::TestSkipped, "Pending fail: #{message || ""}"
|
121
128
|
else
|
122
|
-
capture_result(Assert::Result::Skip, "Pending fail: #{message ||
|
129
|
+
capture_result(Assert::Result::Skip, "Pending fail: #{message || ""}")
|
123
130
|
end
|
124
131
|
end
|
125
132
|
end
|
@@ -128,7 +135,7 @@ module Assert
|
|
128
135
|
# adds a Skip result to the end of the test's results
|
129
136
|
# breaks test execution
|
130
137
|
def skip(skip_msg = nil, called_from = nil)
|
131
|
-
raise Result::TestSkipped, (skip_msg ||
|
138
|
+
raise Result::TestSkipped, (skip_msg || ""), called_from
|
132
139
|
end
|
133
140
|
|
134
141
|
# runs block and any fails are skips and any passes are fails
|
@@ -172,7 +179,7 @@ module Assert
|
|
172
179
|
# Returns a Proc that will output a custom message along with the default
|
173
180
|
# fail message.
|
174
181
|
def fail_message(fail_desc = nil, what_failed_msg = nil)
|
175
|
-
[
|
182
|
+
[fail_desc, what_failed_msg].compact.join("\n")
|
176
183
|
end
|
177
184
|
|
178
185
|
private
|
@@ -190,6 +197,5 @@ module Assert
|
|
190
197
|
def __assert_config__
|
191
198
|
@__assert_config__
|
192
199
|
end
|
193
|
-
|
194
200
|
end
|
195
201
|
end
|