uspec 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +1 -1
- data/example_specs/example_spec.rb +5 -6
- data/lib/uspec/cli.rb +25 -4
- data/lib/uspec/define.rb +1 -1
- data/lib/uspec/errors.rb +177 -0
- data/lib/uspec/harness.rb +18 -40
- data/lib/uspec/result.rb +18 -68
- data/lib/uspec/version.rb +1 -1
- data/lib/uspec.rb +1 -0
- data/uspec/cli_spec.rb +9 -10
- data/uspec/dsl_spec.rb +1 -1
- data/uspec/errors_spec.rb +37 -0
- data/uspec/result_spec.rb +4 -0
- data/uspec/test_specs/error_value_spec +8 -0
- data/uspec/test_specs/internal_error_spec +3 -0
- data/uspec/test_specs/source_error_spec +8 -0
- data/uspec/uspec_helper.rb +10 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5ebd02acebff5a7d7ffa72dfe23a30b6ef1789acffb41b540758d1cf4d1f083
|
4
|
+
data.tar.gz: ffbc0c4e20c8a4c4376e0ba059ecedc9e8f1589ada86a31998a6b628b1d30df9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aecd905b5420be09dca096a188180e98b6af4514e82d58d3e510500d33899e21034ba143bb77de0536e2f00b126e4635478ecc48f7f6b2b2fa7a6c614d3f3e42
|
7
|
+
data.tar.gz: 98990be1d95c445bb8791b3fc11acefc4fc90013ae533b884db4829ad4e965695d58c1788bdc250fe9181a5eb30956b6f17f7c4afa75732e9a71e565f3f90fb7
|
data/README.markdown
CHANGED
@@ -69,7 +69,7 @@ Output
|
|
69
69
|
|
70
70
|
Uspec's output is in beautiful ANSI technicolor, with red for failures, green for successes, and yellow for pending specs.
|
71
71
|
|
72
|
-
![
|
72
|
+
![uspec examples](https://github.com/acook/uspec/assets/71984/0ceb4319-e671-4159-88d6-6319ebf6cbd3)
|
73
73
|
|
74
74
|
A brief explanation of `uspec`'s output to show you what it can do!
|
75
75
|
|
@@ -1,21 +1,20 @@
|
|
1
1
|
require_relative 'spec_helper'
|
2
2
|
|
3
|
-
spec 'I love passing tests' do
|
3
|
+
spec 'I love passing tests! Passing tests return `true`' do
|
4
4
|
true
|
5
5
|
end
|
6
6
|
|
7
7
|
spec "This is an idea, but I haven't written the test yet"
|
8
8
|
|
9
|
-
spec 'Failing tests
|
9
|
+
spec 'This is a failing test. Failing tests return `false`' do
|
10
10
|
false
|
11
11
|
end
|
12
12
|
|
13
|
-
spec '
|
13
|
+
spec 'Non-boolean values are shown in detail' do
|
14
14
|
'non-boolean value'
|
15
15
|
end
|
16
16
|
|
17
|
-
spec '
|
17
|
+
spec 'Exceptions are handled and displayed' do
|
18
18
|
class ExampleError < RuntimeError; end
|
19
|
-
raise ExampleError
|
19
|
+
raise ExampleError, "an example error for demonstration"
|
20
20
|
end
|
21
|
-
|
data/lib/uspec/cli.rb
CHANGED
@@ -3,8 +3,6 @@ require_relative '../uspec'
|
|
3
3
|
|
4
4
|
class Uspec::CLI
|
5
5
|
def initialize args
|
6
|
-
usage unless (args & %w[-h --help -? /? -v --version]).empty?
|
7
|
-
|
8
6
|
@paths = args
|
9
7
|
@pwd = Pathname.pwd.freeze
|
10
8
|
@stats = Uspec::Stats.new
|
@@ -15,6 +13,9 @@ class Uspec::CLI
|
|
15
13
|
def usage
|
16
14
|
warn "uspec v#{::Uspec::VERSION} - minimalistic ruby testing framework"
|
17
15
|
warn "usage: #{File.basename $0} [<file_or_path>...]"
|
16
|
+
warn ""
|
17
|
+
warn "\t\t--full_backtrace\tshow full backtrace"
|
18
|
+
warn "\t\t--\t\t\tstop checking paths for options (good if a path begins with a dash)"
|
18
19
|
exit 1
|
19
20
|
end
|
20
21
|
|
@@ -23,6 +24,7 @@ class Uspec::CLI
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def invoke
|
27
|
+
parse_options @paths
|
26
28
|
run_specs
|
27
29
|
die!
|
28
30
|
end
|
@@ -61,23 +63,42 @@ class Uspec::CLI
|
|
61
63
|
end
|
62
64
|
|
63
65
|
def run_paths
|
66
|
+
check_options = true
|
67
|
+
|
64
68
|
paths.each do |path|
|
65
69
|
run @pwd.join path
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
69
73
|
def run path
|
70
|
-
|
74
|
+
p, line = path.to_s.split(?:)
|
75
|
+
path = Pathname.new p
|
76
|
+
|
71
77
|
if path.directory? then
|
72
78
|
Pathname.glob(path.join('**', '**_spec.rb')).each do |spec|
|
73
79
|
run spec
|
74
80
|
end
|
75
81
|
elsif path.exist? then
|
76
82
|
puts "#{path.basename path.extname}:"
|
77
|
-
harness.file_eval path
|
83
|
+
harness.file_eval path, line
|
78
84
|
else
|
79
85
|
warn "path not found: #{path}"
|
80
86
|
end
|
81
87
|
end
|
82
88
|
|
89
|
+
def parse_options args
|
90
|
+
args.each_with_index do |arg, i|
|
91
|
+
if arg == '--' then
|
92
|
+
return args
|
93
|
+
elsif arg == '--full_backtrace' then
|
94
|
+
Uspec::Errors.full_backtrace!
|
95
|
+
args.delete_at i
|
96
|
+
elsif !(args & %w[-h --help -? /? -v --version]).empty?
|
97
|
+
usage
|
98
|
+
elsif arg[0] == ?- then
|
99
|
+
warn "unknown option: #{arg}"
|
100
|
+
args.delete_at i
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
83
104
|
end
|
data/lib/uspec/define.rb
CHANGED
data/lib/uspec/errors.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
require_relative "terminal"
|
2
|
+
|
3
|
+
module Uspec
|
4
|
+
module Errors
|
5
|
+
module_function
|
6
|
+
|
7
|
+
extend Uspec::Terminal
|
8
|
+
|
9
|
+
MSG_USPEC_BUG_URL = "https://github.com/acook/uspec/issues/new"
|
10
|
+
MSG_IF_USPEC_BUG = "If you think this is a bug in Uspec please report it: #{MSG_USPEC_BUG_URL}"
|
11
|
+
TRACE_EXCLUDE_PATTERN = /#{Uspec.libpath.join 'lib'}|#{Uspec.libpath.join 'bin'}/
|
12
|
+
|
13
|
+
def handle_file_error error, path, cli = nil
|
14
|
+
error_info = error_context error
|
15
|
+
|
16
|
+
message = <<~MSG
|
17
|
+
Uspec encountered an error when loading a test file.
|
18
|
+
This is probably a typo in the test file or the file it is testing.
|
19
|
+
|
20
|
+
Error occured when loading test file `#{path}`.
|
21
|
+
#{error_info}
|
22
|
+
MSG
|
23
|
+
|
24
|
+
handle_error message, error, cli
|
25
|
+
end
|
26
|
+
|
27
|
+
def handle_internal_error error, cli = nil
|
28
|
+
error_info = error_context error, skip_internal: false
|
29
|
+
|
30
|
+
message = <<~MSG
|
31
|
+
Uspec encountered an internal error!
|
32
|
+
|
33
|
+
#{error_info}
|
34
|
+
MSG
|
35
|
+
|
36
|
+
handle_error message, error, cli
|
37
|
+
end
|
38
|
+
|
39
|
+
def handle_error message, error, cli
|
40
|
+
result = Uspec::Result.new(message, error, true)
|
41
|
+
|
42
|
+
puts
|
43
|
+
warn error_format error, message, leading_newline: false
|
44
|
+
|
45
|
+
cli.handle_interrupt! result.raw if cli
|
46
|
+
result
|
47
|
+
end
|
48
|
+
|
49
|
+
def msg_spec_error error, desc
|
50
|
+
error_info = error_context error
|
51
|
+
|
52
|
+
info = <<~MSG
|
53
|
+
Error occured when evaluating spec `#{desc}`.
|
54
|
+
#{error_info}
|
55
|
+
MSG
|
56
|
+
body = error_format error, info, first_line_indent: false
|
57
|
+
|
58
|
+
message = <<~MSG
|
59
|
+
#{red 'Exception'}
|
60
|
+
#{body}
|
61
|
+
MSG
|
62
|
+
|
63
|
+
message
|
64
|
+
end
|
65
|
+
|
66
|
+
def msg_spec_value error
|
67
|
+
error_info = white bt_format(bt_get error).chomp
|
68
|
+
|
69
|
+
message = <<~MSG
|
70
|
+
#{error.message}
|
71
|
+
#{error_info}
|
72
|
+
MSG
|
73
|
+
|
74
|
+
error_format error, message, header: false
|
75
|
+
end
|
76
|
+
|
77
|
+
def msg_source_error error, desc, cli = nil
|
78
|
+
error_info = error_context error
|
79
|
+
|
80
|
+
message = <<~MSG
|
81
|
+
Uspec detected a bug in your source code!
|
82
|
+
|
83
|
+
Calling #inspect on an object will recusively call #inspect on its instance variables and contents.
|
84
|
+
If one of those contained objects does not have an #inspect method you will see this message.
|
85
|
+
You will also get this message if your #inspect method or one of its callees raises an exception.
|
86
|
+
This is most likely to happen with BasicObject and its subclasses.
|
87
|
+
|
88
|
+
Error occured when evaluating spec `#{desc}`.
|
89
|
+
#{error_info}
|
90
|
+
MSG
|
91
|
+
|
92
|
+
error_format error, message, first_line_indent: false
|
93
|
+
end
|
94
|
+
|
95
|
+
def error_context error, skip_internal: true
|
96
|
+
bt = bt_get error
|
97
|
+
error_line = bt.first.split(?:)
|
98
|
+
[
|
99
|
+
error_origin(*error_line),
|
100
|
+
white(bt_format(bt, skip_internal)),
|
101
|
+
MSG_IF_USPEC_BUG
|
102
|
+
].join ?\n
|
103
|
+
end
|
104
|
+
|
105
|
+
def bt_get error
|
106
|
+
error.backtrace || caller[3..-1]
|
107
|
+
end
|
108
|
+
|
109
|
+
def error_origin error_file, error_line, *_
|
110
|
+
"The origin of the error may be in file `#{error_file}` on line ##{error_line}."
|
111
|
+
end
|
112
|
+
|
113
|
+
def error_format error, message, first_line_indent: true, leading_newline: true, header: true
|
114
|
+
h = ""
|
115
|
+
|
116
|
+
if header then
|
117
|
+
h << newline if leading_newline
|
118
|
+
h << hspace if first_line_indent
|
119
|
+
h << error_header(error)
|
120
|
+
h << vspace
|
121
|
+
end
|
122
|
+
|
123
|
+
error_indent(error, h + message)
|
124
|
+
end
|
125
|
+
|
126
|
+
def error_indent error, message
|
127
|
+
a = message.split(newline)
|
128
|
+
a << ""
|
129
|
+
a.join("#{newline}#{hspace}")
|
130
|
+
end
|
131
|
+
|
132
|
+
def error_header error
|
133
|
+
"#{red subklassinfo error}#{error.message}"
|
134
|
+
end
|
135
|
+
|
136
|
+
def subklassinfo obj
|
137
|
+
"#{::TOISB.wrap(obj).subklassinfo}: "
|
138
|
+
end
|
139
|
+
|
140
|
+
def bt_format bt, skip_internal = true
|
141
|
+
skip_internal = skip_internal && !full_backtrace?
|
142
|
+
bt_indent bt_clean(bt, skip_internal)
|
143
|
+
end
|
144
|
+
|
145
|
+
def bt_indent bt
|
146
|
+
"#{newline}#{hspace}" + bt.join("#{newline}#{hspace}") + newline if bt
|
147
|
+
end
|
148
|
+
|
149
|
+
def bt_clean bt, skip_internal = true
|
150
|
+
bt.inject(Array.new) do |t, line|
|
151
|
+
next t if skip_internal && line.match(TRACE_EXCLUDE_PATTERN)
|
152
|
+
t << bt_rewrite_caller(line)
|
153
|
+
end if bt
|
154
|
+
end
|
155
|
+
|
156
|
+
def bt_rewrite_caller line
|
157
|
+
return line if full_backtrace?
|
158
|
+
if line.match TRACE_EXCLUDE_PATTERN then
|
159
|
+
line
|
160
|
+
else
|
161
|
+
line.sub /file_eval/, 'spec_block'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def full_backtrace?
|
166
|
+
@full_backtrace
|
167
|
+
end
|
168
|
+
|
169
|
+
def full_backtrace!
|
170
|
+
@full_backtrace = true
|
171
|
+
end
|
172
|
+
|
173
|
+
def clean_backtrace!
|
174
|
+
@full_backtrace = false
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
data/lib/uspec/harness.rb
CHANGED
@@ -14,36 +14,19 @@ module Uspec
|
|
14
14
|
cli.stats
|
15
15
|
end
|
16
16
|
|
17
|
-
def file_eval path
|
17
|
+
def file_eval path, line
|
18
|
+
@path = path
|
19
|
+
@line = line
|
18
20
|
define.instance_eval(path.read, path.to_s)
|
19
21
|
rescue Exception => error
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
error_file, error_line, _ = error.backtrace.first.split ?:
|
25
|
-
|
26
|
-
message = <<-MSG
|
27
|
-
#{error.class} : #{error.message}
|
28
|
-
|
29
|
-
Uspec encountered an error when loading a test file.
|
30
|
-
This is probably a typo in the test file or the file it is testing.
|
31
|
-
|
32
|
-
If you think this is a bug in Uspec please report it: https://github.com/acook/uspec/issues/new
|
33
|
-
|
34
|
-
Error occured when loading test file `#{spec || path}`.
|
35
|
-
The origin of the error may be in file `#{error_file}` on line ##{error_line}.
|
36
|
-
|
37
|
-
\t#{error.backtrace[0,3].join "\n\t"}
|
38
|
-
MSG
|
39
|
-
puts
|
40
|
-
warn message
|
41
|
-
stats << Uspec::Result.new(message, error, true)
|
42
|
-
|
43
|
-
cli.handle_interrupt! error
|
22
|
+
raise error if SystemExit === error
|
23
|
+
result = Uspec::Errors.handle_file_error error, path, cli
|
24
|
+
stats << result if result
|
44
25
|
end
|
45
26
|
|
46
|
-
def spec_eval description, &block
|
27
|
+
def spec_eval description, source, &block
|
28
|
+
return if @line && !source.first.include?("#{@path}:#{@line}")
|
29
|
+
|
47
30
|
ex = nil
|
48
31
|
state = 0
|
49
32
|
print ' -- ', description
|
@@ -67,24 +50,19 @@ module Uspec
|
|
67
50
|
result.pending!
|
68
51
|
end
|
69
52
|
|
70
|
-
stats << result
|
71
|
-
|
72
53
|
print ': ', result.pretty, "\n"
|
73
54
|
rescue => error
|
74
|
-
|
75
|
-
message = <<-MSG
|
76
|
-
#{error.class} : #{error.message}
|
77
|
-
|
78
|
-
Uspec encountered an internal error, please report this bug: https://github.com/acook/uspec/issues/new
|
79
|
-
|
80
|
-
\t#{error.backtrace.join "\n\t"}
|
81
|
-
MSG
|
82
|
-
puts
|
83
|
-
warn message
|
84
|
-
stats << Uspec::Result.new(message, error, true)
|
55
|
+
result = Uspec::Errors.handle_internal_error error, cli
|
85
56
|
ensure
|
86
|
-
|
57
|
+
stats << result if result
|
58
|
+
cli.handle_interrupt! result ? result.raw : raw_result
|
87
59
|
return [state, error, result, raw_result]
|
88
60
|
end
|
61
|
+
|
62
|
+
def inspect
|
63
|
+
<<~MSG.chomp
|
64
|
+
<#{self.class}##{self.object_id} @cli=#{@cli ? '<...>' : @cli} @define=#{@define ? '<...>' : @define}>
|
65
|
+
MSG
|
66
|
+
end
|
89
67
|
end
|
90
68
|
end
|
data/lib/uspec/result.rb
CHANGED
@@ -6,7 +6,6 @@ module Uspec
|
|
6
6
|
include Terminal
|
7
7
|
|
8
8
|
PREFIX = "#{Uspec::Terminal.newline}#{Uspec::Terminal.yellow}>\t#{Uspec::Terminal.normal}"
|
9
|
-
TRACE_EXCLUDE_PATTERN = /#{Uspec.libpath.join 'lib'}|#{Uspec.libpath.join 'bin'}/
|
10
9
|
|
11
10
|
def initialize spec, raw, ex
|
12
11
|
@spec = spec
|
@@ -26,55 +25,14 @@ module Uspec
|
|
26
25
|
elsif pending? then
|
27
26
|
yellow 'pending'
|
28
27
|
elsif ex == true then
|
29
|
-
|
30
|
-
red('Exception'), vspace,
|
31
|
-
hspace, 'Spec encountered an Exception ', newline,
|
32
|
-
hspace, 'in spec at ', source.first, vspace,
|
33
|
-
hspace, message, vspace,
|
34
|
-
white(trace)
|
35
|
-
].join
|
28
|
+
Uspec::Errors.msg_spec_error raw, desc
|
36
29
|
else
|
37
|
-
|
38
|
-
red('Failed'), vspace,
|
39
|
-
hspace, 'Spec did not return a boolean value ', newline,
|
40
|
-
hspace, 'in spec at ', source.first, vspace,
|
41
|
-
hspace, red(subklassinfo), inspector, (Class === raw ? ' Class' : ''), newline
|
42
|
-
].join
|
30
|
+
nonboolean
|
43
31
|
end
|
44
32
|
end
|
45
33
|
|
46
|
-
def trace
|
47
|
-
@backtrace ||= indent_bt clean_bt(raw.backtrace, !full_backtrace)
|
48
|
-
end
|
49
|
-
|
50
34
|
def source
|
51
|
-
@source ||=
|
52
|
-
end
|
53
|
-
|
54
|
-
def indent_bt bt
|
55
|
-
bt.inject(String.new) do |text, line|
|
56
|
-
text << "#{hspace}#{line}#{newline}"
|
57
|
-
end if bt
|
58
|
-
end
|
59
|
-
|
60
|
-
def clean_bt bt, skip_internal = true
|
61
|
-
bt.inject(Array.new) do |t, line|
|
62
|
-
next t if skip_internal && line.match(TRACE_EXCLUDE_PATTERN)
|
63
|
-
t << rewrite_bt_caller(line)
|
64
|
-
end if bt
|
65
|
-
end
|
66
|
-
|
67
|
-
def rewrite_bt_caller line
|
68
|
-
return line if full_backtrace
|
69
|
-
if line.match TRACE_EXCLUDE_PATTERN then
|
70
|
-
line
|
71
|
-
else
|
72
|
-
line.sub /file_eval/, 'spec_block'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def message
|
77
|
-
"#{red subklassinfo}#{raw.message}"
|
35
|
+
@source ||= Uspec::Errors.bt_clean @caller
|
78
36
|
end
|
79
37
|
|
80
38
|
def subklassinfo
|
@@ -91,6 +49,16 @@ module Uspec
|
|
91
49
|
end
|
92
50
|
end
|
93
51
|
|
52
|
+
def nonboolean
|
53
|
+
[
|
54
|
+
red('Failed'), vspace,
|
55
|
+
hspace, 'Spec did not return a boolean value ', newline,
|
56
|
+
hspace, 'in spec at ', source.first, vspace,
|
57
|
+
hspace, red(subklassinfo), inspector, (Class === raw ? ' Class' : ''), newline
|
58
|
+
].join
|
59
|
+
|
60
|
+
end
|
61
|
+
|
94
62
|
# Attempts to inspect an object
|
95
63
|
def inspector
|
96
64
|
if String === raw && raw.include?(?\n) then
|
@@ -99,35 +67,17 @@ module Uspec
|
|
99
67
|
raw.split(newline).unshift(newline).join(PREFIX), normal, newline,
|
100
68
|
].join
|
101
69
|
elsif Exception === raw then
|
102
|
-
|
103
|
-
raw.message, vspace,
|
104
|
-
white(trace),
|
105
|
-
normal, newline,
|
106
|
-
].join
|
70
|
+
Uspec::Errors.msg_spec_value raw
|
107
71
|
else
|
108
72
|
handler.inspector!
|
109
73
|
end
|
110
74
|
rescue Exception => error
|
111
75
|
return handler.simple_inspector if error.message.include? handler.get_id
|
112
76
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
#{error.class} : #{error.message}
|
118
|
-
|
119
|
-
Uspec detected a bug in your source code!
|
120
|
-
Calling #inspect on an object will recusively call #inspect on its instance variables and contents.
|
121
|
-
If one of those contained objects does not have an #inspect method you will see this message.
|
122
|
-
You will also get this message if your #inspect method or one of its callees raises an exception.
|
123
|
-
This is most likely to happen with BasicObject and its subclasses.
|
124
|
-
|
125
|
-
If you think this is a bug in Uspec please report it: https://github.com/acook/uspec/issues/new
|
126
|
-
|
127
|
-
Error may have occured in test `#{desc}` in file `#{error_file}` on line ##{error_line}.
|
128
|
-
|
129
|
-
\t#{error.backtrace.join "\n\t"}
|
130
|
-
MSG
|
77
|
+
[
|
78
|
+
red('Unable to Inspect Object'), newline,
|
79
|
+
Uspec::Errors.msg_source_error(error, desc),
|
80
|
+
].join
|
131
81
|
end
|
132
82
|
|
133
83
|
def success?
|
data/lib/uspec/version.rb
CHANGED
data/lib/uspec.rb
CHANGED
data/uspec/cli_spec.rb
CHANGED
@@ -1,14 +1,5 @@
|
|
1
1
|
require_relative 'uspec_helper'
|
2
2
|
|
3
|
-
def new_cli path = '.'
|
4
|
-
Uspec::CLI.new(Array(path))
|
5
|
-
end
|
6
|
-
|
7
|
-
def run_specs path
|
8
|
-
new_cli(path).run_specs
|
9
|
-
end
|
10
|
-
|
11
|
-
|
12
3
|
spec 'shows usage' do
|
13
4
|
output = capture do
|
14
5
|
exec 'bin/uspec -h'
|
@@ -25,7 +16,7 @@ spec 'runs a path of specs' do
|
|
25
16
|
output.include?('I love passing tests') || output
|
26
17
|
end
|
27
18
|
|
28
|
-
spec 'runs an individual
|
19
|
+
spec 'runs an individual file' do
|
29
20
|
output = outstr do
|
30
21
|
run_specs exdir.join('example_spec.rb').to_s
|
31
22
|
end
|
@@ -33,6 +24,14 @@ spec 'runs an individual spec' do
|
|
33
24
|
output.include?('I love passing tests') || output
|
34
25
|
end
|
35
26
|
|
27
|
+
spec 'runs an individual spec' do
|
28
|
+
output = outstr do
|
29
|
+
run_specs exdir.join('example_spec.rb:13').to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
!output.include?('I love passing tests') && output.include?('non-boolean') || output
|
33
|
+
end
|
34
|
+
|
36
35
|
spec 'broken requires in test files count as test failures' do
|
37
36
|
output, status = Open3.capture2e "#{root}/bin/uspec #{testdir.join('broken_require_spec')}"
|
38
37
|
|
data/uspec/dsl_spec.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative "uspec_helper"
|
2
|
+
|
3
|
+
spec 'file errors are captured' do
|
4
|
+
cli = new_cli
|
5
|
+
|
6
|
+
output = outstr do
|
7
|
+
cli.harness.file_eval testdir.join('broken_require_spec'), nil
|
8
|
+
end
|
9
|
+
|
10
|
+
output.include?('Uspec encountered an error when loading') || output
|
11
|
+
end
|
12
|
+
|
13
|
+
spec 'internal errors are captured' do
|
14
|
+
cli = new_cli
|
15
|
+
|
16
|
+
output = outstr do
|
17
|
+
cli.harness.spec_eval BasicObject.new, BasicObject.new do
|
18
|
+
raise 'block error'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
output.include?('Uspec encountered an internal error') || output
|
23
|
+
end
|
24
|
+
|
25
|
+
spec 'source errors are captured' do
|
26
|
+
bo = BasicObject.new
|
27
|
+
def bo.inspect
|
28
|
+
invalid_for_source_error
|
29
|
+
end
|
30
|
+
|
31
|
+
a = [ bo ]
|
32
|
+
|
33
|
+
result = Uspec::Result.new "source error result", a, true
|
34
|
+
output = result.inspector
|
35
|
+
|
36
|
+
output.include?('Uspec detected a bug in your source') || output
|
37
|
+
end
|
data/uspec/result_spec.rb
CHANGED
@@ -103,8 +103,12 @@ spec "handles raised exceptions without backtraces" do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
spec "doesn't show 'run' for spec file in stack trace" do
|
106
|
+
Uspec::Errors.clean_backtrace!
|
107
|
+
|
106
108
|
result = Uspec::Result.new "No Run Exception Trace Result", exception_value, true
|
107
109
|
expected = /uspec.*run/
|
108
110
|
actual = result.pretty
|
111
|
+
|
112
|
+
Uspec::Errors.full_backtrace!
|
109
113
|
!actual.match?(expected) || result.pretty
|
110
114
|
end
|
data/uspec/uspec_helper.rb
CHANGED
@@ -9,6 +9,8 @@ require 'stringio'
|
|
9
9
|
require_relative '../lib/uspec'
|
10
10
|
extend Uspec
|
11
11
|
|
12
|
+
Uspec::Errors.full_backtrace!
|
13
|
+
|
12
14
|
def capture
|
13
15
|
readme, writeme = IO.pipe
|
14
16
|
pid = fork do
|
@@ -59,3 +61,11 @@ end
|
|
59
61
|
def testdir
|
60
62
|
specdir.join('test_specs')
|
61
63
|
end
|
64
|
+
|
65
|
+
def new_cli path = '.'
|
66
|
+
Uspec::CLI.new(Array(path))
|
67
|
+
end
|
68
|
+
|
69
|
+
def run_specs path
|
70
|
+
new_cli(path).run_specs
|
71
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony M. Cook
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: that_object_is_so_basic
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/uspec.rb
|
51
51
|
- lib/uspec/cli.rb
|
52
52
|
- lib/uspec/define.rb
|
53
|
+
- lib/uspec/errors.rb
|
53
54
|
- lib/uspec/harness.rb
|
54
55
|
- lib/uspec/result.rb
|
55
56
|
- lib/uspec/spec.rb
|
@@ -59,16 +60,20 @@ files:
|
|
59
60
|
- uspec.gemspec
|
60
61
|
- uspec/cli_spec.rb
|
61
62
|
- uspec/dsl_spec.rb
|
63
|
+
- uspec/errors_spec.rb
|
62
64
|
- uspec/result_spec.rb
|
63
65
|
- uspec/stats_spec.rb
|
64
66
|
- uspec/test_specs/break_spec
|
65
67
|
- uspec/test_specs/broken_require_spec
|
68
|
+
- uspec/test_specs/error_value_spec
|
69
|
+
- uspec/test_specs/internal_error_spec
|
66
70
|
- uspec/test_specs/ivar_spec
|
67
71
|
- uspec/test_specs/kill_this_script.sh
|
68
72
|
- uspec/test_specs/kill_this_spec
|
69
73
|
- uspec/test_specs/method_spec
|
70
74
|
- uspec/test_specs/pending_spec
|
71
75
|
- uspec/test_specs/return_spec
|
76
|
+
- uspec/test_specs/source_error_spec
|
72
77
|
- uspec/test_specs/value_spec
|
73
78
|
- uspec/uspec_helper.rb
|
74
79
|
- uspec/uspec_spec.rb
|