Class: FlakyTestTracker::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/flaky_test_tracker/tracker.rb

Overview

Test tracker.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pretend:, storage:, context:, source:, reporter:, verbose:, test_input_factory: FlakyTestTracker::TestInputFactory.new) ⇒ Tracker

Returns a new instance of Tracker.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/flaky_test_tracker/tracker.rb', line 18

def initialize(
  pretend:, storage:, context:, source:, reporter:, verbose:,
  test_input_factory: FlakyTestTracker::TestInputFactory.new
)
  @pretend = pretend
  @storage = storage
  @context = context
  @source = source
  @reporter = reporter
  @verbose = verbose
  @test_input_factory = test_input_factory
  @tests = nil
  @test_inputs_attributes = []
end

Instance Attribute Details

#contextObject

Returns the current value of context.

Returns:

  • (Object)

    the current value of context



15
16
17
# File 'lib/flaky_test_tracker/tracker.rb', line 15

def context
  @context
end

#pretendBoolean

Run but do not make any changes on the #storage

Returns:

  • (Boolean)

    the current value of pretend



15
16
17
# File 'lib/flaky_test_tracker/tracker.rb', line 15

def pretend
  @pretend
end

#reporter#tracked_tests #resolved_tests

Returns the current value of reporter.

Returns:

  • (#tracked_tests #resolved_tests)

    the current value of reporter



15
16
17
# File 'lib/flaky_test_tracker/tracker.rb', line 15

def reporter
  @reporter
end

#source#file_source_location_uri #source_uri

Returns the current value of source.

Returns:

  • (#file_source_location_uri #source_uri)

    the current value of source



15
16
17
# File 'lib/flaky_test_tracker/tracker.rb', line 15

def source
  @source
end

#storage#all #create #update #delete

Returns the current value of storage.

Returns:

  • (#all #create #update #delete)

    the current value of storage



15
16
17
# File 'lib/flaky_test_tracker/tracker.rb', line 15

def storage
  @storage
end

#test_input_factory#build

Returns the current value of test_input_factory.

Returns:

  • (#build)

    the current value of test_input_factory



15
16
17
# File 'lib/flaky_test_tracker/tracker.rb', line 15

def test_input_factory
  @test_input_factory
end

#test_inputs_attributesArray<Hash>

Returns the current value of test_inputs_attributes.

Returns:

  • (Array<Hash>)

    the current value of test_inputs_attributes



15
16
17
# File 'lib/flaky_test_tracker/tracker.rb', line 15

def test_inputs_attributes
  @test_inputs_attributes
end

#verboseBoolean

Returns the current value of verbose.

Returns:

  • (Boolean)

    the current value of verbose



15
16
17
# File 'lib/flaky_test_tracker/tracker.rb', line 15

def verbose
  @verbose
end

Instance Method Details

#add(reference:, description:, exception:, file_path:, line_number:, finished_at: Time.now) ⇒ Object

Add test attributes to the internal queue.

Parameters:

  • reference (String)

    Test unique reference.

  • description (String)

    Test description.

  • exception (String)

    Test exception message.

  • file_path (String)

    Test source code file path.

  • line_number (Integer)

    Test source code line number.

  • finished_at (Time) (defaults to: Time.now)

    The moment the test execution finished.

See Also:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/flaky_test_tracker/tracker.rb', line 41

def add(
  reference:,
  description:,
  exception:,
  file_path:,
  line_number:,
  finished_at: Time.now
)
  @test_inputs_attributes << {
    reference: reference,
    description: description,
    exception: exception,
    file_path: file_path,
    line_number: line_number,
    finished_at: finished_at
  }
end

#clearObject

Reset the internal queue.



81
82
83
84
# File 'lib/flaky_test_tracker/tracker.rb', line 81

def clear
  @tests = nil
  @test_inputs_attributes = []
end

#testsArray<Test>

All persisted FlakyTestTracker::Test on the #storage.

Returns:



76
77
78
# File 'lib/flaky_test_tracker/tracker.rb', line 76

def tests
  @tests ||= @storage.all
end

#trackArray<Test>

For each test attributes in the internal queue.

Returns:



67
68
69
70
71
72
# File 'lib/flaky_test_tracker/tracker.rb', line 67

def track
  tracked_tests = test_inputs.map { |test_input| track_test(test_input) }
  reporter.tracked_tests(source: source, context: context, tests: tracked_tests)
  puts "\n[FlakyTestTracker][Tracker] #{tracked_tests.count} test(s) tracked" if verbose
  tracked_tests
end