Class: FixtureKit::Analyzer::TextFormatter
- Inherits:
-
Object
- Object
- FixtureKit::Analyzer::TextFormatter
- Defined in:
- lib/fixture_kit/analyzer/text_formatter.rb
Instance Method Summary collapse
-
#initialize(limit:, lets_per_file:, min_reuse:, io: $stdout) ⇒ TextFormatter
constructor
A new instance of TextFormatter.
- #render(results) ⇒ Object
Constructor Details
#initialize(limit:, lets_per_file:, min_reuse:, io: $stdout) ⇒ TextFormatter
Returns a new instance of TextFormatter.
6 7 8 9 10 11 |
# File 'lib/fixture_kit/analyzer/text_formatter.rb', line 6 def initialize(limit:, lets_per_file:, min_reuse:, io: $stdout) @limit = limit @lets_per_file = lets_per_file @min_reuse = min_reuse @io = io end |
Instance Method Details
#render(results) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fixture_kit/analyzer/text_formatter.rb', line 13 def render(results) filtered = results.select { |r| r.max_reuse >= @min_reuse } @io.puts @io.puts "=" * 110 @io.puts "FACTORY LET REUSE (ranked by highest single-let example count)" @io.puts "=" * 110 @io.puts @io.puts "#{results.length} spec files analyzed, #{filtered.length} with max reuse >= #{@min_reuse}" filtered.first(@limit).each_with_index do |result, idx| @io.puts @io.puts "#{idx + 1}. #{result.file}" @io.puts " examples: #{result.total_examples} | factory lets: #{result.lets.length} | max reuse: #{result.max_reuse}" @io.puts " " + "-" * 95 result.lets.first(@lets_per_file).each do |l| @io.puts Kernel.format(" let(:%s) examples: %d factories: %s", l.name, l.example_count, l.factories.join(", ")) @io.puts " group: #{l.group_description}" end remaining = result.lets.length - @lets_per_file @io.puts " ... +#{remaining} more" if remaining > 0 end @io.puts end |