Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pass configuration and world to [DRb]CommandLine.new

- part of effort to reduce/eliminate global state
  • Loading branch information...
commit 1b2163b0af97c554bc13114b1e2640471b3c193f 1 parent c38d497
@dchelimsky dchelimsky authored
View
37 lib/rspec/core/command_line.rb
@@ -1,29 +1,26 @@
module RSpec
module Core
class CommandLine
- def initialize(args_or_options)
- if RSpec::Core::ConfigurationOptions === args_or_options
- @options = args_or_options
- else
- @options = RSpec::Core::ConfigurationOptions.new(args_or_options)
- @options.parse_options
- end
- @options.configure(configuration)
+ def initialize(options, configuration=RSpec::configuration, world=RSpec::world)
+ options.configure(configuration)
configuration.require_files_to_run
configuration.configure_mock_framework
+ @configuration = configuration
+ @options = options
+ @world = world
end
def run(err, out)
- configuration.error_stream = err
- configuration.output_stream = out
- world.announce_inclusion_filter
+ @configuration.error_stream = err
+ @configuration.output_stream = out
+ @world.announce_inclusion_filter
- configuration.reporter.report(example_count) do |reporter|
+ @configuration.reporter.report(example_count) do |reporter|
begin
- configuration.run_hook(:before, :suite)
+ @configuration.run_hook(:before, :suite)
example_groups.run_examples(reporter)
ensure
- configuration.run_hook(:after, :suite)
+ @configuration.run_hook(:after, :suite)
end
end
@@ -33,7 +30,7 @@ def run(err, out)
private
def example_count
- world.example_count
+ @world.example_count
end
module ExampleGroups
@@ -47,15 +44,7 @@ def success?
end
def example_groups
- world.example_groups.extend(ExampleGroups)
- end
-
- def configuration
- RSpec.configuration
- end
-
- def world
- RSpec.world
+ @world.example_groups.extend(ExampleGroups)
end
end
end
View
5 lib/rspec/core/drb_command_line.rb
@@ -1,8 +1,11 @@
module RSpec
module Core
class DRbCommandLine
- def initialize(options)
+ def initialize(options, configuration=RSpec::configuration, ignore_world=nil)
+ # ignore_world in the argument list is just there to keep the
+ # APIs for CommandLine and DRbCommandLine aligned
@options = options
+ @configuration = configuration
end
def drb_port
View
4 lib/rspec/core/runner.rb
@@ -39,11 +39,11 @@ def self.run(args, err, out)
end
def self.run_over_drb(options, err, out)
- DRbCommandLine.new(options).run(err, out)
+ DRbCommandLine.new(options, RSpec::configuration, RSpec::world).run(err, out)
end
def self.run_in_process(options, err, out)
- CommandLine.new(options).run(err, out)
+ CommandLine.new(options, RSpec::configuration, RSpec::world).run(err, out)
end
end
View
10 spec/rspec/core/command_line_spec.rb
@@ -3,13 +3,6 @@
module RSpec::Core
describe CommandLine do
- context "given an array" do
- it "converts the contents to a ConfigurationOptions object" do
- command_line = CommandLine.new(%w[--color])
- command_line.instance_eval { @options }.should be_a(ConfigurationOptions)
- end
- end
-
context "given a ConfigurationOptions object" do
it "assigns it to @options" do
config_options = ConfigurationOptions.new(%w[--color])
@@ -27,7 +20,7 @@ module RSpec::Core
end
let(:command_line) do
- CommandLine.new(config_options)
+ CommandLine.new(config_options, config)
end
let(:config) do
@@ -37,7 +30,6 @@ module RSpec::Core
let(:out) { ::StringIO.new }
before do
- command_line.stub(:configuration) { config }
config.stub(:run_hook)
end
View
22 spec/rspec/core/drb_command_line_spec.rb
@@ -1,14 +1,12 @@
require "spec_helper"
describe "::DRbCommandLine", :ruby => "!jruby" do
- before do
- RSpec.stub(:configuration).and_return(RSpec::Core::Configuration.new)
- end
+ let(:config) { RSpec::Core::Configuration.new }
context "without server running" do
it "prints error" do
err = out = StringIO.new
- RSpec::Core::DRbCommandLine.new([]).run(err, out)
+ RSpec::Core::DRbCommandLine.new([], config).run(err, out)
err.rewind
err.read.should =~ /No DRb server is running/
@@ -16,7 +14,7 @@
it "returns false" do
err = out = StringIO.new
- result = RSpec::Core::DRbCommandLine.new([]).run(err, out)
+ result = RSpec::Core::DRbCommandLine.new([], config).run(err, out)
result.should be_false
end
end
@@ -39,14 +37,14 @@ def with_RSPEC_DRB_set_to(val)
context "without RSPEC_DRB environment variable set" do
it "defaults to 8989" do
with_RSPEC_DRB_set_to(nil) do
- RSpec::Core::DRbCommandLine.new([]).drb_port.should == 8989
+ RSpec::Core::DRbCommandLine.new([], config).drb_port.should == 8989
end
end
it "sets the DRb port" do
with_RSPEC_DRB_set_to(nil) do
- RSpec::Core::DRbCommandLine.new(["--drb-port", "1234"]).drb_port.should == 1234
- RSpec::Core::DRbCommandLine.new(["--drb-port", "5678"]).drb_port.should == 5678
+ RSpec::Core::DRbCommandLine.new(["--drb-port", "1234"], config).drb_port.should == 1234
+ RSpec::Core::DRbCommandLine.new(["--drb-port", "5678"], config).drb_port.should == 5678
end
end
end
@@ -56,7 +54,7 @@ def with_RSPEC_DRB_set_to(val)
context "without config variable set" do
it "uses RSPEC_DRB value" do
with_RSPEC_DRB_set_to('9000') do
- RSpec::Core::DRbCommandLine.new([]).drb_port.should == "9000"
+ RSpec::Core::DRbCommandLine.new([], config).drb_port.should == "9000"
end
end
end
@@ -64,7 +62,7 @@ def with_RSPEC_DRB_set_to(val)
context "and config variable set" do
it "uses configured value" do
with_RSPEC_DRB_set_to('9000') do
- RSpec::Core::DRbCommandLine.new(%w[--drb-port 5678]).drb_port.should == 5678
+ RSpec::Core::DRbCommandLine.new(%w[--drb-port 5678], config).drb_port.should == 5678
end
end
end
@@ -119,14 +117,14 @@ def create_dummy_spec_file
def run_spec_via_druby(argv)
err, out = StringIO.new, StringIO.new
- RSpec::Core::DRbCommandLine.new(argv.push("--drb-port", @drb_port.to_s)).run(err, out)
+ RSpec::Core::DRbCommandLine.new(argv.push("--drb-port", @drb_port.to_s), config).run(err, out)
out.rewind
out.read
end
it "returns true" do
err, out = StringIO.new, StringIO.new
- result = RSpec::Core::DRbCommandLine.new(["--drb-port", @drb_port.to_s]).run(err, out)
+ result = RSpec::Core::DRbCommandLine.new(["--drb-port", @drb_port.to_s], config).run(err, out)
result.should be_true
end
Please sign in to comment.
Something went wrong with that request. Please try again.