Class: TestMap::Plugins::RSpec::CacheFormatter
- Inherits:
-
RSpec::Core::Formatters::ProgressFormatter
- Object
- RSpec::Core::Formatters::ProgressFormatter
- TestMap::Plugins::RSpec::CacheFormatter
- Defined in:
- lib/test_map/plugins/rspec/cache_formatter.rb
Overview
Formatter that shows C for cached tests instead of ‘*` (pending). Extends ProgressFormatter so it can serve as the default formatter. Adjusts the summary to show cached count and filters cached tests from the pending output.
Constant Summary collapse
- CACHED_MESSAGE =
'test-map: cached'
Instance Method Summary collapse
- #dump_pending(notification) ⇒ Object
- #dump_summary(summary) ⇒ Object
- #example_pending(notification) ⇒ Object
-
#initialize(output) ⇒ CacheFormatter
constructor
A new instance of CacheFormatter.
Constructor Details
#initialize(output) ⇒ CacheFormatter
Returns a new instance of CacheFormatter.
19 20 21 22 |
# File 'lib/test_map/plugins/rspec/cache_formatter.rb', line 19 def initialize(output) super @cached_count = 0 end |
Instance Method Details
#dump_pending(notification) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/test_map/plugins/rspec/cache_formatter.rb', line 33 def dump_pending(notification) examples = notification.pending_examples cached = examples.select { |ex| cached?(ex) } return if examples.size == cached.size cached.each { |ex| examples.delete(ex) } super cached.each { |ex| examples.push(ex) } end |
#dump_summary(summary) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/test_map/plugins/rspec/cache_formatter.rb', line 43 def dump_summary(summary) if @cached_count.positive? cached_count = @cached_count original_totals_line = summary.method(:totals_line) summary.define_singleton_method(:totals_line) do "#{original_totals_line.call}, #{cached_count} cached" end end super end |
#example_pending(notification) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/test_map/plugins/rspec/cache_formatter.rb', line 24 def example_pending(notification) if cached?(notification.example) @cached_count += 1 output.print ::RSpec::Core::Formatters::ConsoleCodes.wrap('c', :cyan) else super end end |