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

Commit b2fea38

Browse files
committed
Rename parse_options to options and have it return a memoized value.
The old way was odd. It created an ordering dependency (you had to call `parse_options` after instantiating the object but before doing anything else) and calling it a second time had the side effect of re-parsing the args, which wasn't needed or intended. It's far easier/better to make `options` do the parsing and memoize the result.
1 parent feead38 commit b2fea38

File tree

7 files changed

+9
-21
lines changed

7 files changed

+9
-21
lines changed

lib/rspec/core/command_line.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class CommandLine
44
def initialize(options, configuration=RSpec::configuration, world=RSpec::world)
55
if Array === options
66
options = ConfigurationOptions.new(options)
7-
options.parse_options
87
end
98
@options = options
109
@configuration = configuration

lib/rspec/core/configuration_options.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ module RSpec
55
module Core
66
# @private
77
class ConfigurationOptions
8-
attr_reader :options
9-
108
def initialize(args)
119
@args = args.map {|a|
1210
a.sub("default_path", "default-path").sub("line_number", "line-number")
@@ -20,8 +18,8 @@ def configure(config)
2018
load_formatters_into config
2119
end
2220

23-
def parse_options
24-
@options = (file_options << command_line_options << env_options).
21+
def options
22+
@options ||= (file_options << command_line_options << env_options).
2523
each {|opts|
2624
filter_manager.include opts.delete(:inclusion_filter) if opts.has_key?(:inclusion_filter)
2725
filter_manager.exclude opts.delete(:exclusion_filter) if opts.has_key?(:exclusion_filter)

lib/rspec/core/runner.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def self.trap_interrupt
8787
def self.run(args, err=$stderr, out=$stdout)
8888
trap_interrupt
8989
options = ConfigurationOptions.new(args)
90-
options.parse_options
9190

9291
if options.options[:drb]
9392
require 'rspec/core/drb_command_line'

spec/rspec/core/command_line_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module RSpec::Core
3333
it "assigns ConfigurationOptions built from Array of options to @options" do
3434
config_options = ConfigurationOptions.new(%w[--color])
3535
command_line = CommandLine.new(%w[--color])
36-
expect(command_line.instance_eval { @options.options }).to eq(config_options.parse_options)
36+
expect(command_line.instance_eval { @options.options }).to eq(config_options.options)
3737
end
3838

3939
it "assigns submitted ConfigurationOptions to @options" do
@@ -106,9 +106,7 @@ def build_command_line *args
106106
end
107107

108108
def build_config_options *args
109-
options = ConfigurationOptions.new args
110-
options.parse_options
111-
options
109+
ConfigurationOptions.new args
112110
end
113111
end
114112
end

spec/rspec/core/configuration_options_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
it "warns when HOME env var is not set", :unless => (RUBY_PLATFORM == 'java') do
99
without_env_vars 'HOME' do
1010
expect_warning_with_call_site(__FILE__, __LINE__ + 1)
11-
RSpec::Core::ConfigurationOptions.new([]).parse_options
11+
RSpec::Core::ConfigurationOptions.new([]).options
1212
end
1313
end
1414

15-
it "duplicates the arguments array" do
15+
it "does not mutate the provided args array" do
1616
args = ['-e', 'some spec']
17-
coo = RSpec::Core::ConfigurationOptions.new(args)
18-
coo.parse_options
17+
RSpec::Core::ConfigurationOptions.new(args).options
1918
expect(args).to eq(['-e', 'some spec'])
2019
end
2120

spec/rspec/core/drb_command_line_spec.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ def command_line(*args)
1313
end
1414

1515
def config_options(*args)
16-
options = RSpec::Core::ConfigurationOptions.new(args)
17-
options.parse_options
18-
options
16+
RSpec::Core::ConfigurationOptions.new(args)
1917
end
2018

2119
context "without server running" do
@@ -69,7 +67,6 @@ def with_RSPEC_DRB_set_to(val)
6967
class SimpleDRbSpecServer
7068
def self.run(argv, err, out)
7169
options = RSpec::Core::ConfigurationOptions.new(argv)
72-
options.parse_options
7370
config = RSpec::Core::Configuration.new
7471
RSpec::Core::CommandLine.new(options, config).run(err, out)
7572
end

spec/support/config_options_helper.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ module ConfigOptionsHelper
44
around(:each) { |e| without_env_vars('SPEC_OPTS', &e) }
55

66
def config_options_object(*args)
7-
coo = RSpec::Core::ConfigurationOptions.new(args)
8-
coo.parse_options
9-
coo
7+
RSpec::Core::ConfigurationOptions.new(args)
108
end
119

1210
def parse_options(*args)

0 commit comments

Comments
 (0)