assert 2.17.0 → 2.18.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/README.md +66 -41
- data/assert.gemspec +2 -3
- data/lib/assert.rb +0 -10
- data/lib/assert/actual_value.rb +127 -0
- data/lib/assert/assert_runner.rb +0 -3
- data/lib/assert/assertions.rb +10 -23
- data/lib/assert/cli.rb +30 -46
- data/lib/assert/config.rb +0 -4
- data/lib/assert/config_helpers.rb +0 -4
- data/lib/assert/context.rb +18 -9
- 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 +23 -28
- data/lib/assert/context/suite_dsl.rb +0 -4
- data/lib/assert/context/test_dsl.rb +0 -4
- data/lib/assert/context_info.rb +0 -4
- data/lib/assert/default_runner.rb +0 -4
- data/lib/assert/default_suite.rb +0 -5
- data/lib/assert/default_view.rb +0 -4
- data/lib/assert/factory.rb +0 -3
- data/lib/assert/file_line.rb +0 -4
- data/lib/assert/macro.rb +0 -3
- data/lib/assert/macros/methods.rb +4 -10
- data/lib/assert/result.rb +2 -17
- data/lib/assert/runner.rb +0 -3
- data/lib/assert/stub.rb +15 -1
- data/lib/assert/suite.rb +0 -4
- data/lib/assert/test.rb +2 -7
- data/lib/assert/utils.rb +0 -4
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +0 -3
- data/lib/assert/view_helpers.rb +0 -11
- data/log/{.gitkeep → .keep} +0 -0
- data/test/helper.rb +23 -29
- data/test/support/factory.rb +14 -0
- data/test/support/inherited_stuff.rb +0 -2
- data/test/system/stub_tests.rb +332 -352
- data/test/system/test_tests.rb +98 -124
- data/test/unit/actual_value_tests.rb +335 -0
- data/test/unit/assert_tests.rb +121 -46
- data/test/unit/assertions/assert_block_tests.rb +30 -35
- data/test/unit/assertions/assert_empty_tests.rb +33 -35
- data/test/unit/assertions/assert_equal_tests.rb +75 -83
- data/test/unit/assertions/assert_file_exists_tests.rb +32 -36
- data/test/unit/assertions/assert_includes_tests.rb +38 -41
- data/test/unit/assertions/assert_instance_of_tests.rb +34 -37
- data/test/unit/assertions/assert_kind_of_tests.rb +34 -37
- data/test/unit/assertions/assert_match_tests.rb +34 -37
- data/test/unit/assertions/assert_nil_tests.rb +30 -35
- data/test/unit/assertions/assert_raises_tests.rb +54 -60
- data/test/unit/assertions/assert_respond_to_tests.rb +36 -39
- data/test/unit/assertions/assert_same_tests.rb +86 -88
- data/test/unit/assertions/assert_true_false_tests.rb +60 -66
- data/test/unit/assertions_tests.rb +14 -17
- data/test/unit/config_helpers_tests.rb +41 -39
- data/test/unit/config_tests.rb +38 -37
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +68 -87
- data/test/unit/context/subject_dsl_tests.rb +15 -49
- data/test/unit/context/suite_dsl_tests.rb +15 -20
- data/test/unit/context/test_dsl_tests.rb +50 -57
- data/test/unit/context_info_tests.rb +23 -18
- data/test/unit/context_tests.rb +183 -194
- data/test/unit/default_runner_tests.rb +1 -7
- data/test/unit/default_suite_tests.rb +57 -56
- data/test/unit/factory_tests.rb +5 -6
- data/test/unit/file_line_tests.rb +33 -39
- data/test/unit/macro_tests.rb +14 -18
- data/test/unit/result_tests.rb +159 -196
- data/test/unit/runner_tests.rb +64 -71
- data/test/unit/suite_tests.rb +58 -59
- data/test/unit/test_tests.rb +125 -136
- data/test/unit/utils_tests.rb +43 -54
- data/test/unit/view_helpers_tests.rb +54 -58
- data/test/unit/view_tests.rb +22 -27
- metadata +15 -10
- data/tmp/.gitkeep +0 -0
data/lib/assert/config.rb
CHANGED
@@ -5,9 +5,7 @@ require "assert/file_line"
|
|
5
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|
|
@@ -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
|
@@ -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,4 +1,7 @@
|
|
1
|
+
require "assert/actual_value"
|
1
2
|
require "assert/assertions"
|
3
|
+
require "assert/context/let_dsl"
|
4
|
+
require "assert/context/method_missing"
|
2
5
|
require "assert/context/setup_dsl"
|
3
6
|
require "assert/context/subject_dsl"
|
4
7
|
require "assert/context/suite_dsl"
|
@@ -10,13 +13,14 @@ require "assert/suite"
|
|
10
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
|
|
@@ -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)
|
@@ -158,9 +165,12 @@ module Assert
|
|
158
165
|
end
|
159
166
|
|
160
167
|
def subject
|
161
|
-
|
162
|
-
|
168
|
+
unless instance_variable_defined?("@__assert_subject__")
|
169
|
+
@__assert_subject__ =
|
170
|
+
instance_eval(&self.class.subject) if self.class.subject
|
163
171
|
end
|
172
|
+
|
173
|
+
@__assert_subject__
|
164
174
|
end
|
165
175
|
|
166
176
|
def inspect
|
@@ -190,6 +200,5 @@ module Assert
|
|
190
200
|
def __assert_config__
|
191
201
|
@__assert_config__
|
192
202
|
end
|
193
|
-
|
194
203
|
end
|
195
204
|
end
|
@@ -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
|
+
unless instance_variable_defined?("@__assert_let_#{name}__")
|
7
|
+
instance_variable_set("@__assert_let_#{name}__", instance_eval(&block))
|
8
|
+
end
|
9
|
+
|
10
|
+
instance_variable_get("@__assert_let_#{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,37 +1,32 @@
|
|
1
1
|
module Assert; end
|
2
|
-
class Assert::Context
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
own = self.descriptions
|
13
|
-
[parent, *own].compact.reject(&:empty?).join(" ")
|
14
|
-
end
|
2
|
+
class Assert::Context; end
|
3
|
+
module Assert::Context::SubjectDSL
|
4
|
+
# Add a piece of description text or return the full description for the context
|
5
|
+
def description(text = nil)
|
6
|
+
if text
|
7
|
+
self.descriptions << text.to_s
|
8
|
+
else
|
9
|
+
parent = self.superclass.desc if self.superclass.respond_to?(:desc)
|
10
|
+
own = self.descriptions
|
11
|
+
[parent, *own].compact.reject(&:empty?).join(" ")
|
15
12
|
end
|
16
|
-
|
17
|
-
|
13
|
+
end
|
14
|
+
alias_method :desc, :description
|
15
|
+
alias_method :describe, :description
|
18
16
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
17
|
+
def subject(&block)
|
18
|
+
if block_given?
|
19
|
+
@subject = block
|
20
|
+
else
|
21
|
+
@subject || if superclass.respond_to?(:subject)
|
22
|
+
superclass.subject
|
26
23
|
end
|
27
24
|
end
|
25
|
+
end
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
def descriptions
|
32
|
-
@descriptions ||= []
|
33
|
-
end
|
27
|
+
protected
|
34
28
|
|
29
|
+
def descriptions
|
30
|
+
@descriptions ||= []
|
35
31
|
end
|
36
|
-
|
37
32
|
end
|
@@ -5,9 +5,7 @@ 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)
|
@@ -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,7 +1,5 @@
|
|
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)
|
@@ -13,7 +11,5 @@ module Assert
|
|
13
11
|
def test_name(name)
|
14
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
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
@@ -2,10 +2,8 @@ require "assert/view"
|
|
2
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
|
|
@@ -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
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
|
@@ -2,13 +2,11 @@ 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
@@ -2,7 +2,6 @@ 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,7 +25,6 @@ module Assert::Result
|
|
26
25
|
end
|
27
26
|
|
28
27
|
class Base
|
29
|
-
|
30
28
|
def self.type; :unknown; end
|
31
29
|
def self.name; ""; end
|
32
30
|
|
@@ -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,17 +162,13 @@ module Assert::Result
|
|
164
162
|
end
|
165
163
|
|
166
164
|
class Pass < Base
|
167
|
-
|
168
165
|
def self.type; :pass; end
|
169
166
|
def self.name; "Pass"; end
|
170
|
-
|
171
167
|
end
|
172
168
|
|
173
169
|
class Ignore < Base
|
174
|
-
|
175
170
|
def self.type; :ignore; end
|
176
171
|
def self.name; "Ignore"; end
|
177
|
-
|
178
172
|
end
|
179
173
|
|
180
174
|
class HaltingTestResultError < RuntimeError
|
@@ -185,7 +179,6 @@ module Assert::Result
|
|
185
179
|
TestFailure = Class.new(HaltingTestResultError)
|
186
180
|
|
187
181
|
class Fail < Base
|
188
|
-
|
189
182
|
def self.type; :fail; end
|
190
183
|
def self.name; "Fail"; end
|
191
184
|
|
@@ -201,14 +194,12 @@ module Assert::Result
|
|
201
194
|
super(test, msg_or_err, bt)
|
202
195
|
end
|
203
196
|
end
|
204
|
-
|
205
197
|
end
|
206
198
|
|
207
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
204
|
def self.name; "Skip"; end
|
214
205
|
|
@@ -224,11 +215,9 @@ 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
222
|
def self.name; "Error"; end
|
234
223
|
|
@@ -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,7 +259,7 @@ 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
264
|
# "./lib" in project dir, or "/usr/local/blahblah" if installed
|
278
265
|
assert_lib_path = File.expand_path("../..", __FILE__)
|
@@ -283,7 +270,5 @@ module Assert::Result
|
|
283
270
|
) ||
|
284
271
|
line =~ assert_bin_regex
|
285
272
|
end
|
286
|
-
|
287
273
|
end
|
288
|
-
|
289
274
|
end
|