Class: DeltaTest::RelatedSpecList

Inherits:
Object
  • Object
show all
Defined in:
lib/delta_test/related_spec_list.rb

Instance Method Summary collapse

Constructor Details

#initializeRelatedSpecList

Returns a new instance of RelatedSpecList.



15
16
17
# File 'lib/delta_test/related_spec_list.rb', line 15

def initialize
  @git = Git.new(DeltaTest.config.base_path)
end

Instance Method Details

#customsSet|Nil

Custom spec files

Returns:

  • (Set|Nil)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/delta_test/related_spec_list.rb', line 89

def customs
  return nil unless @changed_files

  return @customs if @customs
  @customs = Set.new

  DeltaTest.config.custom_mappings.each do |spec_file, patterns|
    if Utils.files_grep(@changed_files, patterns).any?
      @customs << spec_file
    end
  end

  @customs
end

#dependentsSet|Nil

Dependent spec files

Returns:

  • (Set|Nil)


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/delta_test/related_spec_list.rb', line 68

def dependents
  return nil unless @changed_files && @table

  return @dependents if @dependents
  @dependents = Set.new

  @table.each do |spec_file, dependencies|
    dependent = @changed_files.include?(spec_file) \
      || (dependencies.map(&:to_s) & @changed_files).any?

    @dependents << spec_file if dependent
  end

  @dependents
end

#fullSet|Nil

Full spec files

Returns:

  • (Set|Nil)


109
110
111
112
113
# File 'lib/delta_test/related_spec_list.rb', line 109

def full
  return nil unless @table

  @full ||= Set.new(@table.keys)
end

#full_tests?Boolean

Return if full tests are related

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/delta_test/related_spec_list.rb', line 49

def full_tests?
  return false unless @changed_files
  return @full_tests if defined?(@full_tests)

  @full_tests = false
  @full_tests ||= DeltaTest.config.full_test_branches.include?(@git.current_branch)
  @full_tests ||= DeltaTest.config.full_test_patterns.any? && Utils.files_grep(
    @changed_files,
    DeltaTest.config.full_test_patterns
  ).any?

  @full_tests
end

#load_table!(table_file_path) ⇒ Object

Load table from the file



22
23
24
25
26
27
28
# File 'lib/delta_test/related_spec_list.rb', line 22

def load_table!(table_file_path)
  unless File.exist?(table_file_path)
    raise TableNotFoundError.new(table_file_path)
  end

  @table = DependenciesTable.load(table_file_path)
end

Calculate related spec files

Returns:

  • (Set<String>)


120
121
122
123
124
125
126
# File 'lib/delta_test/related_spec_list.rb', line 120

def related_spec_files
  if full_tests?
    full
  else
    dependents | customs
  end
end

#retrive_changed_files!(commit) ⇒ Object

Retrive changed files in git diff



36
37
38
39
40
41
42
# File 'lib/delta_test/related_spec_list.rb', line 36

def retrive_changed_files!(commit)
  unless @git.git_repo?
    raise NotInGitRepositoryError
  end

  @changed_files = @git.changed_files(commit)
end