Permalink
Browse files

Don't do stuff on initialization - remember?

  • Loading branch information...
dchelimsky committed Jun 10, 2010
1 parent 117ec8e commit 2e187117467a3f83ea035e6b1905f480a891bce1
@@ -3,6 +3,7 @@ module Core
class CommandLine
def initialize(argv)
@options = RSpec::Core::ConfigurationOptions.new(argv)
+ @options.parse_options
@options.configure(configuration)
configuration.require_files_to_run
configuration.configure_mock_framework
@@ -12,7 +12,6 @@ class ConfigurationOptions
def initialize(args)
@args = args
- @options = parse_options
end
def configure(config)
@@ -33,18 +32,20 @@ def drb_argv
argv + options[:files_or_directories_to_run]
end
- private
-
def parse_options
- command_line_options = parse_command_line_options
- local_options = parse_local_options(command_line_options)
- global_options = parse_global_options
+ @options = begin
+ command_line_options = parse_command_line_options
+ local_options = parse_local_options(command_line_options)
+ global_options = parse_global_options
- [global_options, local_options, command_line_options].inject do |merged, options|
- merged.merge(options)
- end
+ [global_options, local_options, command_line_options].inject do |merged, options|
+ merged.merge(options)
+ end
+ end
end
+ private
+
def parse_command_line_options
options = Parser.parse!(@args)
options[:files_or_directories_to_run] = @args
@@ -3,6 +3,7 @@ module Core
class DRbCommandLine
def initialize(argv)
@options = RSpec::Core::ConfigurationOptions.new(argv)
+ @options.parse_options
end
def drb_port
@@ -5,7 +5,9 @@
describe RSpec::Core::ConfigurationOptions do
def config_options_object(*args)
- RSpec::Core::ConfigurationOptions.new(args)
+ coo = RSpec::Core::ConfigurationOptions.new(args)
+ coo.parse_options
+ coo
end
def options_from_args(*args)
@@ -195,17 +197,19 @@ def options_from_args(*args)
File.stub(:exist?) { true }
File.stub(:readlines) { ["--formatter", "doc"] }
- cli_options = RSpec::Core::ConfigurationOptions.new([])
- cli_options.configure(config)
+ config_options = RSpec::Core::ConfigurationOptions.new([])
+ config_options.parse_options
+ config_options.configure(config)
config.formatter.should == 'doc'
end
it "allows options on one line" do
File.stub(:exist?) { true }
File.stub(:readlines) { ["--formatter doc"] }
- cli_options = RSpec::Core::ConfigurationOptions.new([])
- cli_options.configure(config)
+ config_options = RSpec::Core::ConfigurationOptions.new([])
+ config_options.parse_options
+ config_options.configure(config)
config.formatter.should == 'doc'
end
@@ -221,9 +225,10 @@ def options_from_args(*args)
raise "Unexpected path: #{path}"
end
end
- cli_options = RSpec::Core::ConfigurationOptions.new(["--no-color"])
+ config_options = RSpec::Core::ConfigurationOptions.new(["--no-color"])
+ config_options.parse_options
- cli_options.configure(config)
+ config_options.configure(config)
config.formatter.should == "documentation"
config.line_number.should == "37"
@@ -242,9 +247,10 @@ def options_from_args(*args)
raise "Unexpected path: #{path}"
end
end
- cli_options = RSpec::Core::ConfigurationOptions.new([])
+ config_options = RSpec::Core::ConfigurationOptions.new([])
+ config_options.parse_options
- cli_options.configure(config)
+ config_options.configure(config)
config.formatter.should == "local"
end
@@ -253,6 +259,7 @@ def options_from_args(*args)
config_options = RSpec::Core::ConfigurationOptions.new(['--formatter', 'progress'])
config_options.stub(:parse_options_file).and_return(:formatter => 'documentation')
+ config_options.parse_options
config_options.configure(config)
config.formatter.should == 'progress'
@@ -24,6 +24,7 @@ module RSpec::Core
@err = @out = StringIO.new
@options = RSpec::Core::ConfigurationOptions.new(%w[--drb --drb-port 8181 --color])
+ @options.parse_options
RSpec::Core::ConfigurationOptions.stub(:new) { @options }
@drb_proxy = double(RSpec::Core::DRbCommandLine, :run => true)

0 comments on commit 2e18711

Please sign in to comment.