Skip to content

Commit

Permalink
Add support for drb
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolgual authored and yannlugrin committed Jun 12, 2011
1 parent 97c57a5 commit 36a90e3
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.rdoc
Expand Up @@ -79,6 +79,12 @@ You can enable rubygems usage to run minitest (only if bundler is not present or
...
end

If you use {spork-testunit}[https://github.com/timcharper/spork-testunit] you can enable it with (you'll have to load it before):

guard 'minitest', :drb => true do
...
end

== Development

- Source hosted at {GitHub}[http://github.com/guard/guard-minitest]
Expand Down
42 changes: 28 additions & 14 deletions lib/guard/minitest/runner.rb
Expand Up @@ -16,7 +16,8 @@ def initialize(options = {})
:verbose => false,
:notify => true,
:bundler => File.exist?("#{Dir.pwd}/Gemfile"),
:rubygems => false
:rubygems => false,
:drb => false
}.merge(options)
end

Expand Down Expand Up @@ -46,26 +47,39 @@ def rubygems?
!bundler? && @options[:rubygems]
end

def drb?
@options[:drb]
end

private

def minitest_command(paths)
cmd_parts = []
cmd_parts << "bundle exec" if bundler?
cmd_parts << 'ruby -Itest -Ispec'
cmd_parts << '-r rubygems' if rubygems?
cmd_parts << '-r bundler/setup' if bundler?
paths.each do |path|
cmd_parts << "-r ./#{path}"
end
cmd_parts << "-r #{File.expand_path('../runners/default_runner.rb', __FILE__)}"
if notify?
cmd_parts << '-e \'GUARD_NOTIFY=true; MiniTest::Unit.autorun\''
if drb?
cmd_parts << 'testdrb'
cmd_parts << 'test/test_helper.rb' if File.exist?('test/test_helper.rb')
cmd_parts << 'spec/spec_helper.rb' if File.exist?('spec/spec_helper.rb')
paths.each do |path|
cmd_parts << "./#{path}"
end
else
cmd_parts << '-e \'GUARD_NOTIFY=false; MiniTest::Unit.autorun\''
cmd_parts << 'ruby -Itest -Ispec'
cmd_parts << '-r rubygems' if rubygems?
cmd_parts << '-r bundler/setup' if bundler?
paths.each do |path|
cmd_parts << "-r ./#{path}"
end
cmd_parts << "-r #{File.expand_path('../runners/default_runner.rb', __FILE__)}"
if notify?
cmd_parts << '-e \'GUARD_NOTIFY=true; MiniTest::Unit.autorun\''
else
cmd_parts << '-e \'GUARD_NOTIFY=false; MiniTest::Unit.autorun\''
end
cmd_parts << '--'
cmd_parts << "--seed #{seed}" unless seed.nil?
cmd_parts << '--verbose' if verbose?
end
cmd_parts << '--'
cmd_parts << "--seed #{seed}" unless seed.nil?
cmd_parts << '--verbose' if verbose?
cmd_parts.join(' ')
end

Expand Down
39 changes: 39 additions & 0 deletions spec/guard/minitest/runner_spec.rb
Expand Up @@ -82,6 +82,18 @@
end

end

describe 'drb' do

it 'default should be false' do
subject.new.drb?.must_equal false
end

it 'should be set' do
subject.new(:drb => true).drb?.must_equal true
end

end
end

describe 'run' do
Expand Down Expand Up @@ -179,5 +191,32 @@

end

describe 'drb' do
describe 'when using test_helper' do
it 'should run with drb' do
runner = subject.new(:drb => true)
Guard::UI.expects(:info)
File.expects(:exist?).with('test/test_helper.rb').returns(true)
File.expects(:exist?).with('spec/spec_helper.rb').returns(false)
runner.expects(:system).with(
"testdrb test/test_helper.rb ./test/test_minitest.rb"
)
runner.run(['test/test_minitest.rb'], :drb => true)
end
end

describe 'when using spec_helper' do
it 'should run with drb' do
runner = subject.new(:drb => true)
Guard::UI.expects(:info)
File.expects(:exist?).with('test/test_helper.rb').returns(false)
File.expects(:exist?).with('spec/spec_helper.rb').returns(true)
runner.expects(:system).with(
"testdrb spec/spec_helper.rb ./test/test_minitest.rb"
)
runner.run(['test/test_minitest.rb'], :drb => true)
end
end
end
end
end

0 comments on commit 36a90e3

Please sign in to comment.