module Guard::Cucumber::Inspector

The inspector verifies of the changed paths are valid for Guard::Cucumber.

Public Class Methods

clean(paths, sets) click to toggle source

Clean the changed paths and return only valid Cucumber features.

@param [Array<String>] paths the changed paths @param [Array<String>] feature_sets the feature sets @return [Array<String>] the valid feature files

# File lib/guard/cucumber/inspector.rb, line 17
def clean(paths, sets)
  paths.uniq!
  paths.compact!
  paths = paths.select do |p|
    cucumber_file?(p, sets) || cucumber_folder?(p, sets)
  end
  paths = paths.delete_if { |p| included_in_other_path?(p, paths) }
  clear_cucumber_files_list
  paths
end

Private Class Methods

_path_includes(path, p, massaged) click to toggle source
# File lib/guard/cucumber/inspector.rb, line 83
def _path_includes(path, p, massaged)
  includes = path.include?(p)
  return true if includes && path.gsub(p, "").include?("/")
  massaged.include?(p)
end
clear_cucumber_files_list() click to toggle source

Clears the list of features in this project.

# File lib/guard/cucumber/inspector.rb, line 65
def clear_cucumber_files_list
  @cucumber_files = nil
end
cucumber_file?(path, feature_sets) click to toggle source

Tests if the file is valid.

@param [String] path the file @param [Array<String>] feature_sets the feature sets @return [Boolean] when the file valid

# File lib/guard/cucumber/inspector.rb, line 47
def cucumber_file?(path, feature_sets)
  cucumber_files(feature_sets).include?(path.split(":").first)
end
cucumber_files(feature_sets) click to toggle source

Scans the project and keeps a list of all feature files in the `features` directory.

@see clear_jasmine_specs @param [Array<String>] feature_sets the feature sets @return [Array<String>] the valid files

# File lib/guard/cucumber/inspector.rb, line 58
def cucumber_files(feature_sets)
  glob = "#{feature_sets.join(',')}/**/*.feature"
  @cucumber_files ||= Dir.glob(glob)
end
cucumber_folder?(path, feature_sets) click to toggle source

Tests if the file is the features folder.

@param [String] path the file @param [Array<String>] feature_sets the feature sets @return [Boolean] when the file is the feature folder

# File lib/guard/cucumber/inspector.rb, line 36
def cucumber_folder?(path, feature_sets)
  sets = feature_sets.join("|")
  path.match(/^\/?(#{ sets })/) && !path.match(/\..+$/)
end
included_in_other_path?(path, paths) click to toggle source

Checks if the given path is already contained in the paths list.

@param [Sting] path the path to test @param [Array<String>] paths the list of paths

# File lib/guard/cucumber/inspector.rb, line 75
def included_in_other_path?(path, paths)
  paths = paths.select { |p| p != path }
  massaged = path[0...(path.index(":") || path.size)]
  paths.any? { |p| _path_includes(path, p, massaged) }
end