Module: CucumberSlice::ListCore

Included in:
ListsFeatures
Defined in:
lib/cucumber_slice/lists_features.rb

Instance Method Summary collapse

Instance Method Details

#any_dependencies_in_changeset?(dependencies, changeset) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/cucumber_slice/lists_features.rb', line 39

def any_dependencies_in_changeset?(dependencies, changeset)
  (dependencies & changeset).any?
end

#changed_files(git) ⇒ Object



83
84
85
# File 'lib/cucumber_slice/lists_features.rb', line 83

def changed_files(git)
  git.status.changed.map(&:first)
end

#dependencies_declared_in(feature_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cucumber_slice/lists_features.rb', line 27

def dependencies_declared_in(feature_path)
  dependencies = nil
  File.open(feature_path) do |feature|
    dependencies = feature.each_line.map do |line|
      if match = line.match(/^#=\s*?depends_on (.*)$/)
        match[1]
      end
    end.compact
  end
  dependencies
end

#diff_files(git, since) ⇒ Object



79
80
81
# File 'lib/cucumber_slice/lists_features.rb', line 79

def diff_files(git, since)
  git.diff(since, "HEAD").map(&:path)
end

#expand_globs(patterns) ⇒ Object



57
58
59
60
61
# File 'lib/cucumber_slice/lists_features.rb', line 57

def expand_globs(patterns)
  expand_paths(patterns.map do |pattern|
    Dir.glob(File.join(git_repo_path, pattern))
  end.flatten).compact.uniq
end

#expand_paths(paths) ⇒ Object



63
64
65
# File 'lib/cucumber_slice/lists_features.rb', line 63

def expand_paths(paths)
  paths.map {|path| File.expand_path(path) }
end

#files_changed_since(rev) ⇒ Object



72
73
74
75
76
77
# File 'lib/cucumber_slice/lists_features.rb', line 72

def files_changed_since(rev)
  git = Git.open(git_repo_path)
  changed_files = diff_files(git, rev) + changed_files(git)

  expand_paths(changed_files.map {|p| File.join(git_repo_path, p)}).uniq
end

#find_up(dir, root_checked = false) ⇒ Object

file stuff



44
45
46
47
# File 'lib/cucumber_slice/lists_features.rb', line 44

def find_up(dir, root_checked = false)
  raise "No git repository found at or above `#{Dir.pwd}`!" if root_checked
  is_dir?(File.join(dir, ".git")) ?  dir : find_up(File.join(dir,'..'), is_root?(dir))
end

#format_feature_list(feature_list) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/cucumber_slice/lists_features.rb', line 16

def format_feature_list(feature_list)
  if feature_list.empty?
    #point to an empty file to insist cucumber not run anything.
    #  cucumber's default behavior is to run everything when it's passed nothing.
    #  Super hacky stuff.
    File.expand_path(File.join(File.dirname(__FILE__), "empty_file"))
  else
    feature_list.join(" ")
  end
end

#git_repo_pathObject

git stuff



68
69
70
# File 'lib/cucumber_slice/lists_features.rb', line 68

def git_repo_path
  File.expand_path(find_up(Dir.pwd))
end

#is_dir?(path) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/cucumber_slice/lists_features.rb', line 49

def is_dir?(path)
  File.exist?(path) && File.ftype(path) == "directory"
end

#is_root?(path) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/cucumber_slice/lists_features.rb', line 53

def is_root?(path)
  File.expand_path(path) == "/"
end

#list_features_under(path) ⇒ Object

feature stuff



6
7
8
9
10
11
12
13
14
# File 'lib/cucumber_slice/lists_features.rb', line 6

def list_features_under(path)
  glob = if path.include?('*')
    path
  else
    File.join(path, "**/*.feature")
  end

  Dir.glob(File.join(git_repo_path, glob))
end