Skip to content
Browse files

specify drb server through --port option

  • Loading branch information...
1 parent 1b54ca2 commit ef449c38a7e98dd276ffb6e37758ef6f38a53801 @cflipse cflipse committed Aug 15, 2009
View
6 lib/spec/runner/drb_command_line.rb
@@ -5,8 +5,8 @@ module Runner
# Facade to run specs by connecting to a DRB server
class DrbCommandLine
# port to run against
- def self.port
- (ENV["RSPEC_DRB"] || 8989).to_i
+ def self.port(options)
+ (options.drb_port || ENV["RSPEC_DRB"] || 8989).to_i
end
@@ -19,7 +19,7 @@ def self.run(options)
rescue SocketError; \
DRb.start_service("druby://:0"); \
end
- spec_server = DRbObject.new_with_uri("druby://127.0.0.1:#{port}")
+ spec_server = DRbObject.new_with_uri("druby://127.0.0.1:#{port(options)}")
spec_server.run(options.argv, options.error_stream, options.output_stream)
true
rescue DRb::DRbConnError
View
2 lib/spec/runner/option_parser.rb
@@ -80,6 +80,7 @@ def spec_command?
:runner => ["-U", "--runner RUNNER", "Use a custom Runner."],
:debug => ["-u", "--debugger", "Enable ruby-debugging."],
:drb => ["-X", "--drb", "Run examples via DRb. (For example against script/spec_server)"],
+ :drb_port => ["--port PORT", "Port for DRb server. (Ignored without --drb)"],
:version => ["-v", "--version", "Show version"],
:help => ["-h", "--help", "You're looking at it"]
}
@@ -113,6 +114,7 @@ def initialize(err, out)
on(*OPTIONS[:runner]) {|runner| @options.user_input_for_runner = runner}
on(*OPTIONS[:debug]) {@options.debug = true}
on(*OPTIONS[:drb]) {}
+ on(*OPTIONS[:drb_port]) {|port| @options.drb_port = port}
on(*OPTIONS[:version]) {parse_version}
on("--autospec") {@options.autospec = true}
on_tail(*OPTIONS[:help]) {parse_help}
View
7 lib/spec/runner/options.rb
@@ -50,7 +50,8 @@ class Options
:argv
)
attr_reader :colour, :differ_class, :files, :examples, :example_groups
-
+ attr_writer :drb_port
+
def initialize(error_stream, output_stream)
@error_stream = error_stream
@output_stream = output_stream
@@ -289,6 +290,10 @@ def dry_run?
@dry_run == true
end
+ def drb_port
+ @drb_port.to_i if @drb_port
+ end
+
protected
def define_predicate_matchers
View
29 spec/spec/runner/drb_command_line_spec.rb
@@ -102,18 +102,43 @@ def tty?; true end
end
context "port" do
+ before do
+ @options = stub("options", :drb_port => nil)
+ end
+
+
it "should default to 8989" do
- Spec::Runner::DrbCommandLine.port.should == 8989
+ Spec::Runner::DrbCommandLine.port(@options).should == 8989
end
+
it "should pull default value from RSPEC_DRB environment" do
original = ENV['RSPEC_DRB']
begin
ENV['RSPEC_DRB'] = '9000'
- Spec::Runner::DrbCommandLine.port.should == 9000
+ Spec::Runner::DrbCommandLine.port(@options).should == 9000
ensure
ENV['RSPEC_DRB'] = original
end
end
+
+ it "should pull configured value" do
+ @options.stub(:drb_port => '5000')
+
+ Spec::Runner::DrbCommandLine.port(@options).should == 5000
+ end
+
+ it 'should prefer configured value to environment' do
+ @options.stub(:drb_port => '5000')
+ original = ENV['RSPEC_DRB']
+ begin
+ ENV['RSPEC_DRB'] = '9000'
+ Spec::Runner::DrbCommandLine.port(@options).should == 5000
+ ensure
+ ENV['RSPEC_DRB'] = original
+ end
+ end
+
+
end
View
9 spec/spec/runner/option_parser_spec.rb
@@ -63,6 +63,15 @@ def parse(args)
options = parse(["--drb", "-u"])
options.debug.should be_false
end
+
+ it "should accept port option" do
+ options = parse(["--port", "9000"])
+ options.drb_port.should == 9000
+ end
+
+ it 'should require argument to port option' do
+ lambda { parse(["--port"]) }.should raise_error(OptionParser::MissingArgument)
+ end
it "should accept dry run option" do
options = parse(["--dry-run"])
View
7 spec/spec/runner/options_spec.rb
@@ -266,6 +266,13 @@ module Runner
end
end
+ describe "#drb_port" do
+ it "returns a number" do
+ @options.drb_port = "400"
+ @options.drb_port.should == 400
+ end
+ end
+
describe "#number_of_examples" do
context "when --example is parsed" do
it "provides the number of examples parsed instead of the total number of examples collected" do

0 comments on commit ef449c3

Please sign in to comment.
Something went wrong with that request. Please try again.