Skip to content

Commit

Permalink
Merge remote branch 'cflipse/1.2.9/drb_port' into LH_875
Browse files Browse the repository at this point in the history
* cflipse/1.2.9/drb_port:
  specify drb server through --port option
  pull drb port value from RSPEC_DRB environment

[#875 state:resolved milestone:'Next Release']
  • Loading branch information
dchelimsky committed Nov 23, 2009
2 parents 029f77c + ef449c3 commit e048b37
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/spec/runner/drb_command_line.rb
Expand Up @@ -4,6 +4,12 @@ module Spec
module Runner
# Facade to run specs by connecting to a DRB server
class DrbCommandLine
# port to run against
def self.port(options)
(options.drb_port || ENV["RSPEC_DRB"] || 8989).to_i
end


# Runs specs on a DRB server. Note that this API is similar to that of
# CommandLine - making it possible for clients to use both interchangeably.
def self.run(options)
Expand All @@ -13,14 +19,15 @@ def self.run(options)
rescue SocketError; \
DRb.start_service("druby://:0"); \
end
spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
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
options.error_stream.puts "No server is running"
false
end
end

end
end
end
2 changes: 2 additions & 0 deletions lib/spec/runner/option_parser.rb
Expand Up @@ -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"]
}
Expand Down Expand Up @@ -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}
Expand Down
7 changes: 6 additions & 1 deletion lib/spec/runner/options.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions spec/spec/runner/drb_command_line_spec.rb
Expand Up @@ -101,6 +101,47 @@ def tty?; true end
end
end

context "port" do
before do
@options = stub("options", :drb_port => nil)
end


it "should default to 8989" do
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(@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


end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/spec/runner/option_parser_spec.rb
Expand Up @@ -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"])
Expand Down
7 changes: 7 additions & 0 deletions spec/spec/runner/options_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit e048b37

Please sign in to comment.