Class: FlakeySpecCatcher::CapsuleManager

Inherits:
Object
  • Object
show all
Defined in:
lib/flakey_spec_catcher/capsule_manager.rb

Overview

CapsuleManager class

Contains a file by file summary of all git changes.

A CapsuleManager object contains all ChangeCapsule objects. It delivers summaries of all changes and runs methods on the contained ChangeCapsule objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCapsuleManager

Returns a new instance of CapsuleManager.



14
15
16
# File 'lib/flakey_spec_catcher/capsule_manager.rb', line 14

def initialize
  @change_capsules = []
end

Instance Attribute Details

#change_capsulesObject (readonly)

Returns the value of attribute change_capsules.



12
13
14
# File 'lib/flakey_spec_catcher/capsule_manager.rb', line 12

def change_capsules
  @change_capsules
end

Instance Method Details

#add_capsule(capsule) ⇒ Object



18
19
20
# File 'lib/flakey_spec_catcher/capsule_manager.rb', line 18

def add_capsule(capsule)
  @change_capsules.push(capsule)
end

#changed_examplesObject



22
23
24
# File 'lib/flakey_spec_catcher/capsule_manager.rb', line 22

def changed_examples
  @change_capsules.map(&:changed_examples).flatten.uniq
end

#changed_filesObject



26
27
28
# File 'lib/flakey_spec_catcher/capsule_manager.rb', line 26

def changed_files
  @change_capsules.map(&:file_name).uniq
end

#condense_rerunsObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/flakey_spec_catcher/capsule_manager.rb', line 34

def condense_reruns
  # Don't re-run if the parent context of a change will be run
  reruns = []
  all_contexts = sorted_change_contexts
  all_contexts.each do |context|
    next if reruns.include?(context.file_name) || context.ancestor_present_in_reruns(reruns)

    reruns.push(context.rerun_info) unless reruns.include?(context.rerun_info)
  end
  reruns
end

#find_reruns_by_tags(user_excluded_tags) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/flakey_spec_catcher/capsule_manager.rb', line 54

def find_reruns_by_tags(user_excluded_tags)
  dropped_tests = []
  sorted_change_contexts.each do |context|
    context.tags.keys.each do |tag|
      next unless user_excluded_tags.key?(tag) &&
                  tag_values_equal?(user_excluded_tags[tag], context.tags[tag])

      dropped_tests << context.rerun_info
    end
  end
  dropped_tests
end

#sorted_change_contextsObject



30
31
32
# File 'lib/flakey_spec_catcher/capsule_manager.rb', line 30

def sorted_change_contexts
  @change_capsules.map(&:change_contexts).flatten.sort_by { |c| c.line_number.to_i }
end

#tag_values_equal?(user_excluded_tag_value, rspec_tag_value) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/flakey_spec_catcher/capsule_manager.rb', line 46

def tag_values_equal?(user_excluded_tag_value, rspec_tag_value)
  return true if user_excluded_tag_value.nil? && rspec_tag_value.nil?

  return false if user_excluded_tag_value.nil? || rspec_tag_value.nil?

  (user_excluded_tag_value.tr('\'\"', '') == rspec_tag_value.tr('\'\" ', ''))
end