Module: Guard::XctoolHelper
- Included in:
- XctoolTest
- Defined in:
- lib/guard/xctool_helper.rb
Constant Summary collapse
- TEST_FILE_REGEXP =
/(Test|Spec)\.(m|mm)$/
Instance Method Summary collapse
-
#find_test_target ⇒ Object
Find first project and first Test target from current folder.
-
#test_classes_with_paths(paths, test_path = []) ⇒ Object
Find test class from input paths.
-
#test_file(file, test_paths = []) ⇒ Object
Give a file and a test path, find the test for the given file in the test path.
Instance Method Details
#find_test_target ⇒ Object
Find first project and first Test target from current folder
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/guard/xctool_helper.rb', line 46 def find_test_target project_name = Dir["*.xcodeproj"].first if project_name project = Xcodeproj::Project.new(project_name) # find first targets with name ends with Spec or Target return project.targets.collect(&:name).find {|f| f =~ /(Spec|Test)s?$/} end nil end |
#test_classes_with_paths(paths, test_path = []) ⇒ Object
Find test class from input paths.
-
if the path is end with Test.m/Test.mm/Spec.m/Spec.mm, then it is a test class, return the class name of it
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/guard/xctool_helper.rb', line 14 def test_classes_with_paths(paths, test_path=[]) test_classes = paths.select{|path| path =~ TEST_FILE_REGEXP } # get only Test/Spec .collect {|path| classname_with_file(path) } non_test_classes = paths.select{|path| path !=~ TEST_FILE_REGEXP } .collect {|path| test_file(path, test_path) } .compact .collect {|path| classname_with_file(path) } test_classes = non_test_classes + test_classes test_classes.uniq end |
#test_file(file, test_paths = []) ⇒ Object
Give a file and a test path, find the test for the given file in the test path. return nil if the test do not exists.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/guard/xctool_helper.rb', line 31 def test_file(file, test_paths=[]) test_paths = [] unless test_paths test_paths = [test_paths] unless test_paths.is_a?(Array) class_name = classname_with_file(file) # for each test path, check if we can find corresponding test file test_paths.each do |path| files = Dir.glob("#{path}/**/#{class_name}*.*").select {|file| file =~ /#{class_name}(Test|Spec)\.(m|mm)$/ } first_file = files.first return first_file if first_file end return nil end |