Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 6ee83a5

Browse files
Sketch of generating runnables in OptionParser
1 parent b7a49ca commit 6ee83a5

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

lib/rspec/core/option_parser.rb

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,17 @@ def parser(options)
6868

6969
parser.on('--bisect[=verbose]', 'Repeatedly runs the suite in order to isolate the failures to the ',
7070
' smallest reproducible case.') do |argument|
71-
options[:bisect] = argument || true
71+
options[:runner] = -> (opts, err, out) do
72+
RSpec::Support.require_rspec_core "bisect/coordinator"
73+
74+
success = Bisect::Coordinator.bisect_with(
75+
opts.command_line_and_env_args,
76+
RSpec.configuration,
77+
bisect_formatter_for(argument)
78+
)
79+
80+
exit(success ? 0 : 1)
81+
end
7282
end
7383

7484
parser.on('--[no-]fail-fast[=COUNT]', 'Abort the run after a certain number of failures (1 by default).') do |argument|
@@ -97,15 +107,27 @@ def parser(options)
97107
end
98108

99109
parser.on('-X', '--[no-]drb', 'Run examples via DRb.') do |o|
100-
options[:drb] = 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
101121
end
102122

103123
parser.on('--drb-port PORT', 'Port to connect to the DRb server.') do |o|
104124
options[:drb_port] = o.to_i
105125
end
106126

107127
parser.on('--init', 'Initialize your project with RSpec.') do |_cmd|
108-
initialize_project_and_exit
128+
options[:runner] = -> (*_args) do
129+
initialize_project_and_exit
130+
end
109131
end
110132

111133
parser.separator("\n **** Output ****\n\n")
@@ -242,7 +264,9 @@ def parser(options)
242264
parser.separator("\n **** Utility ****\n\n")
243265

244266
parser.on('-v', '--version', 'Display the version.') do
245-
print_version_and_exit
267+
options[:runner] = -> (*_args) do
268+
print_version_and_exit
269+
end
246270
end
247271

248272
# These options would otherwise be confusing to users, so we forcibly
@@ -254,7 +278,9 @@ def parser(options)
254278
invalid_options = %w[-d --I]
255279

256280
parser.on_tail('-h', '--help', "You're looking at it.") do
257-
print_help_and_exit(parser, invalid_options)
281+
options[:runner] = -> (*_args) do
282+
print_help_and_exit(parser, invalid_options)
283+
end
258284
end
259285

260286
# This prevents usage of the invalid_options.
@@ -282,6 +308,11 @@ def configure_only_failures(options)
282308
add_tag_filter(options, :inclusion_filter, :last_run_status, 'failed')
283309
end
284310

311+
def bisect_formatter_for(argument)
312+
return Formatters::BisectDebugFormatter if argument == "verbose"
313+
Formatters::BisectProgressFormatter
314+
end
315+
285316
def initialize_project_and_exit
286317
RSpec::Support.require_rspec_core "project_initializer"
287318
ProjectInitializer.new.run

lib/rspec/core/runner.rb

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,13 @@ def self.run(args, err=$stderr, out=$stdout)
6565
trap_interrupt
6666
options = ConfigurationOptions.new(args)
6767

68-
if options.options[:drb]
69-
require 'rspec/core/drb'
70-
begin
71-
DRbRunner.new(options).run(err, out)
72-
return
73-
rescue DRb::DRbConnError
74-
err.puts "No DRb server is running. Running in local process instead ..."
75-
end
76-
elsif options.options[:bisect]
77-
bisect_and_exit(options.options[:bisect], options.command_line_and_env_args)
68+
if options.options[:runner]
69+
options.options[:runner].call(options, err, out)
7870
end
7971

8072
new(options).run(err, out)
8173
end
8274

83-
def self.bisect_and_exit(argument, original_args)
84-
RSpec::Support.require_rspec_core "bisect/coordinator"
85-
86-
success = Bisect::Coordinator.bisect_with(
87-
original_args,
88-
RSpec.configuration,
89-
bisect_formatter_for(argument)
90-
)
91-
92-
exit(success ? 0 : 1)
93-
end
94-
95-
def self.bisect_formatter_for(argument)
96-
return Formatters::BisectDebugFormatter if argument == "verbose"
97-
Formatters::BisectProgressFormatter
98-
end
99-
10075
def initialize(options, configuration=RSpec.configuration, world=RSpec.world)
10176
@options = options
10277
@configuration = configuration

0 commit comments

Comments
 (0)