assert 2.18.2 → 2.19.2
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/README.md +7 -6
- data/assert.gemspec +5 -2
- data/bin/assert +1 -0
- data/lib/assert.rb +2 -0
- data/lib/assert/actual_value.rb +143 -0
- data/lib/assert/assert_runner.rb +2 -0
- data/lib/assert/assertions.rb +82 -20
- data/lib/assert/cli.rb +2 -0
- data/lib/assert/config.rb +2 -0
- data/lib/assert/config_helpers.rb +2 -0
- data/lib/assert/context.rb +33 -37
- data/lib/assert/context/let_dsl.rb +16 -0
- data/lib/assert/context/method_missing.rb +22 -0
- data/lib/assert/context/setup_dsl.rb +3 -0
- data/lib/assert/context/subject_dsl.rb +26 -24
- data/lib/assert/context/suite_dsl.rb +3 -0
- data/lib/assert/context/test_dsl.rb +3 -0
- data/lib/assert/context_info.rb +2 -0
- data/lib/assert/default_runner.rb +2 -0
- data/lib/assert/default_suite.rb +2 -0
- data/lib/assert/default_view.rb +2 -0
- data/lib/assert/factory.rb +2 -0
- data/lib/assert/file_line.rb +2 -0
- data/lib/assert/macro.rb +2 -0
- data/lib/assert/macros/methods.rb +6 -4
- data/lib/assert/result.rb +8 -1
- data/lib/assert/runner.rb +2 -0
- data/lib/assert/stub.rb +45 -0
- data/lib/assert/suite.rb +9 -10
- data/lib/assert/test.rb +3 -9
- data/lib/assert/utils.rb +3 -1
- data/lib/assert/version.rb +3 -1
- data/lib/assert/view.rb +2 -0
- data/lib/assert/view_helpers.rb +2 -0
- data/test/helper.rb +28 -28
- data/test/support/factory.rb +17 -0
- data/test/support/inherited_stuff.rb +2 -0
- data/test/system/stub_tests.rb +334 -333
- data/test/system/test_tests.rb +101 -109
- data/test/unit/actual_value_tests.rb +373 -0
- data/test/unit/assert_tests.rb +79 -61
- data/test/unit/assertions/assert_block_tests.rb +32 -31
- data/test/unit/assertions/assert_changes_tests.rb +99 -0
- data/test/unit/assertions/assert_empty_tests.rb +35 -32
- data/test/unit/assertions/assert_equal_tests.rb +96 -74
- data/test/unit/assertions/assert_file_exists_tests.rb +34 -33
- data/test/unit/assertions/assert_includes_tests.rb +40 -37
- data/test/unit/assertions/assert_instance_of_tests.rb +36 -33
- data/test/unit/assertions/assert_kind_of_tests.rb +36 -33
- data/test/unit/assertions/assert_match_tests.rb +36 -33
- data/test/unit/assertions/assert_nil_tests.rb +32 -31
- data/test/unit/assertions/assert_raises_tests.rb +57 -55
- data/test/unit/assertions/assert_respond_to_tests.rb +38 -35
- data/test/unit/assertions/assert_same_tests.rb +88 -81
- data/test/unit/assertions/assert_true_false_tests.rb +62 -60
- data/test/unit/assertions_tests.rb +28 -24
- data/test/unit/config_helpers_tests.rb +45 -38
- data/test/unit/config_tests.rb +40 -34
- data/test/unit/context/let_dsl_tests.rb +12 -0
- data/test/unit/context/setup_dsl_tests.rb +72 -81
- data/test/unit/context/subject_dsl_tests.rb +17 -43
- data/test/unit/context/suite_dsl_tests.rb +17 -16
- data/test/unit/context/test_dsl_tests.rb +52 -52
- data/test/unit/context_info_tests.rb +25 -15
- data/test/unit/context_tests.rb +186 -179
- data/test/unit/default_runner_tests.rb +4 -5
- data/test/unit/default_suite_tests.rb +59 -53
- data/test/unit/factory_tests.rb +7 -3
- data/test/unit/file_line_tests.rb +35 -35
- data/test/unit/macro_tests.rb +16 -10
- data/test/unit/result_tests.rb +161 -183
- data/test/unit/runner_tests.rb +67 -65
- data/test/unit/suite_tests.rb +58 -59
- data/test/unit/test_tests.rb +120 -139
- data/test/unit/utils_tests.rb +45 -45
- data/test/unit/view_helpers_tests.rb +56 -52
- data/test/unit/view_tests.rb +24 -23
- metadata +29 -6
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Assert; end
|
4
|
+
class Assert::Context; end
|
5
|
+
|
6
|
+
module Assert::Context::LetDSL
|
7
|
+
def let(name, &block)
|
8
|
+
self.send(:define_method, name, &-> {
|
9
|
+
unless instance_variable_defined?("@__assert_let_#{name}__")
|
10
|
+
instance_variable_set("@__assert_let_#{name}__", instance_eval(&block))
|
11
|
+
end
|
12
|
+
|
13
|
+
instance_variable_get("@__assert_let_#{name}__")
|
14
|
+
})
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "assert/assertions"
|
4
|
+
|
5
|
+
module Assert; end
|
6
|
+
class Assert::Context; end
|
7
|
+
|
8
|
+
module Assert::Context::MethodMissing
|
9
|
+
def method_missing(method, *args, &block)
|
10
|
+
if Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym)
|
11
|
+
ignore "The assertion `#{method}` is not supported."\
|
12
|
+
" Please use another assertion or the basic `assert`."
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def respond_to_missing?(method, *)
|
19
|
+
Assert::Assertions::IGNORED_ASSERTION_HELPERS.include?(method.to_sym) ||
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
@@ -1,33 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Assert; end
|
2
|
-
class Assert::Context
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
class Assert::Context; end
|
5
|
+
|
6
|
+
module Assert::Context::SubjectDSL
|
7
|
+
# Add a piece of description text or return the full description for the context
|
8
|
+
def description(text = nil)
|
9
|
+
if text
|
10
|
+
self.descriptions << text.to_s
|
11
|
+
else
|
12
|
+
parent = self.superclass.desc if self.superclass.respond_to?(:desc)
|
13
|
+
own = self.descriptions
|
14
|
+
[parent, *own].compact.reject(&:empty?).join(" ")
|
13
15
|
end
|
14
|
-
|
15
|
-
|
16
|
+
end
|
17
|
+
alias_method :desc, :description
|
18
|
+
alias_method :describe, :description
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
20
|
+
def subject(&block)
|
21
|
+
if block_given?
|
22
|
+
@subject = block
|
23
|
+
else
|
24
|
+
@subject || if superclass.respond_to?(:subject)
|
25
|
+
superclass.subject
|
24
26
|
end
|
25
27
|
end
|
28
|
+
end
|
26
29
|
|
27
|
-
|
30
|
+
protected
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
+
def descriptions
|
33
|
+
@descriptions ||= []
|
32
34
|
end
|
33
35
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert/context_info"
|
2
4
|
require "assert/macro"
|
3
5
|
require "assert/suite"
|
4
6
|
require "assert/test"
|
5
7
|
|
6
8
|
module Assert; end
|
9
|
+
|
7
10
|
class Assert::Context
|
8
11
|
module TestDSL
|
9
12
|
def test(desc_or_macro, called_from = nil, first_caller = nil, &block)
|
data/lib/assert/context_info.rb
CHANGED
data/lib/assert/default_suite.rb
CHANGED
data/lib/assert/default_view.rb
CHANGED
data/lib/assert/factory.rb
CHANGED
data/lib/assert/file_line.rb
CHANGED
data/lib/assert/macro.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert/macro"
|
2
4
|
|
3
5
|
module Assert::Macros
|
@@ -102,28 +104,28 @@ module Assert::Macros
|
|
102
104
|
self.class._methods_macro_instance_methods.each do |(method, called_from)|
|
103
105
|
msg = "#{subject.class.name} does not have instance method ##{method}"
|
104
106
|
with_backtrace([called_from]) do
|
105
|
-
|
107
|
+
assert_that(subject).responds_to(method, msg)
|
106
108
|
end
|
107
109
|
end
|
108
110
|
|
109
111
|
self.class._methods_macro_class_methods.each do |(method, called_from)|
|
110
112
|
msg = "#{subject.class.name} does not have class method ##{method}"
|
111
113
|
with_backtrace([called_from]) do
|
112
|
-
|
114
|
+
assert_that(subject.class).responds_to(method, msg)
|
113
115
|
end
|
114
116
|
end
|
115
117
|
|
116
118
|
self.class._methods_macro_not_instance_methods.each do |(method, called_from)|
|
117
119
|
msg = "#{subject.class.name} has instance method ##{method}"
|
118
120
|
with_backtrace([called_from]) do
|
119
|
-
|
121
|
+
assert_that(subject).does_not_respond_to(method, msg)
|
120
122
|
end
|
121
123
|
end
|
122
124
|
|
123
125
|
self.class._methods_macro_not_class_methods.each do |(method, called_from)|
|
124
126
|
msg = "#{subject.class.name} has class method ##{method}"
|
125
127
|
with_backtrace([called_from]) do
|
126
|
-
|
128
|
+
assert_that(subject.class).does_not_respond_to(method, msg)
|
127
129
|
end
|
128
130
|
end
|
129
131
|
end
|
data/lib/assert/result.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert/file_line"
|
2
4
|
|
3
5
|
module Assert; end
|
6
|
+
|
4
7
|
module Assert::Result
|
5
8
|
class Base ; end
|
6
9
|
class Pass < Base ; end
|
@@ -129,7 +132,11 @@ module Assert::Result
|
|
129
132
|
end
|
130
133
|
|
131
134
|
def ==(other_result)
|
132
|
-
|
135
|
+
if other_result.is_a?(self.class)
|
136
|
+
self.type == other_result.type && self.message == other_result.message
|
137
|
+
else
|
138
|
+
super
|
139
|
+
end
|
133
140
|
end
|
134
141
|
|
135
142
|
def inspect
|
data/lib/assert/runner.rb
CHANGED
data/lib/assert/stub.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "much-stub"
|
2
4
|
|
3
5
|
module Assert
|
@@ -9,6 +11,10 @@ module Assert
|
|
9
11
|
MuchStub.stub(*args, &block)
|
10
12
|
end
|
11
13
|
|
14
|
+
def self.stub_on_call(*args, &block)
|
15
|
+
MuchStub.stub_on_call(*args, &block)
|
16
|
+
end
|
17
|
+
|
12
18
|
def self.unstub(*args)
|
13
19
|
MuchStub.unstub(*args)
|
14
20
|
end
|
@@ -38,4 +44,43 @@ module Assert
|
|
38
44
|
def self.stub_spy(*args, &block)
|
39
45
|
MuchStub.spy(*args, &block)
|
40
46
|
end
|
47
|
+
|
48
|
+
StubCall = MuchStub::Call
|
49
|
+
class StubCall
|
50
|
+
def self.name
|
51
|
+
super.gsub("MuchStub::Call", "Assert::StubCall")
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.to_s
|
55
|
+
super.gsub("MuchStub::Call", "Assert::StubCall")
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.inspect
|
59
|
+
super.gsub("MuchStub::Call", "Assert::StubCall")
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspect
|
63
|
+
super.gsub("MuchStub::Call", "Assert::StubCall")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
StubCallSpy = MuchStub::CallSpy
|
68
|
+
class StubCallSpy
|
69
|
+
def self.name
|
70
|
+
super.gsub("MuchStub::CallSpy", "Assert::StubCallSpy")
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.to_s
|
74
|
+
super.gsub("MuchStub::CallSpy", "Assert::StubCallSpy")
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.inspect
|
78
|
+
super.gsub("MuchStub::CallSpy", "Assert::StubCallSpy")
|
79
|
+
end
|
80
|
+
|
81
|
+
# See MuchStub::CallSpy#inspect.
|
82
|
+
def inspect
|
83
|
+
"#<Assert::StubCallSpy:#{"0x0%x" % (self.__id__ << 1)}>"
|
84
|
+
end
|
85
|
+
end
|
41
86
|
end
|
data/lib/assert/suite.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert/config_helpers"
|
2
4
|
require "assert/test"
|
3
5
|
|
@@ -10,22 +12,19 @@ module Assert
|
|
10
12
|
class Suite
|
11
13
|
include Assert::ConfigHelpers
|
12
14
|
|
13
|
-
TEST_METHOD_REGEX = /^test./.freeze
|
14
|
-
|
15
15
|
# A suite is a set of tests to run. When a test class subclasses
|
16
16
|
# the Context class, that test class is pushed to the suite.
|
17
17
|
|
18
|
-
attr_reader :config, :
|
18
|
+
attr_reader :config, :setups, :teardowns
|
19
19
|
attr_accessor :start_time, :end_time
|
20
20
|
|
21
21
|
def initialize(config)
|
22
|
-
@config
|
23
|
-
@tests
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@
|
28
|
-
@end_time = @start_time
|
22
|
+
@config = config
|
23
|
+
@tests = []
|
24
|
+
@setups = []
|
25
|
+
@teardowns = []
|
26
|
+
@start_time = Time.now
|
27
|
+
@end_time = @start_time
|
29
28
|
end
|
30
29
|
|
31
30
|
def suite; self; end
|
data/lib/assert/test.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "stringio"
|
2
4
|
require "assert/file_line"
|
3
5
|
require "assert/result"
|
@@ -20,14 +22,6 @@ module Assert
|
|
20
22
|
}))
|
21
23
|
end
|
22
24
|
|
23
|
-
def self.for_method(method_name, context_info, config)
|
24
|
-
self.new(self.name_file_line_context_data(context_info, method_name).merge({
|
25
|
-
:context_info => context_info,
|
26
|
-
:config => config,
|
27
|
-
:code => proc{ self.send(method_name) }
|
28
|
-
}))
|
29
|
-
end
|
30
|
-
|
31
25
|
def initialize(build_data = nil)
|
32
26
|
@build_data = build_data || {}
|
33
27
|
@result_callback = nil
|
@@ -45,7 +39,7 @@ module Assert
|
|
45
39
|
end
|
46
40
|
|
47
41
|
def output
|
48
|
-
@output ||= (@build_data[:output] || "")
|
42
|
+
@output ||= (@build_data[:output] || +"")
|
49
43
|
end
|
50
44
|
|
51
45
|
def run_time
|
data/lib/assert/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
|
3
5
|
module Assert
|
@@ -29,7 +31,7 @@ module Assert
|
|
29
31
|
# Get a proc that uses stdlib `PP.pp` to pretty print objects
|
30
32
|
def self.stdlib_pp_proc(width = nil)
|
31
33
|
require "pp"
|
32
|
-
Proc.new{ |obj| PP.pp(obj, "", width || 79).strip }
|
34
|
+
Proc.new{ |obj| PP.pp(obj, +"", width || 79).strip }
|
33
35
|
end
|
34
36
|
|
35
37
|
# Return true if if either show output has newlines or is bigger than 29 chars
|
data/lib/assert/version.rb
CHANGED
data/lib/assert/view.rb
CHANGED
data/lib/assert/view_helpers.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
#
|
2
|
-
# put any test helpers here
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
#
|
3
|
+
# This file is automatically required when you run `assert`; put any test
|
4
|
+
# helpers here.
|
5
|
+
|
6
|
+
# Add the root dir to the load path.
|
5
7
|
ROOT_PATH = File.expand_path("../..", __FILE__)
|
6
8
|
$LOAD_PATH.unshift(ROOT_PATH)
|
7
9
|
|
@@ -9,38 +11,36 @@ $LOAD_PATH.unshift(ROOT_PATH)
|
|
9
11
|
require "pry"
|
10
12
|
require "test/support/factory"
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@run_callback = proc{ |result| @test_run_results << result }
|
19
|
-
end
|
14
|
+
module Assert::Test::TestHelpers
|
15
|
+
def self.included(receiver)
|
16
|
+
receiver.class_eval do
|
17
|
+
setup do
|
18
|
+
@test_run_results = []
|
19
|
+
@run_callback = proc { |result| @test_run_results << result }
|
20
20
|
end
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
+
private
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def test_run_callback
|
26
|
+
@run_callback
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def test_run_results(type = nil)
|
30
|
+
return @test_run_results if type.nil?
|
31
|
+
@test_run_results.select{ |r| r.type == type }
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def test_run_result_count(type = nil)
|
35
|
+
test_run_results(type).count
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
def test_run_result_messages
|
39
|
+
@test_run_results.map(&:message)
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
42
|
+
def last_test_run_result
|
43
|
+
@test_run_results.last
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|