Sha256: d9d1f5fa039d85f7ae5790840b859728bf21bea4999b040d2590a72df041dc8c
Contents?: true
Size: 1.92 KB
Versions: 4
Compression:
Stored size: 1.92 KB
Contents
require 'fitting/cover/response' require 'haml' require 'json' module Fitting class Cover def initialize(all_responses, coverage) @all_responses = all_responses @coverage = coverage @list = {} end def to_hash return @list unless @list == {} @all_responses.each_with_object({}) do |response, res| next res unless response.documented? if res.key?(response.route) res[response.route].update(response) else res[response.route] = Fitting::Cover::Response.new(response) end end.map do |key, value| @list[key] = value.to_hash end @list end def template return @template if @template @template = {} to_hash.each do |key, value| @template[key] = value @template[key]['cover'] = 100.0 if value['flags'] == [] @template[key]['type'] = 'passed' else flag_true = value['flags'].find_all { |flag| flag == true } flag_false = value['flags'].find_all { |flag| flag == false } if flag_false.empty? @template[key]['type'] = 'passed' else @template[key]['cover'] = if flag_true.empty? 0.0 else flag_false.size / flag_true.size end @template[key]['type'] = 'failed' end end @template[key]['json_schema'] = JSON.pretty_generate(value['json_schemas'].last) end @template end def save to_hash contents = File.read(File.expand_path('../view/report.html.haml', __FILE__)) html = "<style>\n#{File.read(File.expand_path('../view/style.css', __FILE__))}\n</style>\n" html += Haml::Engine.new(contents).render( Object.new, :@to_hash => template ) html end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
fitting-2.9.0 | lib/fitting/cover.rb |
fitting-2.8.1 | lib/fitting/cover.rb |
fitting-2.8.0 | lib/fitting/cover.rb |
fitting-2.7.2 | lib/fitting/cover.rb |