@@ -68,17 +68,8 @@ def parser(options)
68
68
69
69
parser . on ( '--bisect[=verbose]' , 'Repeatedly runs the suite in order to isolate the failures to the ' ,
70
70
' smallest reproducible case.' ) do |argument |
71
- options [ :runner ] = -> ( opts , err , out ) do
72
- RSpec ::Support . require_rspec_core "bisect/coordinator"
73
-
74
- success = Bisect ::Coordinator . bisect_with (
75
- opts . args ,
76
- RSpec . configuration ,
77
- bisect_formatter_for ( argument )
78
- )
79
-
80
- exit ( success ? 0 : 1 )
81
- end
71
+ options [ :bisect ] = argument
72
+ options [ :runner ] = Callables . bisect_and_exit
82
73
end
83
74
84
75
parser . on ( '--[no-]fail-fast[=COUNT]' , 'Abort the run after a certain number of failures (1 by default).' ) do |argument |
@@ -106,28 +97,16 @@ def parser(options)
106
97
options [ :dry_run ] = true
107
98
end
108
99
109
- parser . on ( '-X' , '--[no-]drb' , 'Run examples via DRb.' ) do |o |
110
- if o
111
- options [ :runner ] = -> ( opts , err , out ) do
112
- require 'rspec/core/drb'
113
- begin
114
- DRbRunner . new ( opts ) . run ( err , out )
115
- exit
116
- rescue DRb ::DRbConnError
117
- err . puts "No DRb server is running. Running in local process instead ..."
118
- end
119
- end
120
- end
100
+ parser . on ( '-X' , '--[no-]drb' , 'Run examples via DRb.' ) do |use_drb |
101
+ options [ :runner ] = Callables . try_drb_runner if use_drb
121
102
end
122
103
123
104
parser . on ( '--drb-port PORT' , 'Port to connect to the DRb server.' ) do |o |
124
105
options [ :drb_port ] = o . to_i
125
106
end
126
107
127
108
parser . on ( '--init' , 'Initialize your project with RSpec.' ) do |_cmd |
128
- options [ :runner ] = -> ( *_args ) do
129
- initialize_project_and_exit
130
- end
109
+ options [ :runner ] = Callables . initialize_project_and_exit
131
110
end
132
111
133
112
parser . separator ( "\n **** Output ****\n \n " )
@@ -264,9 +243,7 @@ def parser(options)
264
243
parser . separator ( "\n **** Utility ****\n \n " )
265
244
266
245
parser . on ( '-v' , '--version' , 'Display the version.' ) do
267
- options [ :runner ] = -> ( *_args ) do
268
- print_version_and_exit
269
- end
246
+ options [ :runner ] = Callables . print_version_and_exit
270
247
end
271
248
272
249
# These options would otherwise be confusing to users, so we forcibly
@@ -278,9 +255,7 @@ def parser(options)
278
255
invalid_options = %w[ -d --I ]
279
256
280
257
parser . on_tail ( '-h' , '--help' , "You're looking at it." ) do
281
- options [ :runner ] = -> ( *_args ) do
282
- print_help_and_exit ( parser , invalid_options )
283
- end
258
+ options [ :runner ] = Callables . print_help_and_exit ( parser , invalid_options )
284
259
end
285
260
286
261
# This prevents usage of the invalid_options.
@@ -308,26 +283,64 @@ def configure_only_failures(options)
308
283
add_tag_filter ( options , :inclusion_filter , :last_run_status , 'failed' )
309
284
end
310
285
311
- def initialize_project_and_exit
312
- RSpec ::Support . require_rspec_core "project_initializer"
313
- ProjectInitializer . new . run
314
- exit
315
- end
286
+ module Callables
287
+ class << self
288
+ def initialize_project_and_exit
289
+ lambda do |*_args |
290
+ RSpec ::Support . require_rspec_core "project_initializer"
291
+ ProjectInitializer . new . run
292
+ exit
293
+ end
294
+ end
316
295
317
- def bisect_formatter_for ( argument )
318
- return Formatters ::BisectDebugFormatter if argument == "verbose"
319
- Formatters ::BisectProgressFormatter
320
- end
296
+ def try_drb_runner
297
+ lambda do |options , err , out |
298
+ require 'rspec/core/drb'
299
+ begin
300
+ DRbRunner . new ( options ) . run ( err , out )
301
+ exit
302
+ rescue DRb ::DRbConnError
303
+ err . puts "No DRb server is running. Running in local process instead ..."
304
+ end
305
+ end
306
+ end
321
307
322
- def print_version_and_exit
323
- puts RSpec ::Core ::Version ::STRING
324
- exit
325
- end
308
+ def bisect_and_exit
309
+ lambda do |options , _err , _out |
310
+ RSpec ::Support . require_rspec_core "bisect/coordinator"
311
+
312
+ success = Bisect ::Coordinator . bisect_with (
313
+ options . args ,
314
+ RSpec . configuration ,
315
+ bisect_formatter_for ( options . options [ :bisect ] )
316
+ )
317
+
318
+ exit ( success ? 0 : 1 )
319
+ end
320
+ end
321
+
322
+ def print_version_and_exit
323
+ lambda do |*_args |
324
+ puts RSpec ::Core ::Version ::STRING
325
+ exit
326
+ end
327
+ end
328
+
329
+ def print_help_and_exit ( parser , invalid_options )
330
+ lambda do |*_args |
331
+ # Removing the blank invalid options from the output.
332
+ puts parser . to_s . gsub ( /^\s +(#{ invalid_options . join ( '|' ) } )\s *$\n / , '' )
333
+ exit
334
+ end
335
+ end
336
+
337
+ private
326
338
327
- def print_help_and_exit ( parser , invalid_options )
328
- # Removing the blank invalid options from the output.
329
- puts parser . to_s . gsub ( /^\s +(#{ invalid_options . join ( '|' ) } )\s *$\n / , '' )
330
- exit
339
+ def bisect_formatter_for ( argument )
340
+ return Formatters ::BisectDebugFormatter if argument == "verbose"
341
+ Formatters ::BisectProgressFormatter
342
+ end
343
+ end
331
344
end
332
345
end
333
346
end
0 commit comments