forked from guard/guard-minitest
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'japgolly/master'
Conflicts: Gemfile lib/guard/minitest/inspector.rb lib/guard/minitest/runner.rb
- Loading branch information
Showing
5 changed files
with
90 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters