reflekt 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9282a0295c04e95cec339bfa6563a517ac12d964f6310320056669ad52b86e1
4
- data.tar.gz: 8ad30ad01a3c021d60eb645e56ddf7aea528860ca30588bb9269dac0a5cc74d8
3
+ metadata.gz: 4a8f70f5646d8276359aaf74b703172bbadc1d9025d8a716183578365fd91014
4
+ data.tar.gz: 9666d1aadc1b8ef280ac68da0c66f75b5c399d4eb67898079abcb82aa23baf23
5
5
  SHA512:
6
- metadata.gz: e7be8cc94f17f83c4c5131862c0ffa424c7976f4baae38d535e2a45f77318d47543493b0259dc0a7a62ad7481a380615c09030060d29ef0462c4ab6bfa6d5cb2
7
- data.tar.gz: 7fcee25ce29344e2181a8db3f3020c11ab4668560651869e81cfa5e059aa31ae35ce45c06892a19946b8509f2d592e0dc7d171ede27b1d6b5f45fa1dbff3744c
6
+ metadata.gz: 68cecdc1e2552bc59dc4fb3a5001f094425a78dd9b96504e2f3270a9cf82b6767e719e8398731d57c58a6ddf20ca30fe3cae66ff75a172bf7d9f73ce758c7b3b
7
+ data.tar.gz: cfabac18abb5dda7b90d3cfa0e8494ece8f9c2a48f3fc8a5c8fff8162eddfbee9b8bc9210fd05ae79d384ded033ef69a6eb1b57d84675dd9c0a71e1ab3dbaf67
@@ -13,6 +13,11 @@ require 'rowdb'
13
13
 
14
14
  module Reflekt
15
15
 
16
+ REFLEKT_STATUS = "s"
17
+ REFLEKT_PASS = "p"
18
+ REFLEKT_FAIL = "f"
19
+ REFLEKT_MESSAGE = "m"
20
+
16
21
  @@reflekt_clone_count = 5
17
22
 
18
23
  def initialize(*args)
@@ -21,7 +26,7 @@ module Reflekt
21
26
  @reflekt_clones = []
22
27
 
23
28
  # Limit the amount of clones that can be created per instance.
24
- # A method called 30,000 times doesn't need that many reflections.
29
+ # A method called thousands of times doesn't need that many reflections.
25
30
  @reflekt_limit = 5
26
31
  @reflekt_count = 0
27
32
 
@@ -43,25 +48,7 @@ module Reflekt
43
48
  # Save results.
44
49
  @@reflekt_db.write()
45
50
 
46
- # Render results.
47
- @@reflekt_json = File.read("#{@@reflekt_output_path}/db.json")
48
- template = File.read("#{@@reflekt_path}/web/template.html.erb")
49
- rendered = ERB.new(template).result(binding)
50
- File.open("#{@@reflekt_output_path}/index.html", 'w+') do |f|
51
- f.write rendered
52
- end
53
-
54
- # Add JS.
55
- alpinejs = File.read("#{@@reflekt_path}/web/alpine.js")
56
- File.open("#{@@reflekt_output_path}/alpine.js", 'w+') do |f|
57
- f.write alpinejs
58
- end
59
-
60
- # Add CSS.
61
- stylesheet = File.read("#{@@reflekt_path}/web/style.css")
62
- File.open("#{@@reflekt_output_path}/style.css", 'w+') do |f|
63
- f.write stylesheet
64
- end
51
+ reflekt_render()
65
52
 
66
53
  end
67
54
  @reflekt_count = @reflekt_count + 1
@@ -114,21 +101,43 @@ module Reflekt
114
101
  clone.send(method, *new_args)
115
102
 
116
103
  # Build reflection.
117
- reflection = {
118
- "time" => Time.now.to_i,
119
- }
104
+ reflection = { "time" => Time.now.to_i }
105
+
120
106
  # When fail.
121
- rescue StandardError => error
122
- reflection["status"] = "error"
123
- reflection["error"] = error
107
+ rescue StandardError => message
108
+ reflection[REFLEKT_STATUS] = REFLEKT_MESSAGE
109
+ reflection[REFLEKT_MESSAGE] = message
124
110
  # When pass.
125
111
  else
126
- reflection["status"] = "pass"
112
+ reflection[REFLEKT_STATUS] = REFLEKT_PASS
127
113
  end
128
114
 
129
115
  # Save reflection.
130
- @@reflekt_db.get("#{class_name}.#{method_name}")
131
- .push(reflection)
116
+ @@reflekt_db.get("#{class_name}.#{method_name}").push(reflection)
117
+
118
+ end
119
+
120
+ def reflekt_render()
121
+
122
+ # Render results.
123
+ @@reflekt_json = File.read("#{@@reflekt_output_path}/db.json")
124
+ template = File.read("#{@@reflekt_path}/web/template.html.erb")
125
+ rendered = ERB.new(template).result(binding)
126
+ File.open("#{@@reflekt_output_path}/index.html", 'w+') do |f|
127
+ f.write rendered
128
+ end
129
+
130
+ # Add JS.
131
+ javascript = File.read("#{@@reflekt_path}/web/alpine.js")
132
+ File.open("#{@@reflekt_output_path}/alpine.js", 'w+') do |f|
133
+ f.write javascript
134
+ end
135
+
136
+ # Add CSS.
137
+ stylesheet = File.read("#{@@reflekt_path}/web/style.css")
138
+ File.open("#{@@reflekt_output_path}/style.css", 'w+') do |f|
139
+ f.write stylesheet
140
+ end
132
141
 
133
142
  end
134
143
 
@@ -1,23 +1,30 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
+
3
4
  <head>
4
5
  <meta charset="utf-8">
5
6
  <title>Reflekt</title>
6
- <meta name="description" content="">
7
- <meta name="author" content="">
7
+ <meta name="description" content="Reflective testing results.">
8
+ <meta name="author" content="Maedi Prichard">
8
9
  <meta name="viewport" content="width=device-width, initial-scale=1">
9
10
  <link rel="stylesheet" href="style.css">
10
11
  <link rel="shortcut icon" href="">
11
12
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
12
13
  <link href="https://fonts.googleapis.com/css2?family=Merriweather&display=swap" rel="stylesheet">
13
14
  </head>
15
+
14
16
  <body>
15
17
 
16
18
  <script>
17
19
 
20
+ const STATUS = "s";
21
+ const PASS = "p";
22
+ const FAIL = "f";
23
+
18
24
  function getReflections() {
19
25
 
20
26
  var reflections = JSON.parse(<%= @@reflekt_json %>);
27
+ console.log("REFLECTIONS:");
21
28
  console.log(reflections);
22
29
  var results = {};
23
30
 
@@ -43,16 +50,16 @@
43
50
 
44
51
  // Method pass rate.
45
52
  var pass_count = method.reduce(function(obj, v) {
46
- obj[v.status] = (obj[v.status] || 0) + 1;
53
+ obj[v[STATUS]] = (obj[v[STATUS]] || 0) + 1;
47
54
  return obj;
48
55
  }, {});
49
56
 
50
- var pass_rate = (pass_count['pass'] / method.length) * 100;
57
+ var pass_rate = (pass_count[PASS] / method.length) * 100;
51
58
  results[class_id]['methods'][method_id] = {
52
59
  'stats': {
53
60
  'pass_rate': pass_rate,
54
61
  'test_count': method.length,
55
- 'pass_count': pass_count['pass']
62
+ 'pass_count': pass_count[PASS]
56
63
  }
57
64
  };
58
65
  if (pass_rate == 100) {
@@ -64,7 +71,7 @@
64
71
 
65
72
  // Class pass rate.
66
73
  results[class_id]['stats']['test_count'] += method.length;
67
- results[class_id]['stats']['pass_count'] += pass_count['pass'];
74
+ results[class_id]['stats']['pass_count'] += pass_count[PASS];
68
75
 
69
76
  }
70
77
 
@@ -98,14 +105,14 @@
98
105
  </div>
99
106
 
100
107
  <ul class="panels">
101
- <template x-for="[class_id, klass] in Object.entries(getReflections()['refs'])" :key="class_id">
108
+ <template x-for="[class_id, klass] in Object.entries(refs)" :key="class_id">
102
109
 
103
110
  <li class="panel">
104
111
 
105
112
  <div class="reflection class" x-bind:class="` ${ klass.status } `">
106
113
  <h2 x-text="` ${class_id}() `"></h2>
107
114
  <div class="stats">
108
- <div class="stat" x-text="` ${klass.stats.pass_rate}% `"></div>
115
+ <div class="stat" x-text="` ${klass.stats.pass_rate.toFixed(2)}% `"></div>
109
116
  </div>
110
117
  </div>
111
118
 
@@ -114,7 +121,7 @@
114
121
  <li class="reflection method" x-bind:class="` ${ method.status } `">
115
122
  <h3 x-text="` ${method_id}() `"></h3>
116
123
  <div class="stats">
117
- <div class="stat" x-text="` ${method.stats.pass_rate}% `"></div>
124
+ <div class="stat" x-text="` ${method.stats.pass_rate.toFixed(2)}% `"></div>
118
125
  </div>
119
126
  </li>
120
127
  </template>
@@ -130,4 +137,5 @@
130
137
  <script src="alpine.js"></script>
131
138
 
132
139
  </body>
140
+
133
141
  </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reflekt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maedi Prichard