This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
spec/rspec/core/formatters Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ def expression_lines
55
55
end
56
56
57
57
source . lines [ ( line_range . begin - 1 ) ..( line_range . end - 1 ) ]
58
- rescue NoExpressionAtLineError
58
+ rescue SyntaxError , NoExpressionAtLineError
59
59
[ self . class . extract_line_at ( source . path , beginning_line_number ) ]
60
60
end
61
61
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ def ast
26
26
@ast ||= begin
27
27
require 'ripper'
28
28
sexp = Ripper . sexp ( source )
29
+ raise SyntaxError unless sexp
29
30
Node . new ( sexp )
30
31
end
31
32
end
Original file line number Diff line number Diff line change @@ -250,6 +250,28 @@ def another_expression(*)
250
250
end
251
251
end
252
252
253
+ context 'when Ripper cannot parse the source (which can happen on JRuby -- see jruby/jruby#2427)' , :isolated_directory do
254
+ let ( :file_path ) { 'invalid_source.rb' }
255
+
256
+ let ( :line_number ) { 1 }
257
+
258
+ let ( :source ) { <<-EOS . gsub ( /^ +\| / , '' ) }
259
+ |expect("some string").to include(
260
+ | "some", "string"
261
+ |]
262
+ EOS
263
+
264
+ before do
265
+ File . open ( file_path , 'w' ) { |file | file . write ( source ) }
266
+ end
267
+
268
+ it 'returns the line by falling back to the simple single line extraction' do
269
+ expect ( expression_lines ) . to eq ( [
270
+ 'expect("some string").to include('
271
+ ] )
272
+ end
273
+ end
274
+
253
275
context 'when max line count is given' do
254
276
let ( :max_line_count ) do
255
277
2
You can’t perform that action at this time.
0 commit comments