Class: MissCleo::TestConfigurations::RspecConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/miss_cleo/test_configurations/rspec_config.rb

Constant Summary collapse

RSPEC_MAP =
"rspec_map.json"
LOGS =
[]

Class Method Summary collapse

Class Method Details

.setup_hooks(context) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/miss_cleo/test_configurations/rspec_config.rb', line 7

def self.setup_hooks(context)
  if ENV["COVERAGE"]
    MissCleo::TemplateTracker.initialize_tracker
    ActionView::Template.prepend MissCleo::TestConfigurations::ActionViewConfig if defined? ActionView::Template
    Coverage.start
    RSpec.configuration.after(:suite) do
      File.open(RSPEC_MAP, 'w') { |f| f.write JSON.dump LOGS }
    end

    RSpec.configuration.around(:example) do |example|
      MissCleo::TemplateTracker.clear_templates
      before = Coverage.peek_result
      example.call
      after = Coverage.peek_result
      templates = MissCleo::TemplateTracker.templates.uniq
      LOGS << [ example.location, {
        before: CoverageFilter.filter_and_trim(before),
        after: CoverageFilter.filter_and_trim(after),
        templates: templates
      } ]
    end
  end
end