Class: FlakeySpecCatcher::ChangeCapsule
- Inherits:
-
Object
- Object
- FlakeySpecCatcher::ChangeCapsule
- Defined in:
- lib/flakey_spec_catcher/change_capsule.rb
Overview
ChangeCapsule class
Summarizes a git change for a single file.
A ChangeCapsule object will represent the changes made to a block of code. It accomplishes this using ChangeContext and ChangeSummary objects.
Constant Summary collapse
- SCOPE_SPECIFIERS =
%w[it context describe scenario].freeze
- SHARED_EXAMPLES =
%w[include_examples it_behaves_like it_should_behave_like matching].freeze
Instance Attribute Summary collapse
-
#change_contexts ⇒ Object
readonly
Returns the value of attribute change_contexts.
-
#change_summary ⇒ Object
readonly
Returns the value of attribute change_summary.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
- #changed_examples ⇒ Object
- #fill_contexts ⇒ Object
-
#initialize(file_name, change_summary, change_contexts = []) ⇒ ChangeCapsule
constructor
A new instance of ChangeCapsule.
Constructor Details
#initialize(file_name, change_summary, change_contexts = []) ⇒ ChangeCapsule
Returns a new instance of ChangeCapsule.
15 16 17 18 19 20 |
# File 'lib/flakey_spec_catcher/change_capsule.rb', line 15 def initialize(file_name, change_summary, change_contexts = []) @file_name = file_name @change_summary = change_summary @change_contexts = [] handle_initial_change_contexts(change_contexts) end |
Instance Attribute Details
#change_contexts ⇒ Object (readonly)
Returns the value of attribute change_contexts.
11 12 13 |
# File 'lib/flakey_spec_catcher/change_capsule.rb', line 11 def change_contexts @change_contexts end |
#change_summary ⇒ Object (readonly)
Returns the value of attribute change_summary.
11 12 13 |
# File 'lib/flakey_spec_catcher/change_capsule.rb', line 11 def change_summary @change_summary end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
11 12 13 |
# File 'lib/flakey_spec_catcher/change_capsule.rb', line 11 def file_name @file_name end |
Instance Method Details
#changed_examples ⇒ Object
22 23 24 |
# File 'lib/flakey_spec_catcher/change_capsule.rb', line 22 def changed_examples @change_contexts.map(&:rerun_info) end |
#fill_contexts ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/flakey_spec_catcher/change_capsule.rb', line 26 def fill_contexts change_context_stack = [] ignore_scope_closure = 0 lines_in_file = File.read(@file_name).split("\n") lines_in_file.each_with_index do |line, index| # Check if line matches an rspec example or examplegroup format if line =~ spec_scope handle_change_context(line, index, change_context_stack) # Else, ignore other blocks that might pollute context stack elsif line_matches_method_or_block(line) ignore_scope_closure += 1 end fill_context(line, index, change_context_stack) # Note - some things use do-like loops and we need to be able to ignore those if line =~ pop_scope if ignore_scope_closure.positive? ignore_scope_closure -= 1 else change_context_stack.pop end end end end |