Skip to content

Commit

Permalink
Take a :drb option in Guardfile
Browse files Browse the repository at this point in the history
If :drb is true pass the --drb flag to RSpec each time we run specs
  • Loading branch information
James Conroy-Finn committed Nov 4, 2010
1 parent 05f2201 commit f19b8b6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
7 changes: 6 additions & 1 deletion lib/guard/rspec.rb
Expand Up @@ -7,6 +7,11 @@ class RSpec < Guard
autoload :Runner, 'guard/rspec/runner'
autoload :Inspector, 'guard/rspec/inspector'

def initialize(watchers = [], options = {})
super
Runner.use_drb(options)
end

def start
Runner.set_rspec_version(options)
end
Expand All @@ -21,4 +26,4 @@ def run_on_change(paths)
end

end
end
end
28 changes: 20 additions & 8 deletions lib/guard/rspec/runner.rb
Expand Up @@ -3,22 +3,31 @@ class RSpec
module Runner
class << self
attr_reader :rspec_version

def run(paths, options = {})
message = options[:message] || "Running: #{paths.join(' ')}"
UI.info message, :reset => true
system(rspec_command(paths))
end

def set_rspec_version(options = {})
@rspec_version = options[:version] || determine_rspec_version
end


def use_drb(options = {})
@use_drb = options[:drb] == true
end

def using_drb?
@use_drb
end

private

def rspec_command(paths)
cmd_parts = []
cmd_parts << "bundle exec" if bundler?

case rspec_version
when 1
cmd_parts << "spec"
Expand All @@ -27,15 +36,18 @@ def rspec_command(paths)
cmd_parts << "rspec"
cmd_parts << "--require #{File.dirname(__FILE__)}/formatters/rspec_notify.rb --format RSpecNotify"
end

cmd_parts << "--drb" if using_drb?
cmd_parts << "--color"

cmd_parts << paths.join(' ')
cmd_parts.join(" ")
end

def bundler?
@bundler ||= File.exist?("#{Dir.pwd}/Gemfile")
end

def determine_rspec_version
UI.info "Determine rspec_version... (can be forced with Guard::RSpec version option)"
if File.exist?("#{Dir.pwd}/spec/spec_helper.rb")
Expand All @@ -48,8 +60,8 @@ def determine_rspec_version
2
end
end

end
end
end
end
end
16 changes: 14 additions & 2 deletions spec/guard/rspec/runner_spec.rb
@@ -1,8 +1,20 @@
require 'spec_helper'

describe Guard::RSpec::Runner do
subject { Guard::RSpec::Runner}

subject { Guard::RSpec::Runner }

describe 'using_drb?' do
it 'is true when DRB options is true' do
subject.use_drb({:drb => true})
subject.should be_using_drb
end

it 'is false when the DRB option is anything but true' do
subject.use_drb({:drb => 'strawberry jam'})
subject.should_not be_using_drb
end
end

describe "run" do

context "in empty folder" do
Expand Down
9 changes: 8 additions & 1 deletion spec/guard/rspec_spec.rb
Expand Up @@ -2,7 +2,14 @@

describe Guard::RSpec do
subject { Guard::RSpec.new }


describe '#initialize' do
it 'should pass options to the Runner.use_drb' do
Guard::RSpec::Runner.should_receive(:use_drb).with({:drb => true})
Guard::RSpec.new([], {:drb => true})
end
end

describe "start" do
it "should set rspec_version" do
Guard::RSpec::Runner.should_receive(:set_rspec_version)
Expand Down

0 comments on commit f19b8b6

Please sign in to comment.