Class: Fitting::Cover
- Inherits:
-
Object
show all
- Defined in:
- lib/fitting/cover.rb,
lib/fitting/cover/response.rb,
lib/fitting/cover/json_schema.rb
Defined Under Namespace
Classes: JSONSchema, Response
Instance Method Summary
collapse
Constructor Details
#initialize(all_responses, coverage) ⇒ Cover
Returns a new instance of Cover.
7
8
9
10
11
|
# File 'lib/fitting/cover.rb', line 7
def initialize(all_responses, coverage)
@all_responses = all_responses
@coverage = coverage
@list = {}
end
|
Instance Method Details
#save ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/fitting/cover.rb', line 55
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
|
#template ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/fitting/cover.rb', line 28
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.size == 0
@template[key]['type'] = 'passed'
else
if flag_true.size == 0
@template[key]['cover'] = 0.0
else
@template[key]['cover'] = 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
|
#to_hash ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/fitting/cover.rb', line 13
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
|