Module: Minitest::Flog::Assertions

Included in:
Test
Defined in:
lib/minitest/flog/assertions.rb

Constant Summary collapse

DEFAULT_FLOG_OPTIONS =
{ all: true, continue: true }
DEFAULT_METHOD_OPTIONS =
{ score: 40.0, ratio: 1.0 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



9
10
11
# File 'lib/minitest/flog/assertions.rb', line 9

def dir
  @dir
end

#filteredObject

Returns the value of attribute filtered.



9
10
11
# File 'lib/minitest/flog/assertions.rb', line 9

def filtered
  @filtered
end

#thresholdObject

Returns the value of attribute threshold.



9
10
11
# File 'lib/minitest/flog/assertions.rb', line 9

def threshold
  @threshold
end

Instance Method Details

#_flog_scores_for_directory(dir) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/minitest/flog/assertions.rb', line 26

def _flog_scores_for_directory(dir)
  flog = flog_for(dir)
  scores = {}
  flog.each_by_score do |method, score, list|
    scores[method] = score
  end
  scores
end

#assert_method_score(dir, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/minitest/flog/assertions.rb', line 11

def assert_method_score(dir, options = {})
  options = DEFAULT_METHOD_OPTIONS.merge options
  self.dir = dir
  self.threshold = options[:score]

  scores = _flog_scores_for_directory(dir)
  self.filtered = scores.select { |method, score| score > options[:score] }

  score_count = scores.count.to_f.round(2)
  filtered_count = self.filtered.count.to_f.round(2)
  msg = options[:msg] || message(options[:score], options[:ratio],
                                 1.0 - (filtered_count / score_count))
  assert (filtered_count / score_count) <= (1.0 - options[:ratio]), msg
end