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 +70
-7
lines changed Expand file tree Collapse file tree 3 files changed +70
-7
lines changed Original file line number Diff line number Diff line change 1
1
require 'rspec/core/formatters/snippet_extractor'
2
+ require 'support/helper_methods'
3
+ require 'tempfile'
2
4
3
5
module RSpec ::Core ::Formatters
4
6
RSpec . describe SnippetExtractor do
7
+ include RSpecHelpers
8
+
5
9
subject ( :expression_lines ) do
6
10
SnippetExtractor . extract_expression_lines_at ( file_path , line_number , max_line_count )
7
11
end
@@ -182,6 +186,62 @@ def obj.foo(arg)
182
186
end
183
187
end
184
188
189
+ context 'when the expression line includes an "end"-less method definition' , :if => RUBY_VERSION . to_f >= 3.0 do
190
+ include RSpec ::Support ::InSubProcess
191
+
192
+ let ( :source ) do
193
+ in_sub_process do
194
+ load ( file . path )
195
+ end
196
+ end
197
+
198
+ let ( :file ) do
199
+ file = Tempfile . new ( 'source.rb' )
200
+
201
+ file . write ( unindent ( <<-END ) )
202
+ obj = Object.new
203
+
204
+ def obj.foo = raise
205
+
206
+ obj.foo
207
+ END
208
+
209
+ file . close
210
+
211
+ file
212
+ end
213
+
214
+ after do
215
+ file . unlink
216
+ end
217
+
218
+ it 'returns only the line' do
219
+ expect ( expression_lines ) . to eq ( [
220
+ 'def obj.foo = raise'
221
+ ] )
222
+ end
223
+ end
224
+
225
+ context 'when the expression is a setter method definition' , :unless => argument_error_points_invoker do
226
+ let ( :source ) do
227
+ obj = Object . new
228
+
229
+ def obj . foo = ( arg1 , arg2 )
230
+ @foo = arg1
231
+ end
232
+
233
+ obj . foo = 1
234
+ end
235
+
236
+ it 'returns all the lines without confusing it with "end"-less method' do
237
+ expect ( expression_lines ) . to eq ( [
238
+ ' def obj.foo=(arg1, arg2)' ,
239
+ ' @foo = arg1' ,
240
+ ' end'
241
+ ] )
242
+ end
243
+ end
244
+
185
245
context "when the expression ends with multiple paren-only lines of same type" do
186
246
let ( :source ) do
187
247
do_something_fail ( :foo , ( :bar
Original file line number Diff line number Diff line change
1
+ require 'support/helper_methods'
2
+
1
3
if RSpec ::Support ::Ruby . jruby? && RSpec ::Support ::Ruby . jruby_version == "9.1.17.0"
2
4
# A regression appeared in require_relative in JRuby 9.1.17.0 where require some
3
5
# how ends up private, this monkey patch uses `send`
@@ -29,6 +31,7 @@ module ArubaLoader
29
31
30
32
RSpec . shared_context "aruba support" do
31
33
include Aruba ::Api
34
+ include RSpecHelpers
32
35
let ( :stderr ) { StringIO . new }
33
36
let ( :stdout ) { StringIO . new }
34
37
@@ -70,13 +73,6 @@ def write_file_formatted(file_name, contents)
70
73
formatted_contents = unindent ( contents . sub ( /\A \n / , "" ) )
71
74
write_file file_name , formatted_contents
72
75
end
73
-
74
- # Intended for use with indented heredocs.
75
- # taken from Ruby Tapas:
76
- # https://rubytapas.dpdcart.com/subscriber/post?id=616#files
77
- def unindent ( s )
78
- s . gsub ( /^#{ s . scan ( /^[ \t ]+(?=\S )/ ) . min } / , "" )
79
- end
80
76
end
81
77
82
78
RSpec . configure do |c |
Original file line number Diff line number Diff line change @@ -14,6 +14,13 @@ def ignoring_warnings
14
14
result
15
15
end
16
16
17
+ # Intended for use with indented heredocs.
18
+ # taken from Ruby Tapas:
19
+ # https://rubytapas.dpdcart.com/subscriber/post?id=616#files
20
+ def unindent ( s )
21
+ s . gsub ( /^#{ s . scan ( /^[ \t ]+(?=\S )/ ) . min } / , "" )
22
+ end
23
+
17
24
# In Ruby 2.7 taint was removed and has no effect, whilst SAFE warns that it
18
25
# has no effect and will become a normal varible in 3.0. Other engines do not
19
26
# implement SAFE.
You can’t perform that action at this time.
0 commit comments