Permalink
Browse files

use guard notification config

  • Loading branch information...
1 parent 7bc9a5b commit 60d71f418be24d995088eeb8dbaba8800fd4cad3 @yannlugrin yannlugrin committed Feb 24, 2012
Showing with 50 additions and 57 deletions.
  1. +15 −23 lib/guard/minitest/runner.rb
  2. +35 −34 spec/guard/minitest/runner_spec.rb
View
38 lib/guard/minitest/runner.rb
@@ -15,7 +15,6 @@ def initialize(options = {})
parse_deprecated_options(options)
@options = {
- :notify => true,
:bundler => File.exist?("#{Dir.pwd}/Gemfile"),
:rubygems => false,
:drb => false,
@@ -38,11 +37,11 @@ def cli_options
end
def verbose?
- @options[:cli] =~ /verbose/
+ @options[:cli].include?('--verbose')
end
def notify?
- @options[:notify]
+ !!@options[:notification]
end
def bundler?
@@ -69,46 +68,39 @@ def test_file_patterns
def minitest_command(paths)
cmd_parts = []
+
cmd_parts << "bundle exec" if bundler?
if drb?
cmd_parts << 'testdrb'
cmd_parts << "-r #{File.expand_path('../runners/default_runner.rb', __FILE__)}"
- if notify?
- cmd_parts << '-e \'::GUARD_NOTIFY=true\''
- else
- cmd_parts << '-e \'::GUARD_NOTIFY=false\''
- end
+ cmd_parts << "-e '::GUARD_NOTIFY=#{notify?}'"
test_folders.each do |f|
cmd_parts << "#{f}/test_helper.rb" if File.exist?("#{f}/test_helper.rb")
cmd_parts << "#{f}/spec_helper.rb" if File.exist?("#{f}/spec_helper.rb")
end
- paths.each do |path|
- cmd_parts << "./#{path}"
- end
+ cmd_parts += paths.map{|path| "./#{path}" }
else
cmd_parts << 'ruby'
- cmd_parts.concat test_folders.map{|f| %[-I"#{f}"]}
+ cmd_parts += test_folders.map{|f| %[-I"#{f}"] }
cmd_parts << '-r rubygems' if rubygems?
cmd_parts << '-r bundler/setup' if bundler?
- paths.each do |path|
- cmd_parts << "-r ./#{path}"
- end
+ cmd_parts += paths.map{|path| "-r ./#{path}" }
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 << '-e \'MiniTest::Unit.autorun\''
cmd_parts << '--' << cli_options unless cli_options.empty?
end
- cmd= cmd_parts.join(' ')
- puts "Running: #{cmd}\n\n" if verbose?
- cmd
+
+ cmd_parts.join(' ')
end
def parse_deprecated_options(options)
options[:cli] ||= ''
+ if value = options.delete(:notify)
+ options[:notification] = value
+ UI.info %{DEPRECATION WARNING: The :notify option is deprecated. Guard notification configuration is used.}
+ end
+
[:seed, :verbose].each do |key|
if value = options.delete(key)
options[:cli] << " --#{key}"
View
69 spec/guard/minitest/runner_spec.rb
@@ -34,18 +34,6 @@
end
- describe 'notify' do
-
- it 'default should be true' do
- subject.new.notify?.must_equal true
- end
-
- it 'should be set' do
- subject.new(:notify => false).notify?.must_equal false
- end
-
- end
-
describe 'bundler' do
it 'default should be true if Gemfile exist' do
@@ -111,7 +99,7 @@
runner = subject.new(:test_folders => %w[test], :seed => 12345)
Guard::UI.expects(:info)
runner.expects(:system).with(
- "ruby -I\"test\" -r ./test/test_minitest.rb -r #{@default_runner} -e 'GUARD_NOTIFY=true; MiniTest::Unit.autorun' -- --seed 12345"
+ "ruby -I\"test\" -r ./test/test_minitest.rb -r #{@default_runner} -e 'MiniTest::Unit.autorun' -- --seed 12345"
)
runner.run(['test/test_minitest.rb'])
end
@@ -120,16 +108,7 @@
runner = subject.new(:test_folders => %w[test], :verbose => true)
Guard::UI.expects(:info)
runner.expects(:system).with(
- "ruby -I\"test\" -r ./test/test_minitest.rb -r #{@default_runner} -e 'GUARD_NOTIFY=true; MiniTest::Unit.autorun' -- --verbose"
- )
- runner.run(['test/test_minitest.rb'])
- end
-
- it 'should disable notification' do
- runner = subject.new(:test_folders => %w[test], :notify => false)
- Guard::UI.expects(:info)
- runner.expects(:system).with(
- "ruby -I\"test\" -r ./test/test_minitest.rb -r #{@default_runner} -e 'GUARD_NOTIFY=false; MiniTest::Unit.autorun'"
+ "ruby -I\"test\" -r ./test/test_minitest.rb -r #{@default_runner} -e 'MiniTest::Unit.autorun' -- --verbose"
)
runner.run(['test/test_minitest.rb'])
end
@@ -144,7 +123,7 @@
runner = subject.new(:test_folders => %w[test])
Guard::UI.expects(:info)
runner.expects(:system).with(
- "ruby -I\"test\" -r ./test/test_minitest.rb -r #{@default_runner} -e 'GUARD_NOTIFY=true; MiniTest::Unit.autorun'"
+ "ruby -I\"test\" -r ./test/test_minitest.rb -r #{@default_runner} -e 'MiniTest::Unit.autorun'"
)
runner.run(['test/test_minitest.rb'])
end
@@ -153,7 +132,7 @@
runner = subject.new(:test_folders => %w[test], :rubygems => true)
Guard::UI.expects(:info)
runner.expects(:system).with(
- "ruby -I\"test\" -r rubygems -r ./test/test_minitest.rb -r #{@default_runner} -e 'GUARD_NOTIFY=true; MiniTest::Unit.autorun'"
+ "ruby -I\"test\" -r rubygems -r ./test/test_minitest.rb -r #{@default_runner} -e 'MiniTest::Unit.autorun'"
)
runner.run(['test/test_minitest.rb'])
end
@@ -170,7 +149,7 @@
runner = subject.new(:test_folders => %w[test], :bundler => true, :rubygems => false)
Guard::UI.expects(:info)
runner.expects(:system).with(
- "bundle exec ruby -I\"test\" -r bundler/setup -r ./test/test_minitest.rb -r #{@default_runner} -e 'GUARD_NOTIFY=true; MiniTest::Unit.autorun'"
+ "bundle exec ruby -I\"test\" -r bundler/setup -r ./test/test_minitest.rb -r #{@default_runner} -e 'MiniTest::Unit.autorun'"
)
runner.run(['test/test_minitest.rb'])
end
@@ -179,7 +158,7 @@
runner = subject.new(:test_folders => %w[test], :bundler => false, :rubygems => true)
Guard::UI.expects(:info)
runner.expects(:system).with(
- "ruby -I\"test\" -r rubygems -r ./test/test_minitest.rb -r #{@default_runner} -e 'GUARD_NOTIFY=true; MiniTest::Unit.autorun'"
+ "ruby -I\"test\" -r rubygems -r ./test/test_minitest.rb -r #{@default_runner} -e 'MiniTest::Unit.autorun'"
)
runner.run(['test/test_minitest.rb'], :bundler => false, :rubygems => true)
end
@@ -188,7 +167,7 @@
runner = subject.new(:test_folders => %w[test], :bundler => false, :rubygems => false)
Guard::UI.expects(:info)
runner.expects(:system).with(
- "ruby -I\"test\" -r ./test/test_minitest.rb -r #{@default_runner} -e 'GUARD_NOTIFY=true; MiniTest::Unit.autorun'"
+ "ruby -I\"test\" -r ./test/test_minitest.rb -r #{@default_runner} -e 'MiniTest::Unit.autorun'"
)
runner.run(['test/test_minitest.rb'], :bundler => false, :rubygems => false)
end
@@ -203,13 +182,13 @@
File.expects(:exist?).with('test/test_helper.rb').returns(true)
File.expects(:exist?).with('test/spec_helper.rb').returns(false)
runner.expects(:system).with(
- "testdrb -r #{File.expand_path('.')}/lib/guard/minitest/runners/default_runner.rb -e '::GUARD_NOTIFY=true' test/test_helper.rb ./test/test_minitest.rb"
+ "testdrb -r #{File.expand_path('.')}/lib/guard/minitest/runners/default_runner.rb -e '::GUARD_NOTIFY=false' test/test_helper.rb ./test/test_minitest.rb"
)
runner.run(['test/test_minitest.rb'], :drb => true)
end
- it 'should run with drb and notify=false' do
- runner = subject.new(:test_folders => %w[test], :drb => true, :notify => false)
+ it 'should run with drb and notification disable' do
+ runner = subject.new(:test_folders => %w[test], :drb => true, :notification => false)
Guard::UI.expects(:info)
File.expects(:exist?).with('test/test_helper.rb').returns(true)
File.expects(:exist?).with('test/spec_helper.rb').returns(false)
@@ -218,6 +197,17 @@
)
runner.run(['test/test_minitest.rb'], :drb => true)
end
+
+ it 'should run with drb and notification enable' do
+ runner = subject.new(:test_folders => %w[test], :drb => true, :notification => true)
+ Guard::UI.expects(:info)
+ File.expects(:exist?).with('test/test_helper.rb').returns(true)
+ File.expects(:exist?).with('test/spec_helper.rb').returns(false)
+ runner.expects(:system).with(
+ "testdrb -r #{File.expand_path('.')}/lib/guard/minitest/runners/default_runner.rb -e '::GUARD_NOTIFY=true' test/test_helper.rb ./test/test_minitest.rb"
+ )
+ runner.run(['test/test_minitest.rb'], :drb => true)
+ end
end
describe 'when using spec_helper' do
@@ -227,13 +217,13 @@
File.expects(:exist?).with('spec/test_helper.rb').returns(false)
File.expects(:exist?).with('spec/spec_helper.rb').returns(true)
runner.expects(:system).with(
- "testdrb -r #{File.expand_path('.')}/lib/guard/minitest/runners/default_runner.rb -e '::GUARD_NOTIFY=true' spec/spec_helper.rb ./test/test_minitest.rb"
+ "testdrb -r #{File.expand_path('.')}/lib/guard/minitest/runners/default_runner.rb -e '::GUARD_NOTIFY=false' spec/spec_helper.rb ./test/test_minitest.rb"
)
runner.run(['test/test_minitest.rb'], :drb => true)
end
- it 'should run with drb and notify=false' do
- runner = subject.new(:test_folders => %w[spec], :drb => true, :notify => false)
+ it 'should run with drb and notification disable' do
+ runner = subject.new(:test_folders => %w[spec], :drb => true, :notification => false)
Guard::UI.expects(:info)
File.expects(:exist?).with('spec/test_helper.rb').returns(false)
File.expects(:exist?).with('spec/spec_helper.rb').returns(true)
@@ -242,6 +232,17 @@
)
runner.run(['test/test_minitest.rb'], :drb => true)
end
+
+ it 'should run with drb and notification disable' do
+ runner = subject.new(:test_folders => %w[spec], :drb => true, :notification => true)
+ Guard::UI.expects(:info)
+ File.expects(:exist?).with('spec/test_helper.rb').returns(false)
+ File.expects(:exist?).with('spec/spec_helper.rb').returns(true)
+ runner.expects(:system).with(
+ "testdrb -r #{File.expand_path('.')}/lib/guard/minitest/runners/default_runner.rb -e '::GUARD_NOTIFY=true' spec/spec_helper.rb ./test/test_minitest.rb"
+ )
+ runner.run(['test/test_minitest.rb'], :drb => true)
+ end
end
end
end

0 comments on commit 60d71f4

Please sign in to comment.