forked from rspec/rspec-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_file_load_errors_spec.rb
138 lines (105 loc) · 3.72 KB
/
spec_file_load_errors_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
require 'support/aruba_support'
require 'support/formatter_support'
RSpec.describe 'Spec file load errors' do
include_context "aruba support"
include FormatterSupport
let(:failure_exit_code) { rand(97) + 2 } # 2..99
let(:error_exit_code) { failure_exit_code + 1 } # 3..100
if RSpec::Support::Ruby.jruby_9000?
let(:spec_line_suffix) { ":in `<main>'" }
elsif RSpec::Support::Ruby.jruby?
let(:spec_line_suffix) { ":in `(root)'" }
elsif RUBY_VERSION == "1.8.7"
let(:spec_line_suffix) { "" }
else
let(:spec_line_suffix) { ":in `<top (required)>'" }
end
before do
setup_aruba
RSpec.configure do |c|
c.filter_gems_from_backtrace "gems/aruba"
c.backtrace_exclusion_patterns << %r{/rspec-core/spec/} << %r{rspec_with_simplecov}
c.failure_exit_code = failure_exit_code
c.error_exit_code = error_exit_code
end
end
it 'nicely handles load-time errors from --require files' do
write_file_formatted "helper_with_error.rb", "raise 'boom'"
run_command "--require ./helper_with_error"
expect(last_cmd_exit_status).to eq(error_exit_code)
output = normalize_durations(last_cmd_stdout)
expect(output).to eq unindent(<<-EOS)
An error occurred while loading ./helper_with_error.
Failure/Error: raise 'boom'
RuntimeError:
boom
# ./helper_with_error.rb:1#{spec_line_suffix}
No examples found.
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
EOS
end
it 'prints a single error when it happens on --require files' do
write_file_formatted "helper_with_error.rb", "raise 'boom'"
write_file_formatted "1_spec.rb", "
RSpec.describe 'A broken spec file that will raise when loaded' do
raise 'kaboom'
end
"
run_command "--require ./helper_with_error 1_spec.rb"
expect(last_cmd_exit_status).to eq(error_exit_code)
output = normalize_durations(last_cmd_stdout)
expect(output).to eq unindent(<<-EOS)
An error occurred while loading ./helper_with_error.
Failure/Error: raise 'boom'
RuntimeError:
boom
# ./helper_with_error.rb:1#{spec_line_suffix}
No examples found.
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
EOS
end
it 'nicely handles load-time errors in user spec files' do
write_file_formatted "1_spec.rb", "
boom
RSpec.describe 'Calling boom' do
it 'will not run this example' do
expect(1).to eq 1
end
end
"
write_file_formatted "2_spec.rb", "
RSpec.describe 'No Error' do
it 'will not run this example, either' do
expect(1).to eq 1
end
end
"
write_file_formatted "3_spec.rb", "
boom
RSpec.describe 'Calling boom again' do
it 'will not run this example, either' do
expect(1).to eq 1
end
end
"
run_command "1_spec.rb 2_spec.rb 3_spec.rb"
expect(last_cmd_exit_status).to eq(error_exit_code)
output = normalize_durations(last_cmd_stdout)
expect(output).to eq unindent(<<-EOS)
An error occurred while loading ./1_spec.rb.
Failure/Error: boom
NameError:
undefined local variable or method `boom' for main:Object
# ./1_spec.rb:1#{spec_line_suffix}
An error occurred while loading ./3_spec.rb.
Failure/Error: boom
NameError:
undefined local variable or method `boom' for main:Object
# ./3_spec.rb:1#{spec_line_suffix}
Finished in n.nnnn seconds (files took n.nnnn seconds to load)
0 examples, 0 failures, 2 errors occurred outside of examples
EOS
end
end