Skip to content

Commit

Permalink
Merge ee7cd4d into a5cbdab
Browse files Browse the repository at this point in the history
  • Loading branch information
HotFusionMan committed May 27, 2013
2 parents a5cbdab + ee7cd4d commit 43a4649
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/guard/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def start
end

def run_all
passed = @runner.run(@inspector.spec_paths, @options[:run_all].merge(:message => 'Running all specs'))
passed = @runner.run(@inspector.spec_paths, @options[:run_all].merge(:message => 'Running all specs', :run_all_specs => true))

unless @last_failed = !passed
@failed_paths = []
Expand Down
19 changes: 11 additions & 8 deletions lib/guard/rspec/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def run(paths, options = {})
end
end

def rspec_executable
command = parallel? ? 'parallel_rspec' : 'rspec'
def rspec_executable(runtime_options = {})
command = parallel?(runtime_options) ? 'parallel_rspec' : 'rspec'
@rspec_executable ||= (binstubs? && !executable_prefix?) ? "#{binstubs}/#{command}" : command
end

Expand Down Expand Up @@ -118,9 +118,9 @@ def rspec_command(paths, options)
cmd_parts << bin_command('foreman run') if foreman?
cmd_parts << "bundle exec" if bundle_exec?
cmd_parts << executable_prefix if executable_prefix?
cmd_parts << rspec_executable
cmd_parts << rspec_arguments(paths, options) if !parallel?
cmd_parts << parallel_rspec_arguments(paths, options) if parallel?
cmd_parts << rspec_executable(options)
cmd_parts << rspec_arguments(paths, options) if !parallel?(options)
cmd_parts << parallel_rspec_arguments(paths, options) if parallel?(options)
cmd_parts.compact.join(' ')
end

Expand Down Expand Up @@ -213,9 +213,12 @@ def zeus?
options.fetch(:zeus, false)
end

def parallel?
parallel = options.fetch(:parallel, false)
(run_all = options[:run_all]) ? (run_all[:parallel] || parallel) : parallel
def parallel?(runtime_options = {})
if runtime_options[:run_all_specs]
runtime_options[:parallel]
else
options.fetch(:parallel, false)
end
end

def spring?
Expand Down
30 changes: 27 additions & 3 deletions spec/guard/rspec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -627,19 +627,43 @@
end
end

describe ':run_all' do
context ':parallel => true' do
subject { described_class.new(:run_all => {:parallel => true}) }
describe ':run_all =>' do
context '{:parallel => true}' do
options = { :run_all => {:parallel => true} }
subject { described_class.new(options) }

it 'runs with parallel_rspec' do
subject.should_receive(:system).with(
'bundle exec parallel_rspec ' <<
"-o '-f progress -r #{@lib_path.join('guard/rspec/formatter.rb')} -f Guard::RSpec::Formatter --failure-exit-code 2' spec"
).and_return(true)

subject.run(['spec'], options[:run_all].merge(:run_all_specs => true))
end

it 'does not use parallel_rspec unless #run_all was called' do
subject.should_receive(:system).with(
"bundle exec rspec -f progress -r #{@lib_path.join('guard/rspec/formatter.rb')} " <<
'-f Guard::RSpec::Formatter --failure-exit-code 2 spec'
).and_return(true)

subject.run(['spec'])
end
end

context '{:parallel => false}' do
options = { :run_all => {:parallel => false} }
subject { described_class.new(options) }

it 'does not use parallel_rspec' do
subject.should_receive(:system).with(
"bundle exec rspec -f progress -r #{@lib_path.join('guard/rspec/formatter.rb')} " <<
'-f Guard::RSpec::Formatter --failure-exit-code 2 spec'
).and_return(true)

subject.run(['spec'], options[:run_all].merge(:run_all_specs => true))
end
end
end
end
end
Expand Down
12 changes: 9 additions & 3 deletions spec/guard/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@
subject.run_all
end

it 'passes the :run_all_specs argument' do
runner.should_receive(:run).with(['spec'], (hash_including(:run_all_specs => true))) { true }

subject.run_all
end

it 'passes the :run_all options' do
subject = described_class.new([], {
:rvm => ['1.8.7', '1.9.2'], :cli => '--color', :run_all => { :cli => '--format progress' }
:rvm => ['1.8.7', '1.9.2'], :cli => '--color', :run_all => { :cli => '--format progress', :parallel => true, :parallel_cli => '-n 42' }
})
runner.should_receive(:run).with(['spec'], hash_including(:cli => '--format progress')) { true }
runner.should_receive(:run).with(['spec'], hash_including(:cli => '--format progress', :parallel => true, :parallel_cli => '-n 42')) { true }

subject.run_all
end
Expand Down Expand Up @@ -215,7 +221,7 @@

runner.should_receive(:run).with(['./a_spec.rb:1', './a_spec.rb:7']) { true }
runner.should_receive(:run).with(['./a_spec.rb', './b_spec']) { true }
runner.should_receive(:run).with(['spec'], :message => "Running all specs") { true }
runner.should_receive(:run).with(['spec'], :message => "Running all specs", :run_all_specs => true) { true }

@subject.run_on_changes(['./a_spec.rb','./b_spec'])
end
Expand Down

0 comments on commit 43a4649

Please sign in to comment.