reflekt 0.1.2 → 0.4.0

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/reflekt.rb +55 -19
  3. data/lib/template.html.erb +20 -0
  4. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f06cf08a2480f6d8185b2cad1b4671ed618825efecd9338f53abcc8e85322a78
4
- data.tar.gz: bc805bee9d14f3ad6a119532d950ff88a6c413bf68ca6f8648d71ed6e4bdadc8
3
+ metadata.gz: 9dab0fd8f1b076c4d4a4d6d7f571af7a6488e6d7a2a2fb430c4563cf12a8b011
4
+ data.tar.gz: 22ac5bf780e0d048b50a902ce498f679d03c24a6e251b48ce31511c3d0829a6c
5
5
  SHA512:
6
- metadata.gz: 3d240da65e9ee473091aad1a42646c2655995218318187d888f75d68ec674a0c6954350deb8ed3817853cf592c946696cce7b7372d9f5c3bf808984e3080a08b
7
- data.tar.gz: 6e5ae5a9cb89310c78169c56fafd56b3047ba89d55f1b405f30a3413348a0cb3592f8c4b8652bd7abe5d01313a2dc2fa6a0790e140445d57a56c35f33d2ec82f
6
+ metadata.gz: 251b7a98ea53230c50f2b3f77e602b5456b4a60b59a73c41e511b498d25b72c50a632cbadce1d887644c08ae32c90a30e36fb0ea51cffb437e0c3037a857ae7d
7
+ data.tar.gz: ba4872b5ef00a2fec12e9a2ebb662f3024e1411f529bc467fdd6d8c67a54382fb99c72e800c7cb07671eee165e00f6e231d1e600e9dfb91c59b175d3e48989d3
@@ -1,13 +1,7 @@
1
1
  require 'set'
2
-
3
- # Production.
2
+ require 'erb'
4
3
  require 'rowdb'
5
4
 
6
- # Development.
7
- #require_relative '../../rowdb/lib/rowdb.rb'
8
- #require_relative '../../rowdb/lib/adapters/Adapter.rb'
9
- #require_relative '../../rowdb/lib/adapters/FileSystem.rb'
10
-
11
5
  ################################################################################
12
6
  # REFLEKT
13
7
  #
@@ -19,7 +13,7 @@ require 'rowdb'
19
13
 
20
14
  module Reflekt
21
15
 
22
- @@clone_count = 5
16
+ @@reflekt_clone_count = 5
23
17
 
24
18
  def initialize(*args)
25
19
 
@@ -33,10 +27,25 @@ module Reflekt
33
27
  # When method called in flow.
34
28
  if @reflekt_forked
35
29
  unless self.class.deflekted?(method)
30
+
36
31
  # Reflekt on method.
37
32
  @reflekt_clones.each do |clone|
38
33
  reflekt_action(clone, method, *args)
39
34
  end
35
+
36
+ # Save results.
37
+ @@reflekt_db.write()
38
+
39
+ # Render results.
40
+ @@reflekt_json = File.read("#{@@reflekt_output_path}/db.json")
41
+ template = File.read("#{@@reflekt_path}/template.html.erb")
42
+ rendered = ERB.new(template).result(binding)
43
+
44
+ # Write results.
45
+ File.open("#{@@reflekt_output_path}/index.html", 'w+') do |f|
46
+ f.write rendered
47
+ end
48
+
40
49
  end
41
50
  end
42
51
 
@@ -56,7 +65,7 @@ module Reflekt
56
65
 
57
66
  def reflekt_fork()
58
67
 
59
- @@clone_count.times do |clone|
68
+ @@reflekt_clone_count.times do |clone|
60
69
  @reflekt_clones << self.clone
61
70
  end
62
71
 
@@ -66,6 +75,9 @@ module Reflekt
66
75
 
67
76
  def reflekt_action(clone, method, *args)
68
77
 
78
+ class_name = clone.class.to_s
79
+ method_name = method.to_s
80
+
69
81
  # Create new arguments.
70
82
  new_args = []
71
83
  args.each do |arg|
@@ -80,12 +92,24 @@ module Reflekt
80
92
  # Action method with new arguments.
81
93
  begin
82
94
  clone.send(method, *new_args)
95
+
96
+ # Build reflection.
97
+ reflection = {
98
+ "time" => Time.now.to_i,
99
+ }
100
+ # When error.
83
101
  rescue StandardError => error
84
- p error
102
+ reflection["status"] = "error"
103
+ reflection["error"] = error
104
+ # When success.
85
105
  else
86
- puts "Success."
106
+ reflection["status"] = "success"
87
107
  end
88
108
 
109
+ # Save reflection.
110
+ @@reflekt_db.get("#{class_name}.#{method_name}")
111
+ .push(reflection)
112
+
89
113
  end
90
114
 
91
115
  private
@@ -94,21 +118,33 @@ module Reflekt
94
118
  def self.prepended(base)
95
119
  base.singleton_class.prepend(Klass)
96
120
 
97
- @@setup ||= setup_klass
121
+ @@reflekt_setup ||= reflekt_setup_klass
98
122
  end
99
123
 
100
124
  # Setup Klass.
101
- def self.setup_klass()
125
+ def self.reflekt_setup_klass()
126
+
127
+ # Receive configuration from host application.
128
+ $ENV ||= {}
129
+ $ENV[:reflekt] ||= $ENV[:reflekt] = {}
102
130
 
131
+ @@reflekt_path = File.dirname(File.realpath(__FILE__))
132
+
133
+ # Create "reflections" directory in configured path.
134
+ if $ENV[:reflekt][:output_path]
135
+ @@reflekt_output_path = File.join($ENV[:reflekt][:output_path], 'reflections')
103
136
  # Create "reflections" directory in current execution path.
104
- # TODO: Allow override of path via global config.
105
- dir_path = File.join(Dir.pwd, 'reflections')
106
- unless Dir.exist? dir_path
107
- Dir.mkdir(dir_path)
137
+ else
138
+ @@reflekt_output_path = File.join(Dir.pwd, 'reflections')
139
+ end
140
+
141
+ unless Dir.exist? @@reflekt_output_path
142
+ Dir.mkdir(@@reflekt_output_path)
108
143
  end
109
144
 
110
- @@db = Rowdb.new(dir_path + '/db.json')
111
- @@db.defaults({items: []})
145
+ # Create database.
146
+ @@reflekt_db = Rowdb.new(@@reflekt_output_path + '/db.json')
147
+ @@reflekt_db.defaults({ :reflekt => { :api_version => 1 }}).write()
112
148
 
113
149
  return true
114
150
  end
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Reflekt</title>
6
+ <meta name="description" content="">
7
+ <meta name="author" content="">
8
+ <meta name="viewport" content="width=device-width, initial-scale=1">
9
+ <link rel="stylesheet" href="">
10
+ <link rel="shortcut icon" href="">
11
+ </head>
12
+ <body>
13
+
14
+ <script>
15
+ var reflections = JSON.parse(<%= @@reflekt_json %>)
16
+ console.log(reflections)
17
+ </script>
18
+
19
+ </body>
20
+ </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reflekt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maedi Prichard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-18 00:00:00.000000000 Z
11
+ date: 2020-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rowdb
@@ -24,13 +24,14 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: Reflection-driven development via reflection testing.
27
+ description: Testing that's completely automated.
28
28
  email: maediprichard@gmailcom
29
29
  executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
33
  - lib/reflekt.rb
34
+ - lib/template.html.erb
34
35
  homepage: https://github.com/maedi/reflekt
35
36
  licenses:
36
37
  - MPL-2.0
@@ -53,5 +54,5 @@ requirements: []
53
54
  rubygems_version: 3.0.2
54
55
  signing_key:
55
56
  specification_version: 4
56
- summary: Reflection-driven development.
57
+ summary: Reflective testing.
57
58
  test_files: []