Class: FlakeySpecCatcher::ChangeContext
- Inherits:
-
Object
- Object
- FlakeySpecCatcher::ChangeContext
- Defined in:
- lib/flakey_spec_catcher/change_context.rb
Overview
ChangeContext class
Identifies the conditions in which a code change occurs.
At a high level, a ChangeContext captures (A) the line number, and (B) the block of code in which a change exists. This identifies both the code change’s context and its parent context.
FSC uses parent contexts to eliminate re-running tests too many times. For example, if changes are detected in both a ‘describe’ block and a child test case inside of that ‘describe’ block, FSC will re-run the contents of the ‘describe’ block only.
Instance Attribute Summary collapse
-
#ancestor_contexts ⇒ Object
readonly
Returns the value of attribute ancestor_contexts.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #ancestor_present_in_reruns(reruns) ⇒ Object
- #example_group? ⇒ Boolean
-
#identify_tags_and_values ⇒ Object
Get tag strings which optionally may continue tags with their values and return a hash.
-
#initialize(description:, line_number:, file_name:, ancestor_contexts: [], tags: {}) ⇒ ChangeContext
constructor
A new instance of ChangeContext.
- #rerun_info ⇒ Object
- #update_descriptions ⇒ Object
Constructor Details
#initialize(description:, line_number:, file_name:, ancestor_contexts: [], tags: {}) ⇒ ChangeContext
Returns a new instance of ChangeContext.
20 21 22 23 24 25 26 27 28 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 20 def initialize(description:, line_number:, file_name:, ancestor_contexts: [], tags: {}) @description = description @line_number = line_number @file_name = file_name @ancestor_contexts = ancestor_contexts @tags = update_descriptions end |
Instance Attribute Details
#ancestor_contexts ⇒ Object (readonly)
Returns the value of attribute ancestor_contexts.
18 19 20 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 18 def ancestor_contexts @ancestor_contexts end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
17 18 19 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 17 def description @description end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
18 19 20 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 18 def file_name @file_name end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
17 18 19 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 17 def line_number @line_number end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
18 19 20 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 18 def @tags end |
Instance Method Details
#==(other) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 67 def ==(other) @description == other.description && @line_number == other.line_number && @file_name == other.file_name && @ancestor_contexts == other.ancestor_contexts end |
#ancestor_present_in_reruns(reruns) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 82 def ancestor_present_in_reruns(reruns) reruns.each do |rerun| return true if @ancestor_contexts.map(&:rerun_info).include? rerun end false end |
#example_group? ⇒ Boolean
37 38 39 40 41 42 43 44 45 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 37 def example_group? # If the description starts with 'it' or 'scenario' then the test # can provide assertions/expectations and is not an example group if @description =~ /^\s*(it|scenario)\s+/ false else true end end |
#identify_tags_and_values ⇒ Object
Get tag strings which optionally may continue tags with their values
and return a hash
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 49 def = {} tag_strings = identify_tag_strings return if tag_strings.nil? || tag_strings.empty? # Since tags can have a value represented as strings or symbols # we'll only remove the hash rockets and not colons # Example: ":tag => 'special'" => tags_with_values[:tag] = 'special' # Example: ":tag => :special" => tags_with_values[:tag] = :special tag_strings.each do |str| tag_and_value = str.sub(/=>/, ' ').split(' ') [tag_and_value[0]] = tag_and_value[1] end @tags = end |
#rerun_info ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 74 def rerun_info if @line_number.nil? @file_name else "#{@file_name}:#{@line_number}" end end |
#update_descriptions ⇒ Object
30 31 32 33 34 35 |
# File 'lib/flakey_spec_catcher/change_context.rb', line 30 def update_descriptions return unless @description.nil? || @description.empty? @description = @file_name @line_number = nil end |