Skip to content

Commit

Permalink
add optional bundle exec
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Nov 16, 2010
1 parent f2068f2 commit 20ba6fc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Improvements over ZenTest
- `-r` use given config file
- `-p` use parallel_tests to run tests (Test::Unit only)
- `-s` use any style you want -> `alias autospec2="autotest --style rspec2"`
- `-b` use bundle exec to run tests
- simplified test setup
- simplified packaging
- less globals
Expand Down Expand Up @@ -38,6 +39,7 @@ Usage
-q, --quiet Be quiet.
-r, --rc CONFIG Path to config file. (Defaults to ~/.autotest or current_dir/.autotest)
-s, --style STYLE Which style to use, e.g. rspec, rspec2
-b, --bundle-exec Use bundle exec to run tests
-h, --help Show this.

Windows needs [diff.exe](http://gnuwin32.sourceforge.net/packages.html)
Expand Down
5 changes: 4 additions & 1 deletion bin/autotest
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ BANNER
opts.on("-s", "--style STYLE", "Which style to use, e.g. rspec, rspec2") do |style|
options[:style] = style
end
opts.on("-b", "--bundle-exec", "Use bundle exec to run tests") do
options[:bundle_exec] = true
end
opts.on("-h", "--help","Show this.") { puts opts;exit }
end.parse!

Expand Down Expand Up @@ -61,4 +64,4 @@ unless style.empty?
puts "style: #{style.map {|s| s.capitalize}.join}"
target = Autotest.const_get(style.map {|s| s.capitalize}.join)
end
target.run
target.run
8 changes: 6 additions & 2 deletions lib/autotest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,12 @@ def known_files
def make_test_cmd files_to_test
cmds = []
full, partial = reorder(files_to_test).partition { |k,v| v.empty? }
base_cmd = "#{ruby} -I#{libs} -rubygems"
base_cmd = "#{bundle_exec}#{ruby} -I#{libs} -rubygems"

unless full.empty? then
classes = full.map {|k,v| k}.flatten.uniq
if options[:parallel] and classes.size > 1
cmds << "parallel_test #{escape_filenames(classes).join(' ')}"
cmds << "#{bundle_exec}parallel_test #{escape_filenames(classes).join(' ')}"
else
classes.unshift testlib
cmds << "#{base_cmd} -e \"[#{escape_filenames(classes).join(', ')}].each { |f| require f }\" | #{unit_diff}"
Expand All @@ -469,6 +469,10 @@ def make_test_cmd files_to_test
cmds.join("#{SEP} ")
end

def bundle_exec
options[:bundle_exec] ? 'bundle exec ' : ''
end

def escape_filenames(classes)
classes.map{|klass| "'#{klass}'"}
end
Expand Down
21 changes: 21 additions & 0 deletions test/test_autotest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def setup
@a = klassname.split(/::/).inject(Object) { |k,n| k.const_get(n) }.new
@a.output = StringIO.new
@a.last_mtime = Time.at(2)
@a.options[:bundle_exec] = nil
@a.options[:parallel] = nil

@files = {}
Expand Down Expand Up @@ -380,6 +381,26 @@ def test_make_test_cmd_basics
assert_equal expected, result
end

def test_make_test_cmd_uses_bundle_exec_when_given
@a.options[:bundle_exec] = true
f = {
@test => []
}
result = @a.make_test_cmd f
assert_match /^bundle exec \//,result
end

def test_make_test_cmd_uses_bundle_exec_with_parallel_test
@a.options[:bundle_exec] = true
@a.options[:parallel] = true
f = {
'test/a.rb' => [],
'test/b.rb' => []
}
result = @a.make_test_cmd f
assert_match /^bundle exec parallel_test/, result
end

def test_make_test_cmd_uses_parallel_with_multiple_files
@a.options[:parallel] = true
f = {
Expand Down

0 comments on commit 20ba6fc

Please sign in to comment.