Skip to content

Commit

Permalink
Merge remote-tracking branch 'japgolly/master'
Browse files Browse the repository at this point in the history
Conflicts:
	Gemfile
	lib/guard/minitest/inspector.rb
	lib/guard/minitest/runner.rb
  • Loading branch information
yannlugrin committed Feb 21, 2012
2 parents f85d7ed + fdc54c6 commit a9e5b36
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 42 deletions.
8 changes: 4 additions & 4 deletions Gemfile
Expand Up @@ -6,12 +6,12 @@ gem 'rake'

require 'rbconfig'
if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent', '>= 0.3.2'
gem 'growl', '~> 1.0.3'
gem 'rb-fsevent', '>= 0.3.2', :require => false
gem 'growl', '~> 1.0.3', :require => false
end
if RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.5.1'
gem 'libnotify', '~> 0.1.3'
gem 'rb-inotify', '>= 0.5.1', :require => false
gem 'libnotify', '~> 0.7.1', :require => false
end
if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
gem 'win32console', :require => false
Expand Down
6 changes: 6 additions & 0 deletions README.rdoc
Expand Up @@ -63,6 +63,12 @@ You can set minitest verbose mode with:
...
end

You can change the default location and pattern of minitest files:

guard 'minitest', test_folders: 'test/unit', test_file_patterns: '*_test.rb' do
...
end

You can disable desktop notification with:

guard 'minitest', :notify => false do
Expand Down
5 changes: 3 additions & 2 deletions lib/guard/minitest.rb
Expand Up @@ -12,6 +12,7 @@ def initialize(watchers = [], options = {})
super

@runner ||= Runner.new(options)
@inspector= Inspector.new(@runner.test_folders, @runner.test_file_patterns)
end

def start
Expand All @@ -27,13 +28,13 @@ def reload
end

def run_all
paths = Inspector.clean(['test', 'spec'])
paths = @inspector.clean_all
return @runner.run(paths, :message => 'Running all tests') unless paths.empty?
true
end

def run_on_change(paths = [])
paths = Inspector.clean(paths)
paths = @inspector.clean(paths)
return @runner.run(paths) unless paths.empty?
true
end
Expand Down
86 changes: 55 additions & 31 deletions lib/guard/minitest/inspector.rb
@@ -1,46 +1,70 @@
# encoding: utf-8
module Guard
class Minitest
module Inspector
class << self

def clean(paths)
paths.uniq!
paths.compact!
paths = paths.select { |p| test_file?(p) || test_folder?(p) }

paths.dup.each do |path|
if File.directory?(path)
paths.delete(path)
paths += Dir.glob("#{path}/**/test_*.rb") + Dir.glob("#{path}/**/*_test.rb") + Dir.glob("#{path}/**/*_spec.rb")
end
end
class Inspector

paths.uniq!
paths.compact!
clear_test_files_list
paths
end
attr_reader :test_folders, :test_file_patterns

private
def initialize(test_folders, test_file_patterns)
@test_folders= test_folders.uniq.compact.freeze
@test_file_patterns= test_file_patterns.uniq.compact.freeze
end

def test_folder?(path)
path.match(/^\/?(test|spec)/) && !path.match(/\..+$/) && File.directory?(path)
end
def clean_all
clean self.test_folders
end

def test_file?(path)
test_files.include?(path)
end
def clean(paths)
paths= paths.uniq.compact unless paths == @test_folders
paths = paths.select { |p| test_file?(p) || test_folder?(p) }

def test_files
@test_files ||= Dir.glob('test/**/test_*.rb') + Dir.glob('test/**/*_test.rb') + Dir.glob('{test,spec}/**/*_spec.rb')
paths.dup.each do |path|
if File.directory?(path)
paths.delete(path)
paths += test_files_for_pathes([path])
end
end

def clear_test_files_list
@test_files = nil
end
paths.uniq!
paths.compact!
clear_test_files_list
paths
end

private
def test_folder_regex
@test_folder_regex ||= (
folders= self.test_folders.map {|f| Regexp.quote f}.join '|'
Regexp.new("^/?(?:#{folders})(?:/|$)")
)
end

def test_folder?(path)
path.match(test_folder_regex) && !path.match(/\..+$/) && File.directory?(path)
end

def test_file?(path)
test_files.include?(path)
end

def test_files
@test_files ||= test_files_for_pathes(self.test_folders)
end

def join_for_glob(fragments)
"{#{fragments.join ','}}"
end

def test_files_for_pathes(pathes)
pathes= join_for_glob(pathes)
files= join_for_glob(self.test_file_patterns)
Dir.glob(pathes + '/**/' + files)
end

def clear_test_files_list
@test_files = nil
end

end
end
end
27 changes: 22 additions & 5 deletions lib/guard/minitest/runner.rb
Expand Up @@ -17,8 +17,12 @@ def initialize(options = {})
:notify => true,
:bundler => File.exist?("#{Dir.pwd}/Gemfile"),
:rubygems => false,
:drb => false
:drb => false,
:test_folders => %w[test spec],
:test_file_patterns => %w[*_test.rb test_*.rb *_spec.rb],
}.merge(options)
[:test_folders,:test_file_patterns].each {|k| (@options[k]= [@options[k]].flatten.uniq.compact).freeze}
options= options.freeze
end

def run(paths, options = {})
Expand Down Expand Up @@ -51,6 +55,14 @@ def drb?
@options[:drb]
end

def test_folders
@options[:test_folders]
end

def test_file_patterns
@options[:test_file_patterns]
end

private

def minitest_command(paths)
Expand All @@ -64,13 +76,16 @@ def minitest_command(paths)
else
cmd_parts << '-e \'::GUARD_NOTIFY=false\''
end
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')
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
else
cmd_parts << 'ruby -Itest -Ispec'
cmd_parts << 'ruby'
cmd_parts.concat test_folders.map{|f| %[-I"#{f}"]}
cmd_parts << '-r rubygems' if rubygems?
cmd_parts << '-r bundler/setup' if bundler?
paths.each do |path|
Expand All @@ -86,7 +101,9 @@ def minitest_command(paths)
cmd_parts << "--seed #{seed}" unless seed.nil?
cmd_parts << '--verbose' if verbose?
end
cmd_parts.join(' ')
cmd= cmd_parts.join(' ')
puts "Running: #{cmd}\n\n" if verbose?
cmd
end

end
Expand Down

0 comments on commit a9e5b36

Please sign in to comment.