Module: Guard::Cucumber::Inspector

Defined in:
lib/guard/cucumber/inspector.rb

Overview

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

Class Method Summary collapse

Class Method Details

._path_includes(path, p, massaged) ⇒ Object (private)



83
84
85
86
87
# 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

.clean(paths, sets) ⇒ Array<String>

Clean the changed paths and return only valid Cucumber features.

Parameters:

  • paths (Array<String>)

    the changed paths

  • feature_sets (Array<String>)

    the feature sets

Returns:

  • (Array<String>)

    the valid feature files



17
18
19
20
21
22
23
24
25
26
# 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

.clear_cucumber_files_listObject (private)

Clears the list of features in this project.



65
66
67
# File 'lib/guard/cucumber/inspector.rb', line 65

def clear_cucumber_files_list
  @cucumber_files = nil
end

.cucumber_file?(path, feature_sets) ⇒ Boolean (private)

Tests if the file is valid.

Parameters:

  • path (String)

    the file

  • feature_sets (Array<String>)

    the feature sets

Returns:

  • (Boolean)

    when the file valid



47
48
49
# 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) ⇒ Array<String> (private)

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

Parameters:

  • feature_sets (Array<String>)

    the feature sets

Returns:

  • (Array<String>)

    the valid files

See Also:

  • #clear_jasmine_specs


58
59
60
61
# 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) ⇒ Boolean (private)

Tests if the file is the features folder.

Parameters:

  • path (String)

    the file

  • feature_sets (Array<String>)

    the feature sets

Returns:

  • (Boolean)

    when the file is the feature folder



36
37
38
39
# 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) ⇒ Boolean (private)

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

Parameters:

  • path (Sting)

    the path to test

  • paths (Array<String>)

    the list of paths

Returns:

  • (Boolean)


75
76
77
78
79
# 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