Sha256: 4dcff05a3c60f76c7599891047075bec37708a54c52c73b3088590636a1f67a2
Contents?: true
Size: 1.83 KB
Versions: 3
Compression:
Stored size: 1.83 KB
Contents
module XCPretty class HTML include XCPretty::FormatMethods FILEPATH = 'build/reports/tests.html' TEMPLATE = File.expand_path('../../../../assets/report.html.erb', __FILE__) def load_dependencies unless @@loaded ||= false require 'fileutils' require 'pathname' require 'erb' @@loaded = true end end def initialize(options) load_dependencies @test_suites = {} @filepath = options[:path] || FILEPATH @parser = Parser.new(self) @test_count = 0 @fail_count = 0 end def handle(line) @parser.parse(line) end def format_failing_test(suite, test_case, reason, file) add_test(suite, {:name => test_case, :failing => true, :reason => reason, :file => file, :snippet => formatted_snippet(file)}) end def format_passing_test(suite, test_case, time) add_test(suite, {:name => test_case, :time => time}) end def finish FileUtils.mkdir_p(File.dirname(@filepath)) write_report end private def formatted_snippet(filepath) snippet = Snippet.from_filepath(filepath) Syntax.highlight(snippet, "-f html -O style=colorful -O noclasses") end def add_test(suite_name, data) @test_count += 1 @test_suites[suite_name] ||= {:tests => []} @test_suites[suite_name][:tests] << data if data[:failing] @test_suites[suite_name][:failing] = true @fail_count += 1 end end def write_report File.open(@filepath, 'w') do |f| # WAT: get rid of these locals. BTW Cucumber fails if you remove them test_suites = @test_suites fail_count = @fail_count test_count = @test_count erb = ERB.new(File.open(TEMPLATE, 'r').read) f.write erb.result(binding) end end end end
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
learn-xcpretty-0.1.12 | lib/xcpretty/reporters/html.rb |
learn-xcpretty-0.1.11 | lib/xcpretty/reporters/html.rb |
xcpretty-0.1.6 | lib/xcpretty/reporters/html.rb |