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
@@ -0,0 +1,13 @@
|
|
1
|
+
module Assert; end
|
2
|
+
class Assert::Context; end
|
3
|
+
module Assert::Context::LetDSL
|
4
|
+
def let(name, &block)
|
5
|
+
self.send(:define_method, name, &-> {
|
6
|
+
if instance_variable_get("@#{name}").nil?
|
7
|
+
instance_variable_set("@#{name}", instance_eval(&block))
|
8
|
+
end
|
9
|
+
|
10
|
+
instance_variable_get("@#{name}")
|
11
|
+
})
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "assert/assertions"
|
2
|
+
|
3
|
+
module Assert; end
|
4
|
+
class Assert::Context; end
|
5
|
+
module Assert::Context::MethodMissing
|
6
|
+
def method_missing(method, *args, &block)
|
7
|
+
if Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
|
8
|
+
ignore "The assertion `#{method}` is not supported."\
|
9
|
+
" Please use another assertion or the basic `assert`."
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to_missing?(method, *)
|
16
|
+
Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym) ||
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Assert; end
|
2
2
|
class Assert::Context
|
3
|
-
|
4
3
|
module SetupDSL
|
5
|
-
|
6
4
|
def setup_once(&block)
|
7
5
|
self.suite.setup(&block)
|
8
6
|
end
|
@@ -70,7 +68,5 @@ class Assert::Context
|
|
70
68
|
# ... before the parent
|
71
69
|
self.superclass.run_teardowns(scope) if self.superclass.respond_to?(:run_teardowns)
|
72
70
|
end
|
73
|
-
|
74
71
|
end
|
75
|
-
|
76
72
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
module Assert; end
|
2
2
|
class Assert::Context
|
3
|
-
|
4
3
|
module SubjectDSL
|
5
|
-
|
6
4
|
# Add a piece of description text or return the full description for the context
|
7
5
|
def description(text = nil)
|
8
6
|
if text
|
@@ -31,7 +29,5 @@ class Assert::Context
|
|
31
29
|
def descriptions
|
32
30
|
@descriptions ||= []
|
33
31
|
end
|
34
|
-
|
35
32
|
end
|
36
|
-
|
37
33
|
end
|
@@ -1,13 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "assert/context_info"
|
2
|
+
require "assert/macro"
|
3
|
+
require "assert/suite"
|
4
|
+
require "assert/test"
|
5
5
|
|
6
6
|
module Assert; end
|
7
7
|
class Assert::Context
|
8
|
-
|
9
8
|
module TestDSL
|
10
|
-
|
11
9
|
def test(desc_or_macro, called_from = nil, first_caller = nil, &block)
|
12
10
|
if desc_or_macro.kind_of?(Assert::Macro)
|
13
11
|
instance_eval(&desc_or_macro)
|
@@ -31,7 +29,7 @@ class Assert::Context
|
|
31
29
|
desc_or_macro.kind_of?(Assert::Macro) ? desc_or_macro.name : desc_or_macro,
|
32
30
|
ci,
|
33
31
|
self.suite.config,
|
34
|
-
&proc { skip(
|
32
|
+
&proc { skip("TODO", [ci.called_from.to_s]) }
|
35
33
|
))
|
36
34
|
end
|
37
35
|
alias_method :test_skip, :test_eventually
|
@@ -50,7 +48,5 @@ class Assert::Context
|
|
50
48
|
test_eventually(desc_or_macro, called_from, first_caller || caller_locations.first, &block)
|
51
49
|
end
|
52
50
|
alias_method :should_skip, :should_eventually
|
53
|
-
|
54
51
|
end
|
55
|
-
|
56
52
|
end
|
data/lib/assert/context_info.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
module Assert
|
2
|
-
|
3
2
|
class ContextInfo
|
4
|
-
|
5
3
|
attr_reader :called_from, :klass, :file
|
6
4
|
|
7
5
|
def initialize(klass, called_from = nil, first_caller = nil)
|
8
6
|
@called_from = called_from || first_caller
|
9
7
|
@klass = klass
|
10
|
-
@file = @called_from.to_s.gsub(/\:[0-9]+.*$/,
|
8
|
+
@file = @called_from.to_s.gsub(/\:[0-9]+.*$/, "") if @called_from
|
11
9
|
end
|
12
10
|
|
13
11
|
def test_name(name)
|
14
|
-
[klass.description.to_s, name.to_s].compact.reject(&:empty?).join(
|
12
|
+
[klass.description.to_s, name.to_s].compact.reject(&:empty?).join(" ")
|
15
13
|
end
|
16
|
-
|
17
14
|
end
|
18
|
-
|
19
15
|
end
|
data/lib/assert/default_suite.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "assert/suite"
|
2
2
|
|
3
3
|
module Assert
|
4
|
-
|
5
4
|
# This is the default suite used by assert. In addition to the base suite
|
6
5
|
# behavior, it accumulates test/result counts in memory. This data is used
|
7
6
|
# by the runner/view for handling and presentation purposes.
|
8
|
-
|
9
7
|
class DefaultSuite < Assert::Suite
|
10
|
-
|
11
8
|
def initialize(config)
|
12
9
|
super
|
13
10
|
reset_run_data
|
@@ -53,7 +50,5 @@ module Assert
|
|
53
50
|
@skip_result_count = 0
|
54
51
|
@ignore_result_count = 0
|
55
52
|
end
|
56
|
-
|
57
53
|
end
|
58
|
-
|
59
54
|
end
|
data/lib/assert/default_view.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "assert/view"
|
2
|
+
require "assert/view_helpers"
|
3
3
|
|
4
4
|
module Assert
|
5
|
-
|
6
5
|
# This is the default view used by assert. It renders ansi test output
|
7
6
|
# designed for terminal viewing.
|
8
|
-
|
9
7
|
class DefaultView < Assert::View
|
10
8
|
include Assert::ViewHelpers::Ansi
|
11
9
|
|
12
10
|
# setup options and their default values
|
13
11
|
|
14
|
-
option
|
15
|
-
option
|
16
|
-
option
|
17
|
-
option
|
18
|
-
option
|
19
|
-
option
|
12
|
+
option "styled", true
|
13
|
+
option "pass_styles", :green
|
14
|
+
option "fail_styles", :red, :bold
|
15
|
+
option "error_styles", :yellow, :bold
|
16
|
+
option "skip_styles", :cyan
|
17
|
+
option "ignore_styles", :magenta
|
20
18
|
|
21
19
|
def before_load(test_files)
|
22
20
|
end
|
@@ -184,7 +182,5 @@ module Assert
|
|
184
182
|
end
|
185
183
|
end
|
186
184
|
end
|
187
|
-
|
188
185
|
end
|
189
|
-
|
190
186
|
end
|
data/lib/assert/factory.rb
CHANGED
data/lib/assert/file_line.rb
CHANGED
data/lib/assert/macro.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
module Assert
|
2
2
|
class Macro < ::Proc
|
3
|
-
|
4
3
|
# this class is essentially a way to define a custom set of tests using
|
5
|
-
# arguments. When passed as an argument to the
|
4
|
+
# arguments. When passed as an argument to the "should" method, a macro
|
6
5
|
# will be instance_eval'd in that Assert::Context.
|
7
|
-
|
8
6
|
attr_accessor :name
|
9
7
|
|
10
8
|
def initialize(name = nil, *args, &block)
|
@@ -12,6 +10,5 @@ module Assert
|
|
12
10
|
@name = name || "run this macro"
|
13
11
|
super()
|
14
12
|
end
|
15
|
-
|
16
13
|
end
|
17
14
|
end
|
@@ -1,14 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "assert/macro"
|
2
2
|
|
3
3
|
module Assert::Macros
|
4
4
|
module Methods
|
5
|
-
|
6
5
|
def self.included(receiver)
|
7
6
|
receiver.send(:extend, ClassMethods)
|
8
7
|
end
|
9
8
|
|
10
9
|
module ClassMethods
|
11
|
-
|
12
10
|
def have_instance_method(*methods)
|
13
11
|
called_from = (methods.last.kind_of?(Array) ? methods.pop : caller_locations).first
|
14
12
|
Assert::Macro.new do
|
@@ -101,35 +99,33 @@ module Assert::Macros
|
|
101
99
|
|
102
100
|
def _methods_macro_test(called_from)
|
103
101
|
@_methods_macro_test ||= test "should respond to methods", called_from do
|
104
|
-
|
105
102
|
self.class._methods_macro_instance_methods.each do |(method, called_from)|
|
106
103
|
msg = "#{subject.class.name} does not have instance method ##{method}"
|
107
104
|
with_backtrace([called_from]) do
|
108
|
-
|
105
|
+
assert_that(subject).responds_to(method, msg)
|
109
106
|
end
|
110
107
|
end
|
111
108
|
|
112
109
|
self.class._methods_macro_class_methods.each do |(method, called_from)|
|
113
110
|
msg = "#{subject.class.name} does not have class method ##{method}"
|
114
111
|
with_backtrace([called_from]) do
|
115
|
-
|
112
|
+
assert_that(subject.class).responds_to(method, msg)
|
116
113
|
end
|
117
114
|
end
|
118
115
|
|
119
116
|
self.class._methods_macro_not_instance_methods.each do |(method, called_from)|
|
120
117
|
msg = "#{subject.class.name} has instance method ##{method}"
|
121
118
|
with_backtrace([called_from]) do
|
122
|
-
|
119
|
+
assert_that(subject).does_not_respond_to(method, msg)
|
123
120
|
end
|
124
121
|
end
|
125
122
|
|
126
123
|
self.class._methods_macro_not_class_methods.each do |(method, called_from)|
|
127
124
|
msg = "#{subject.class.name} has class method ##{method}"
|
128
125
|
with_backtrace([called_from]) do
|
129
|
-
|
126
|
+
assert_that(subject.class).does_not_respond_to(method, msg)
|
130
127
|
end
|
131
128
|
end
|
132
|
-
|
133
129
|
end
|
134
130
|
end
|
135
131
|
|
@@ -148,8 +144,6 @@ module Assert::Macros
|
|
148
144
|
def _methods_macro_not_class_methods
|
149
145
|
@_methods_macro_not_class_methods ||= []
|
150
146
|
end
|
151
|
-
|
152
147
|
end
|
153
|
-
|
154
148
|
end
|
155
149
|
end
|
data/lib/assert/result.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "assert/file_line"
|
2
2
|
|
3
3
|
module Assert; end
|
4
4
|
module Assert::Result
|
5
|
-
|
6
5
|
class Base ; end
|
7
6
|
class Pass < Base ; end
|
8
7
|
class Ignore < Base ; end
|
@@ -26,9 +25,8 @@ module Assert::Result
|
|
26
25
|
end
|
27
26
|
|
28
27
|
class Base
|
29
|
-
|
30
28
|
def self.type; :unknown; end
|
31
|
-
def self.name;
|
29
|
+
def self.name; ""; end
|
32
30
|
|
33
31
|
def self.for_test(test, message, bt)
|
34
32
|
self.new({
|
@@ -54,11 +52,11 @@ module Assert::Result
|
|
54
52
|
end
|
55
53
|
|
56
54
|
def test_name
|
57
|
-
@test_name ||= (@build_data[:test_name] ||
|
55
|
+
@test_name ||= (@build_data[:test_name] || "")
|
58
56
|
end
|
59
57
|
|
60
58
|
def test_file_line
|
61
|
-
@test_file_line ||= (@build_data[:test_file_line] || Assert::FileLine.parse(
|
59
|
+
@test_file_line ||= (@build_data[:test_file_line] || Assert::FileLine.parse(""))
|
62
60
|
end
|
63
61
|
|
64
62
|
def test_file_name; self.test_file_line.file; end
|
@@ -69,11 +67,11 @@ module Assert::Result
|
|
69
67
|
end
|
70
68
|
|
71
69
|
def message
|
72
|
-
@message ||= (@build_data[:message] ||
|
70
|
+
@message ||= (@build_data[:message] || "")
|
73
71
|
end
|
74
72
|
|
75
73
|
def output
|
76
|
-
@output ||= (@build_data[:output] ||
|
74
|
+
@output ||= (@build_data[:output] || "")
|
77
75
|
end
|
78
76
|
|
79
77
|
def backtrace
|
@@ -135,7 +133,7 @@ module Assert::Result
|
|
135
133
|
end
|
136
134
|
|
137
135
|
def inspect
|
138
|
-
"#<#{self.class}:#{
|
136
|
+
"#<#{self.class}:#{"0x0%x" % (object_id << 1)} "\
|
139
137
|
"@message=#{self.message.inspect} "\
|
140
138
|
"@file_line=#{self.file_line.to_s.inspect} "\
|
141
139
|
"@test_file_line=#{self.test_file_line.to_s.inspect}>"
|
@@ -156,7 +154,7 @@ module Assert::Result
|
|
156
154
|
end
|
157
155
|
|
158
156
|
# if the filtered backtrace is empty, just use the backtrace itself (this
|
159
|
-
# should only occur if the result is an error from a line in
|
157
|
+
# should only occur if the result is an error from a line in Assert's
|
160
158
|
# non-test code).
|
161
159
|
def first_filtered_bt_line(backtrace)
|
162
160
|
((fbt = backtrace.filtered).empty? ? backtrace : fbt).first.to_s
|
@@ -164,30 +162,25 @@ module Assert::Result
|
|
164
162
|
end
|
165
163
|
|
166
164
|
class Pass < Base
|
167
|
-
|
168
165
|
def self.type; :pass; end
|
169
|
-
def self.name;
|
170
|
-
|
166
|
+
def self.name; "Pass"; end
|
171
167
|
end
|
172
168
|
|
173
169
|
class Ignore < Base
|
174
|
-
|
175
170
|
def self.type; :ignore; end
|
176
|
-
def self.name;
|
177
|
-
|
171
|
+
def self.name; "Ignore"; end
|
178
172
|
end
|
179
173
|
|
180
174
|
class HaltingTestResultError < RuntimeError
|
181
175
|
attr_accessor :assert_with_bt
|
182
176
|
end
|
183
177
|
|
184
|
-
# raised by the
|
178
|
+
# raised by the "fail" context helper to break test execution
|
185
179
|
TestFailure = Class.new(HaltingTestResultError)
|
186
180
|
|
187
181
|
class Fail < Base
|
188
|
-
|
189
182
|
def self.type; :fail; end
|
190
|
-
def self.name;
|
183
|
+
def self.name; "Fail"; end
|
191
184
|
|
192
185
|
# fail results can be generated manually or by raising Assert::Result::TestFailure
|
193
186
|
def self.for_test(test, msg_or_err, bt = nil)
|
@@ -201,16 +194,14 @@ module Assert::Result
|
|
201
194
|
super(test, msg_or_err, bt)
|
202
195
|
end
|
203
196
|
end
|
204
|
-
|
205
197
|
end
|
206
198
|
|
207
|
-
# raised by the
|
199
|
+
# raised by the "skip" context helper to break test execution
|
208
200
|
TestSkipped = Class.new(HaltingTestResultError)
|
209
201
|
|
210
202
|
class Skip < Base
|
211
|
-
|
212
203
|
def self.type; :skip; end
|
213
|
-
def self.name;
|
204
|
+
def self.name; "Skip"; end
|
214
205
|
|
215
206
|
# skip results are generated by raising Assert::Result::TestSkipped
|
216
207
|
def self.for_test(test, msg_or_err, bt = nil)
|
@@ -224,13 +215,11 @@ module Assert::Result
|
|
224
215
|
super(test, msg_or_err, bt)
|
225
216
|
end
|
226
217
|
end
|
227
|
-
|
228
218
|
end
|
229
219
|
|
230
220
|
class Error < Base
|
231
|
-
|
232
221
|
def self.type; :error; end
|
233
|
-
def self.name;
|
222
|
+
def self.name; "Error"; end
|
234
223
|
|
235
224
|
# error results are generated by raising exceptions in tests
|
236
225
|
def self.for_test(test, err)
|
@@ -247,11 +236,9 @@ module Assert::Result
|
|
247
236
|
def build_trace
|
248
237
|
Backtrace.to_s(backtrace)
|
249
238
|
end
|
250
|
-
|
251
239
|
end
|
252
240
|
|
253
241
|
class Backtrace < ::Array
|
254
|
-
|
255
242
|
DELIM = "\n".freeze
|
256
243
|
|
257
244
|
def self.parse(bt)
|
@@ -272,18 +259,16 @@ module Assert::Result
|
|
272
259
|
|
273
260
|
protected
|
274
261
|
|
275
|
-
# filter a line out if it's an
|
262
|
+
# filter a line out if it's an Assert lib/bin line
|
276
263
|
def filter_out?(line)
|
277
|
-
#
|
278
|
-
assert_lib_path = File.expand_path(
|
279
|
-
assert_macros_path = File.join(assert_lib_path,
|
264
|
+
# "./lib" in project dir, or "/usr/local/blahblah" if installed
|
265
|
+
assert_lib_path = File.expand_path("../..", __FILE__)
|
266
|
+
assert_macros_path = File.join(assert_lib_path, "assert/macros")
|
280
267
|
assert_bin_regex = /bin\/assert\:/
|
281
268
|
( line.rindex(assert_lib_path, 0) &&
|
282
269
|
!line.rindex(assert_macros_path, 0)
|
283
270
|
) ||
|
284
271
|
line =~ assert_bin_regex
|
285
272
|
end
|
286
|
-
|
287
273
|
end
|
288
|
-
|
289
274
|
end
|