Class: JiraMetrics::Testing::MockCycleTimeConfig

Inherits:
CycleTimeConfig show all
Defined in:
lib/jirametrics/testing/mock_cycle_time_config.rb

Overview

Stubs are matched by the issue's KEY, not by object identity, so every issue in a test needs its own key. Building two issues with the same key and stubbing both raises.

board.cycletime = MockCycleTimeConfig.new
.stub(issue1, started: '2021-01-02')
.stub(issue2, started: '2021-01-02', stopped: '2021-10-04')

An issue with no stub at all reads as never started, which is a legitimate state and so cannot be distinguished from one you forgot.

Instance Attribute Summary

Attributes inherited from CycleTimeConfig

#file_system, #label, #settings

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CycleTimeConfig

#age, #collapse_zero_length_start, #cycletime, #done?, #flush_cache, #in_progress?, #possible_statuses, #resolve_change, #start_at, #started_stopped_dates, #started_stopped_times, #stop_at, #warn_on_cache_mismatch

Methods included from SelfOrIssueDispatcher

#method_missing, #respond_to_missing?

Constructor Details

#initializeMockCycleTimeConfig

Returns a new instance of MockCycleTimeConfig.



15
16
17
18
# File 'lib/jirametrics/testing/mock_cycle_time_config.rb', line 15

def initialize
  super(possible_statuses: nil, label: nil, block: nil, settings: self.class.default_settings)
  @stubs = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SelfOrIssueDispatcher

Class Method Details

.default_settingsObject

The same file ProjectConfig reads, resolved from this file's own location so that it works from wherever the caller happens to be rather than only from a checkout of this repo.



22
23
24
25
26
27
28
29
# File 'lib/jirametrics/testing/mock_cycle_time_config.rb', line 22

def self.default_settings
  settings_file = File.expand_path '../settings.json', __dir__
  JSON.parse(File.read(settings_file, encoding: 'UTF-8')).tap do |settings|
    # A cached cycle time would outlive the stub that produced it, so a second stub for the same
    # issue would appear to have no effect.
    settings['cache_cycletime_calculations'] = false
  end
end

Instance Method Details

#started_stopped_changes(issue) ⇒ Object



39
40
41
42
43
44
# File 'lib/jirametrics/testing/mock_cycle_time_config.rb', line 39

def started_stopped_changes(issue)
  value = @stubs.find { |issue_key, _start, _stop| issue_key == issue.key }
  return [nil, nil] unless value

  [to_change(value[1]), to_change(value[2])]
end

#stub(issue, started: nil, stopped: nil) ⇒ Object

Returns self so that calls cascade.



32
33
34
35
36
37
# File 'lib/jirametrics/testing/mock_cycle_time_config.rb', line 32

def stub issue, started: nil, stopped: nil
  key = issue.is_a?(Issue) ? issue.key : issue
  assert_key_unused key
  @stubs << [key, normalize_time(started), normalize_time(stopped)]
  self
end