assert 2.19.2 → 2.19.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assert.gemspec +10 -7
- data/lib/assert.rb +18 -6
- data/lib/assert/actual_value.rb +8 -6
- data/lib/assert/assert_runner.rb +36 -17
- data/lib/assert/assertions.rb +83 -50
- data/lib/assert/cli.rb +17 -66
- data/lib/assert/clirb.rb +55 -0
- data/lib/assert/config.rb +7 -7
- data/lib/assert/config_helpers.rb +55 -22
- data/lib/assert/context.rb +14 -18
- data/lib/assert/context/let_dsl.rb +5 -2
- data/lib/assert/context/setup_dsl.rb +21 -16
- data/lib/assert/context/subject_dsl.rb +6 -7
- data/lib/assert/context/suite_dsl.rb +2 -1
- data/lib/assert/context/test_dsl.rb +55 -19
- data/lib/assert/default_suite.rb +25 -15
- data/lib/assert/default_view.rb +47 -30
- data/lib/assert/file_line.rb +6 -6
- data/lib/assert/macro.rb +1 -1
- data/lib/assert/macros/methods.rb +71 -45
- data/lib/assert/result.rb +111 -62
- data/lib/assert/runner.rb +68 -51
- data/lib/assert/stub.rb +4 -4
- data/lib/assert/suite.rb +67 -28
- data/lib/assert/test.rb +40 -35
- data/lib/assert/utils.rb +19 -10
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +44 -18
- data/lib/assert/view_helpers.rb +100 -92
- data/test/helper.rb +3 -1
- data/test/support/factory.rb +38 -21
- data/test/system/stub_tests.rb +180 -144
- data/test/system/test_tests.rb +86 -60
- data/test/unit/actual_value_tests.rb +69 -50
- data/test/unit/assert_tests.rb +39 -22
- data/test/unit/assertions/assert_block_tests.rb +10 -10
- data/test/unit/assertions/assert_changes_tests.rb +25 -21
- data/test/unit/assertions/assert_empty_tests.rb +14 -12
- data/test/unit/assertions/assert_equal_tests.rb +26 -26
- data/test/unit/assertions/assert_file_exists_tests.rb +15 -13
- data/test/unit/assertions/assert_includes_tests.rb +10 -10
- data/test/unit/assertions/assert_instance_of_tests.rb +14 -14
- data/test/unit/assertions/assert_is_a_tests.rb +128 -0
- data/test/unit/assertions/assert_match_tests.rb +10 -10
- data/test/unit/assertions/assert_nil_tests.rb +16 -12
- data/test/unit/assertions/assert_raises_tests.rb +27 -20
- data/test/unit/assertions/assert_respond_to_tests.rb +10 -10
- data/test/unit/assertions/assert_same_tests.rb +24 -24
- data/test/unit/assertions/assert_true_false_tests.rb +32 -24
- data/test/unit/assertions_tests.rb +14 -9
- data/test/unit/config_helpers_tests.rb +15 -10
- data/test/unit/config_tests.rb +10 -9
- data/test/unit/context/setup_dsl_tests.rb +24 -14
- data/test/unit/context/subject_dsl_tests.rb +3 -3
- data/test/unit/context/suite_dsl_tests.rb +4 -4
- data/test/unit/context/test_dsl_tests.rb +37 -17
- data/test/unit/context_info_tests.rb +4 -4
- data/test/unit/context_tests.rb +110 -54
- data/test/unit/default_suite_tests.rb +10 -6
- data/test/unit/factory_tests.rb +2 -2
- data/test/unit/file_line_tests.rb +7 -7
- data/test/unit/macro_tests.rb +11 -11
- data/test/unit/result_tests.rb +47 -41
- data/test/unit/runner_tests.rb +29 -16
- data/test/unit/suite_tests.rb +37 -15
- data/test/unit/test_tests.rb +63 -50
- data/test/unit/utils_tests.rb +48 -35
- data/test/unit/view_helpers_tests.rb +21 -14
- data/test/unit/view_tests.rb +5 -5
- metadata +26 -11
- data/test/unit/assertions/assert_kind_of_tests.rb +0 -68
data/lib/assert/stub.rb
CHANGED
@@ -27,9 +27,9 @@ module Assert
|
|
27
27
|
orig_caller = caller_locations
|
28
28
|
begin
|
29
29
|
MuchStub.stub_send(*args, &block)
|
30
|
-
rescue MuchStub::NotStubbedError =>
|
31
|
-
|
32
|
-
raise
|
30
|
+
rescue MuchStub::NotStubbedError => ex
|
31
|
+
ex.set_backtrace(orig_caller.map(&:to_s))
|
32
|
+
raise ex
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -80,7 +80,7 @@ module Assert
|
|
80
80
|
|
81
81
|
# See MuchStub::CallSpy#inspect.
|
82
82
|
def inspect
|
83
|
-
"#<Assert::StubCallSpy:#{"0x0%x" % (
|
83
|
+
"#<Assert::StubCallSpy:#{"0x0%x" % (__id__ << 1)}>"
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
data/lib/assert/suite.rb
CHANGED
@@ -27,21 +27,31 @@ module Assert
|
|
27
27
|
@end_time = @start_time
|
28
28
|
end
|
29
29
|
|
30
|
-
def suite
|
30
|
+
def suite
|
31
|
+
self
|
32
|
+
end
|
31
33
|
|
32
34
|
def setup(&block)
|
33
|
-
|
35
|
+
setups << (block || proc{})
|
34
36
|
end
|
35
37
|
alias_method :startup, :setup
|
36
38
|
|
37
39
|
def teardown(&block)
|
38
|
-
|
40
|
+
teardowns << (block || proc{})
|
39
41
|
end
|
40
42
|
alias_method :shutdown, :teardown
|
41
43
|
|
42
|
-
def tests_to_run
|
43
|
-
|
44
|
-
|
44
|
+
def tests_to_run?
|
45
|
+
@tests.any?
|
46
|
+
end
|
47
|
+
|
48
|
+
def tests_to_run_count
|
49
|
+
@tests.size
|
50
|
+
end
|
51
|
+
|
52
|
+
def clear_tests_to_run
|
53
|
+
@tests.clear
|
54
|
+
end
|
45
55
|
|
46
56
|
def find_test_to_run(file_line)
|
47
57
|
@tests.find{ |t| t.file_line == file_line }
|
@@ -51,32 +61,46 @@ module Assert
|
|
51
61
|
@tests.sort.sort_by(&sort_by_proc)
|
52
62
|
end
|
53
63
|
|
54
|
-
def test_count
|
55
|
-
|
56
|
-
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
def
|
64
|
+
def test_count
|
65
|
+
end
|
66
|
+
|
67
|
+
def result_count
|
68
|
+
end
|
69
|
+
|
70
|
+
def pass_result_count
|
71
|
+
end
|
72
|
+
|
73
|
+
def fail_result_count
|
74
|
+
end
|
75
|
+
|
76
|
+
def error_result_count
|
77
|
+
end
|
78
|
+
|
79
|
+
def skip_result_count
|
80
|
+
end
|
81
|
+
|
82
|
+
def ignore_result_count
|
83
|
+
end
|
61
84
|
|
62
85
|
def run_time
|
63
86
|
@end_time - @start_time
|
64
87
|
end
|
65
88
|
|
66
89
|
def test_rate
|
67
|
-
get_rate(
|
90
|
+
get_rate(test_count, run_time)
|
68
91
|
end
|
69
92
|
|
70
93
|
def result_rate
|
71
|
-
get_rate(
|
94
|
+
get_rate(result_count, run_time)
|
72
95
|
end
|
73
96
|
|
74
97
|
# Callbacks
|
75
98
|
|
76
|
-
# define callback handlers to do special behavior during the test run.
|
77
|
-
# will be called by the test runner
|
99
|
+
# define callback handlers to do special behavior during the test run.
|
100
|
+
# These will be called by the test runner.
|
78
101
|
|
79
|
-
def before_load(test_files)
|
102
|
+
def before_load(test_files)
|
103
|
+
end
|
80
104
|
|
81
105
|
# this is required to load tests into the suite, be sure to `super` if you
|
82
106
|
# override this method
|
@@ -84,19 +108,34 @@ module Assert
|
|
84
108
|
@tests << test
|
85
109
|
end
|
86
110
|
|
87
|
-
def after_load
|
88
|
-
|
89
|
-
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
def
|
94
|
-
|
111
|
+
def after_load
|
112
|
+
end
|
113
|
+
|
114
|
+
def on_start
|
115
|
+
end
|
116
|
+
|
117
|
+
def before_test(test)
|
118
|
+
end
|
119
|
+
|
120
|
+
def on_result(result)
|
121
|
+
end
|
122
|
+
|
123
|
+
def after_test(test)
|
124
|
+
end
|
125
|
+
|
126
|
+
def on_finish
|
127
|
+
end
|
128
|
+
|
129
|
+
def on_info(test)
|
130
|
+
end
|
131
|
+
|
132
|
+
def on_interrupt(err)
|
133
|
+
end
|
95
134
|
|
96
135
|
def inspect
|
97
136
|
"#<#{self.class}:#{"0x0%x" % (object_id << 1)}"\
|
98
|
-
" test_count=#{
|
99
|
-
" result_count=#{
|
137
|
+
" test_count=#{test_count.inspect}"\
|
138
|
+
" result_count=#{result_count.inspect}>"
|
100
139
|
end
|
101
140
|
end
|
102
141
|
end
|
data/lib/assert/test.rb
CHANGED
@@ -9,16 +9,16 @@ module Assert
|
|
9
9
|
# Test is some code/method to run in the scope of a Context that may
|
10
10
|
# produce results.
|
11
11
|
def self.name_file_line_context_data(ci, name)
|
12
|
-
{ :
|
13
|
-
:
|
12
|
+
{ name: ci.test_name(name),
|
13
|
+
file_line: ci.called_from,
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.for_block(name, context_info, config, &block)
|
18
|
-
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
18
|
+
new(name_file_line_context_data(context_info, name).merge({
|
19
|
+
context_info: context_info,
|
20
|
+
config: config,
|
21
|
+
code: block,
|
22
22
|
}))
|
23
23
|
end
|
24
24
|
|
@@ -31,8 +31,13 @@ module Assert
|
|
31
31
|
@file_line ||= FileLine.parse((@build_data[:file_line] || "").to_s)
|
32
32
|
end
|
33
33
|
|
34
|
-
def file_name
|
35
|
-
|
34
|
+
def file_name
|
35
|
+
file_line.file
|
36
|
+
end
|
37
|
+
|
38
|
+
def line_num
|
39
|
+
file_line.line.to_i
|
40
|
+
end
|
36
41
|
|
37
42
|
def name
|
38
43
|
@name ||= (@build_data[:name] || "")
|
@@ -51,7 +56,7 @@ module Assert
|
|
51
56
|
end
|
52
57
|
|
53
58
|
def context_class
|
54
|
-
|
59
|
+
context_info.klass
|
55
60
|
end
|
56
61
|
|
57
62
|
def config
|
@@ -64,22 +69,22 @@ module Assert
|
|
64
69
|
|
65
70
|
def run(&result_callback)
|
66
71
|
@result_callback = result_callback || proc{ |result| } # noop by default
|
67
|
-
scope =
|
72
|
+
scope = context_class.new(self, config, @result_callback)
|
68
73
|
start_time = Time.now
|
69
74
|
capture_output do
|
70
|
-
|
75
|
+
context_class.run_arounds(scope){ run_test(scope) }
|
71
76
|
end
|
72
77
|
@result_callback = nil
|
73
78
|
@run_time = Time.now - start_time
|
74
79
|
end
|
75
80
|
|
76
|
-
def <=>(
|
77
|
-
|
81
|
+
def <=>(other)
|
82
|
+
name <=> other.name
|
78
83
|
end
|
79
84
|
|
80
85
|
def inspect
|
81
86
|
attributes_string = ([:name, :context_info].collect do |attr|
|
82
|
-
"@#{attr}=#{
|
87
|
+
"@#{attr}=#{send(attr).inspect}"
|
83
88
|
end).join(" ")
|
84
89
|
"#<#{self.class}:#{"0x0%x" % (object_id << 1)} #{attributes_string}>"
|
85
90
|
end
|
@@ -89,33 +94,33 @@ module Assert
|
|
89
94
|
def run_test(scope)
|
90
95
|
begin
|
91
96
|
# run any assert style "setup do" setups
|
92
|
-
|
97
|
+
context_class.run_setups(scope)
|
93
98
|
# run any test/unit style "def setup" setups
|
94
99
|
scope.setup if scope.respond_to?(:setup)
|
95
100
|
# run the code block
|
96
|
-
scope.instance_eval(&(
|
97
|
-
rescue Result::TestFailure =>
|
98
|
-
capture_result(Result::Fail,
|
99
|
-
rescue Result::TestSkipped =>
|
100
|
-
capture_result(Result::Skip,
|
101
|
-
rescue SignalException =>
|
102
|
-
raise(
|
103
|
-
rescue
|
104
|
-
capture_result(Result::Error,
|
101
|
+
scope.instance_eval(&(code || proc{}))
|
102
|
+
rescue Result::TestFailure => ex
|
103
|
+
capture_result(Result::Fail, ex)
|
104
|
+
rescue Result::TestSkipped => ex
|
105
|
+
capture_result(Result::Skip, ex)
|
106
|
+
rescue SignalException => ex
|
107
|
+
raise(ex)
|
108
|
+
rescue => ex
|
109
|
+
capture_result(Result::Error, ex)
|
105
110
|
ensure
|
106
111
|
begin
|
107
112
|
# run any assert style "teardown do" teardowns
|
108
|
-
|
113
|
+
context_class.run_teardowns(scope)
|
109
114
|
# run any test/unit style "def teardown" teardowns
|
110
115
|
scope.teardown if scope.respond_to?(:teardown)
|
111
|
-
rescue Result::TestFailure =>
|
112
|
-
capture_result(Result::Fail,
|
113
|
-
rescue Result::TestSkipped =>
|
114
|
-
capture_result(Result::Skip,
|
115
|
-
rescue SignalException =>
|
116
|
-
raise(
|
117
|
-
rescue
|
118
|
-
capture_result(Result::Error,
|
116
|
+
rescue Result::TestFailure => ex
|
117
|
+
capture_result(Result::Fail, ex)
|
118
|
+
rescue Result::TestSkipped => ex
|
119
|
+
capture_result(Result::Skip, ex)
|
120
|
+
rescue SignalException => ex
|
121
|
+
raise(ex)
|
122
|
+
rescue => ex
|
123
|
+
capture_result(Result::Error, ex)
|
119
124
|
end
|
120
125
|
end
|
121
126
|
end
|
@@ -125,7 +130,7 @@ module Assert
|
|
125
130
|
end
|
126
131
|
|
127
132
|
def capture_output(&block)
|
128
|
-
if
|
133
|
+
if config.capture_output == true
|
129
134
|
orig_stdout = $stdout.clone
|
130
135
|
$stdout = capture_io
|
131
136
|
block.call
|
@@ -136,7 +141,7 @@ module Assert
|
|
136
141
|
end
|
137
142
|
|
138
143
|
def capture_io
|
139
|
-
StringIO.new(
|
144
|
+
StringIO.new(output, "a+")
|
140
145
|
end
|
141
146
|
end
|
142
147
|
end
|
data/lib/assert/utils.rb
CHANGED
@@ -12,18 +12,21 @@ module Assert
|
|
12
12
|
out
|
13
13
|
end
|
14
14
|
|
15
|
-
# show objects in a human-readable manner and make the output diff-able.
|
16
|
-
# expands on the basic `show` util by escaping newlines and making
|
17
|
-
# hex-values generic.
|
15
|
+
# show objects in a human-readable manner and make the output diff-able.
|
16
|
+
# This expands on the basic `show` util by escaping newlines and making
|
17
|
+
# object id hex-values generic.
|
18
18
|
def self.show_for_diff(obj, config)
|
19
|
-
show(obj, config)
|
19
|
+
show(obj, config)
|
20
|
+
.gsub(/\\n/, "\n")
|
21
|
+
.gsub(/:0x[a-fA-F0-9]{4,}/m, ":0xXXXXXX")
|
20
22
|
end
|
21
23
|
|
22
24
|
# open a tempfile and yield it
|
23
25
|
def self.tempfile(name, content)
|
24
26
|
require "tempfile"
|
25
27
|
Tempfile.open(name) do |tmpfile|
|
26
|
-
tmpfile.puts(content)
|
28
|
+
tmpfile.puts(content)
|
29
|
+
tmpfile.flush
|
27
30
|
yield tmpfile if block_given?
|
28
31
|
end
|
29
32
|
end
|
@@ -34,7 +37,8 @@ module Assert
|
|
34
37
|
Proc.new{ |obj| PP.pp(obj, +"", width || 79).strip }
|
35
38
|
end
|
36
39
|
|
37
|
-
# Return true if if either show output has newlines or is bigger than 29
|
40
|
+
# Return true if if either show output has newlines or is bigger than 29
|
41
|
+
# chars.
|
38
42
|
def self.default_use_diff_proc
|
39
43
|
Proc.new do |exp_show_output, act_show_output|
|
40
44
|
exp_show_output.include?("\n") || exp_show_output.size > 29 ||
|
@@ -62,10 +66,15 @@ module Assert
|
|
62
66
|
def self.git_changed_proc
|
63
67
|
Proc.new do |config, test_paths|
|
64
68
|
files = []
|
65
|
-
cmd =
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
+
cmd =
|
70
|
+
[
|
71
|
+
# changed files
|
72
|
+
"git diff --no-ext-diff --name-only #{config.changed_ref}",
|
73
|
+
# added files
|
74
|
+
"git ls-files --others --exclude-standard",
|
75
|
+
]
|
76
|
+
.map{ |c| "#{c} -- #{test_paths.join(" ")}" }
|
77
|
+
.join(" && ")
|
69
78
|
Assert::CLI.bench("Load only changed files") do
|
70
79
|
files = `#{cmd}`.split("\n")
|
71
80
|
end
|
data/lib/assert/version.rb
CHANGED
data/lib/assert/view.rb
CHANGED
@@ -16,16 +16,18 @@ module Assert
|
|
16
16
|
|
17
17
|
def self.require_user_view(view_name)
|
18
18
|
views_file = File.expand_path(
|
19
|
-
File.join("#{ENV["HOME"]}/.assert/views", view_name, "lib", view_name)
|
19
|
+
File.join("#{ENV["HOME"]}/.assert/views", view_name, "lib", view_name),
|
20
20
|
)
|
21
21
|
|
22
|
-
if File.
|
22
|
+
if File.exist?(view_name) || File.exist?(view_name + ".rb")
|
23
23
|
require view_name
|
24
|
-
elsif File.
|
24
|
+
elsif File.exist?(views_file + ".rb")
|
25
25
|
require views_file
|
26
26
|
else
|
27
|
-
msg = "[WARN] Can't find or require #{view_name.inspect} view."
|
28
|
-
|
27
|
+
msg = +"[WARN] Can't find or require #{view_name.inspect} view."
|
28
|
+
unless view_name.match(%r{\A/})
|
29
|
+
msg << " Did you install it in `~/.assert/views`?"
|
30
|
+
end
|
29
31
|
warn msg
|
30
32
|
end
|
31
33
|
end
|
@@ -48,11 +50,13 @@ module Assert
|
|
48
50
|
attr_reader :config
|
49
51
|
|
50
52
|
def initialize(config, output_io)
|
51
|
-
@config
|
53
|
+
@config, @output_io, = config, output_io
|
52
54
|
@output_io.sync = true if @output_io.respond_to?(:sync=)
|
53
55
|
end
|
54
56
|
|
55
|
-
def view
|
57
|
+
def view
|
58
|
+
self
|
59
|
+
end
|
56
60
|
|
57
61
|
def is_tty?
|
58
62
|
!!@output_io.isatty
|
@@ -79,19 +83,41 @@ module Assert
|
|
79
83
|
# the test suite
|
80
84
|
# * `on_interrupt`: called when the test suite is interrupted while running
|
81
85
|
# the interrupt exception is passed as an arg
|
82
|
-
def before_load(test_files)
|
83
|
-
|
84
|
-
|
85
|
-
def
|
86
|
-
|
87
|
-
|
88
|
-
def
|
89
|
-
|
90
|
-
|
86
|
+
def before_load(test_files)
|
87
|
+
end
|
88
|
+
|
89
|
+
def after_load
|
90
|
+
end
|
91
|
+
|
92
|
+
def on_start
|
93
|
+
end
|
94
|
+
|
95
|
+
def before_test(test)
|
96
|
+
end
|
97
|
+
|
98
|
+
def on_result(result)
|
99
|
+
end
|
100
|
+
|
101
|
+
def after_test(test)
|
102
|
+
end
|
103
|
+
|
104
|
+
def on_finish
|
105
|
+
end
|
106
|
+
|
107
|
+
def on_info(test)
|
108
|
+
end
|
109
|
+
|
110
|
+
def on_interrupt(err)
|
111
|
+
end
|
91
112
|
|
92
113
|
# IO capture
|
93
114
|
|
94
|
-
def puts(*args)
|
95
|
-
|
115
|
+
def puts(*args)
|
116
|
+
@output_io.puts(*args)
|
117
|
+
end
|
118
|
+
|
119
|
+
def print(*args)
|
120
|
+
@output_io.print(*args)
|
121
|
+
end
|
96
122
|
end
|
97
123
|
end
|