structured-acceptance-test 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/JSONable.rb +50 -0
- data/lib/detail.rb +8 -2
- data/lib/finding.rb +23 -3
- data/lib/fix.rb +5 -1
- data/lib/location.rb +30 -1
- data/lib/process.rb +87 -72
- data/lib/stat.rb +38 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49cc33e85de90d729c0e7a88d5d9fdc198fd5249
|
4
|
+
data.tar.gz: 42509a0de215fd4956d1277b90265845cf0491b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dfdc18dc345aaac83b4f0386e68e1952143183576f1dcac592dfa14bbc8329e9416814c819ba8a11315ccde955852dddbb1fe24664ad36c165eb7e111d2b0ea
|
7
|
+
data.tar.gz: 334a82473516230ac3ce8831466f2dc7f9c628a4a4587bda0bcb55c613a24604be829192369e0365ca361393588e7a2a697455f781e760271239b4e7af1ace2f
|
data/lib/JSONable.rb
CHANGED
@@ -1,7 +1,51 @@
|
|
1
1
|
module StatModule
|
2
2
|
require 'json'
|
3
|
+
require 'colorize'
|
3
4
|
|
4
5
|
class JSONable
|
6
|
+
|
7
|
+
FORMATTING_STAR = '⭐'
|
8
|
+
FORMATTING_CHECKMARK = '✅'
|
9
|
+
FORMATTING_BALL = '⚫'
|
10
|
+
FORMATTING_WARNING = '⚠'
|
11
|
+
|
12
|
+
def initialize(hash)
|
13
|
+
if hash.is_a? Hash
|
14
|
+
hash.each do |k, v|
|
15
|
+
if v.is_a? Array
|
16
|
+
items = []
|
17
|
+
v.each { |i|
|
18
|
+
case k
|
19
|
+
when 'findings'
|
20
|
+
item = StatModule::Finding.new(nil, nil, nil, i)
|
21
|
+
when 'fixes'
|
22
|
+
item = StatModule::Fix.new(nil, i)
|
23
|
+
when 'traces'
|
24
|
+
item = StatModule::Location.new(nil, i)
|
25
|
+
else
|
26
|
+
v = item
|
27
|
+
end
|
28
|
+
items.push(item)
|
29
|
+
}
|
30
|
+
v = items
|
31
|
+
end
|
32
|
+
if v.is_a? Hash
|
33
|
+
case k
|
34
|
+
when 'process'
|
35
|
+
v = StatModule::Process.new(nil, v)
|
36
|
+
when 'location'
|
37
|
+
v = StatModule::Location.new(nil, v)
|
38
|
+
when 'detail'
|
39
|
+
v = StatModule::Detail.new(nil, v)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
self.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair
|
43
|
+
self.class.send(:define_method, k, proc { self.instance_variable_get("@#{k}") }) ## create the getter that returns the instance variable
|
44
|
+
self.class.send(:define_method, "#{k}=", proc { |v| self.instance_variable_set("@#{k}", v) }) ## create the setter that sets the instance variable
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
5
49
|
def to_json(excluded_fields = [])
|
6
50
|
hash = {}
|
7
51
|
self.instance_variables.each do |var|
|
@@ -9,5 +53,11 @@ module StatModule
|
|
9
53
|
end
|
10
54
|
hash.to_json
|
11
55
|
end
|
56
|
+
|
57
|
+
def self.from_json! string
|
58
|
+
JSON.load(string).each do |var, val|
|
59
|
+
self.instance_variable_set '@' + var, val
|
60
|
+
end
|
61
|
+
end
|
12
62
|
end
|
13
63
|
end
|
data/lib/detail.rb
CHANGED
data/lib/finding.rb
CHANGED
@@ -3,13 +3,19 @@ module StatModule
|
|
3
3
|
|
4
4
|
class Finding < JSONable
|
5
5
|
|
6
|
-
def initialize(failure, rule, description)
|
6
|
+
def initialize(failure, rule, description, hash = nil)
|
7
|
+
@categories = []
|
8
|
+
@fixes = []
|
9
|
+
|
10
|
+
if hash.is_a? Hash
|
11
|
+
super(hash)
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
7
15
|
raise TypeException unless rule.is_a?(String) && description.is_a?(String)
|
8
16
|
@failure = failure
|
9
17
|
@rule = rule
|
10
18
|
@description = description
|
11
|
-
@categories = []
|
12
|
-
@fixes = []
|
13
19
|
end
|
14
20
|
|
15
21
|
def failure=(failure)
|
@@ -99,5 +105,19 @@ module StatModule
|
|
99
105
|
def fixes
|
100
106
|
@fixes
|
101
107
|
end
|
108
|
+
|
109
|
+
def print(formatted = false)
|
110
|
+
result = "#{rule}, #{description}"
|
111
|
+
if formatted
|
112
|
+
if failure
|
113
|
+
result = "#{FORMATTING_BALL} #{result}".colorize(:red)
|
114
|
+
else
|
115
|
+
result = "#{FORMATTING_WARNING} #{result}".colorize(:yellow)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
result += "\n#{location.print}" unless location.nil?
|
119
|
+
result += "\nRECOMMENDATION: #{recommendation}" unless recommendation.nil?
|
120
|
+
result
|
121
|
+
end
|
102
122
|
end
|
103
123
|
end
|
data/lib/fix.rb
CHANGED
data/lib/location.rb
CHANGED
@@ -3,7 +3,11 @@ module StatModule
|
|
3
3
|
|
4
4
|
class Location < JSONable
|
5
5
|
|
6
|
-
def initialize(path)
|
6
|
+
def initialize(path, hash = nil)
|
7
|
+
if hash.is_a? Hash
|
8
|
+
super(hash)
|
9
|
+
return
|
10
|
+
end
|
7
11
|
@path = path
|
8
12
|
end
|
9
13
|
|
@@ -51,5 +55,30 @@ module StatModule
|
|
51
55
|
def end_column
|
52
56
|
@endColumn
|
53
57
|
end
|
58
|
+
|
59
|
+
def print
|
60
|
+
result = "in #{path}"
|
61
|
+
if !begin_line.nil? && !end_line.nil?
|
62
|
+
if begin_line != end_line
|
63
|
+
if !begin_column.nil? && !end_column.nil?
|
64
|
+
result += ", line #{begin_line}:#{begin_column} to line #{end_line}:#{end_column}"
|
65
|
+
elsif !begin_column.nil? && end_column.nil?
|
66
|
+
result += ", line #{begin_line}:#{begin_column} to line #{end_line}"
|
67
|
+
elsif begin_column.nil? && !end_column.nil?
|
68
|
+
result += ", line #{begin_line} to line #{end_line}:#{end_column}"
|
69
|
+
else
|
70
|
+
result += ", lines #{begin_line}-#{end_line}"
|
71
|
+
end
|
72
|
+
else
|
73
|
+
if begin_column.nil?
|
74
|
+
result += ", line #{begin_line}"
|
75
|
+
else
|
76
|
+
result += ", line #{begin_line}:#{begin_column}"
|
77
|
+
result += "-#{end_column}" unless end_column.nil?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
result
|
82
|
+
end
|
54
83
|
end
|
55
84
|
end
|
data/lib/process.rb
CHANGED
@@ -1,76 +1,91 @@
|
|
1
1
|
module StatModule
|
2
2
|
|
3
|
-
require_relative 'JSONable'
|
4
|
-
|
5
|
-
class Process < JSONable
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
3
|
+
require_relative 'JSONable'
|
4
|
+
|
5
|
+
class Process < JSONable
|
6
|
+
|
7
|
+
def initialize(name, hash)
|
8
|
+
if hash.is_a? Hash
|
9
|
+
super(hash)
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
raise TypeException unless name.is_a?(String)
|
14
|
+
@name = name
|
15
|
+
end
|
16
|
+
|
17
|
+
def name=(name)
|
18
|
+
raise TypeException unless name.is_a?(String)
|
19
|
+
@name = name
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
@name
|
24
|
+
end
|
25
|
+
|
26
|
+
def version=(version)
|
27
|
+
raise TypeException unless version.is_a?(String)
|
28
|
+
@version = version
|
29
|
+
end
|
30
|
+
|
31
|
+
def version
|
32
|
+
@version
|
33
|
+
end
|
34
|
+
|
35
|
+
def description=(description)
|
36
|
+
raise TypeException unless description.is_a?(String)
|
37
|
+
@description = description
|
38
|
+
end
|
39
|
+
|
40
|
+
def description
|
41
|
+
@description
|
42
|
+
end
|
43
|
+
|
44
|
+
def maintainer=(maintainer)
|
45
|
+
raise TypeException unless maintainer.is_a?(String)
|
46
|
+
@maintainer = maintainer
|
47
|
+
end
|
48
|
+
|
49
|
+
def maintainer
|
50
|
+
@maintainer
|
51
|
+
end
|
52
|
+
|
53
|
+
def email=(email)
|
54
|
+
raise TypeException unless email.is_a?(String)
|
55
|
+
@email = email
|
56
|
+
end
|
57
|
+
|
58
|
+
def email
|
59
|
+
@email
|
60
|
+
end
|
61
|
+
|
62
|
+
def website=(website)
|
63
|
+
raise TypeException unless website.is_a?(String)
|
64
|
+
@website = website
|
65
|
+
end
|
66
|
+
|
67
|
+
def website
|
68
|
+
@website
|
69
|
+
end
|
70
|
+
|
71
|
+
def repeatability=(repeatability)
|
72
|
+
raise TypeException unless Repeatability.all.include?(repeatability)
|
73
|
+
@repeatability = repeatability
|
74
|
+
end
|
75
|
+
|
76
|
+
def repeatability
|
77
|
+
@repeatability
|
78
|
+
end
|
79
|
+
|
80
|
+
def print(formatted = nil)
|
81
|
+
result = name
|
82
|
+
unless version.nil?
|
83
|
+
result += ", version #{version}"
|
84
|
+
end
|
85
|
+
if formatted
|
86
|
+
result = "#{FORMATTING_STAR.colorize(:yellow)} #{result}"
|
87
|
+
end
|
88
|
+
result
|
89
|
+
end
|
42
90
|
end
|
43
|
-
|
44
|
-
def maintainer
|
45
|
-
@maintainer
|
46
|
-
end
|
47
|
-
|
48
|
-
def email=(email)
|
49
|
-
raise TypeException unless email.is_a?(String)
|
50
|
-
@email = email
|
51
|
-
end
|
52
|
-
|
53
|
-
def email
|
54
|
-
@email
|
55
|
-
end
|
56
|
-
|
57
|
-
def website=(website)
|
58
|
-
raise TypeException unless website.is_a?(String)
|
59
|
-
@website = website
|
60
|
-
end
|
61
|
-
|
62
|
-
def website
|
63
|
-
@website
|
64
|
-
end
|
65
|
-
|
66
|
-
def repeatability=(repeatability)
|
67
|
-
raise TypeException unless Repeatability.all.include?(repeatability)
|
68
|
-
@repeatability = repeatability
|
69
|
-
end
|
70
|
-
|
71
|
-
def repeatability
|
72
|
-
@repeatability
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
91
|
end
|
data/lib/stat.rb
CHANGED
@@ -15,12 +15,18 @@ module StatModule
|
|
15
15
|
class Stat < JSONable
|
16
16
|
attr_reader :statVersion
|
17
17
|
|
18
|
-
def initialize(process)
|
18
|
+
def initialize(process, hash = nil)
|
19
|
+
@finding_print_index = 0
|
20
|
+
@findings = []
|
21
|
+
|
22
|
+
if hash.is_a? Hash
|
23
|
+
super(hash)
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
19
27
|
raise TypeException unless process.is_a?(StatModule::Process)
|
20
28
|
@statVersion = '1.0.0'
|
21
29
|
@process = process
|
22
|
-
@findings = []
|
23
|
-
@finding_print_index = 0
|
24
30
|
end
|
25
31
|
|
26
32
|
def findings=(findings)
|
@@ -55,6 +61,7 @@ module StatModule
|
|
55
61
|
result = result[0..result.length - 3]
|
56
62
|
puts(result)
|
57
63
|
puts
|
64
|
+
$stdout.flush
|
58
65
|
end
|
59
66
|
|
60
67
|
def print_finding
|
@@ -63,6 +70,7 @@ module StatModule
|
|
63
70
|
result += ',' unless @finding_print_index >= @findings.length - 1
|
64
71
|
puts(result)
|
65
72
|
puts
|
73
|
+
$stdout.flush
|
66
74
|
@finding_print_index += 1
|
67
75
|
else
|
68
76
|
raise IndexOutOfBoundException
|
@@ -73,10 +81,37 @@ module StatModule
|
|
73
81
|
@finding_print_index = 0
|
74
82
|
puts ']}'
|
75
83
|
puts
|
84
|
+
$stdout.flush
|
76
85
|
end
|
77
86
|
|
78
87
|
def to_json(options = {})
|
79
88
|
super(['finding_print_index'])
|
80
89
|
end
|
90
|
+
|
91
|
+
def summary_print(formatted = false)
|
92
|
+
errors = 0
|
93
|
+
warnings = 0
|
94
|
+
findings.each { |finding|
|
95
|
+
if finding.failure
|
96
|
+
errors += 1
|
97
|
+
else
|
98
|
+
warnings += 1
|
99
|
+
end
|
100
|
+
}
|
101
|
+
if errors == 0 && warnings == 0
|
102
|
+
result = "#{FORMATTING_CHECKMARK} PASSED with no warning".colorize(:green)
|
103
|
+
elsif errors == 0
|
104
|
+
result = "#{FORMATTING_WARNING} PASSED with #{warnings} warning".colorize(:yellow)
|
105
|
+
elsif warnings == 0
|
106
|
+
result = "#{FORMATTING_BALL} FAILED with #{errors} error".colorize(:red)
|
107
|
+
else
|
108
|
+
result = "#{FORMATTING_BALL} FAILED with #{errors} error and #{warnings} warning".colorize(:red)
|
109
|
+
end
|
110
|
+
if formatted
|
111
|
+
result
|
112
|
+
else
|
113
|
+
result[result.index(' ') + 1..result.length]
|
114
|
+
end
|
115
|
+
end
|
81
116
|
end
|
82
117
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: structured-acceptance-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Entriken
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-02
|
12
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Structured acceptance test data structure gem
|
15
15
|
email: github.com@phor.net
|