lizarb 0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +13 -2
  4. data/Gemfile +22 -2
  5. data/Gemfile.lock +52 -0
  6. data/README.md +88 -12
  7. data/app/dev/benches/app_bench.rb +5 -0
  8. data/app/dev/benches/app_bench_test.rb +7 -0
  9. data/app/dev/benches/loops_bench.rb +148 -0
  10. data/app/dev/benches/loops_bench_test.rb +11 -0
  11. data/app/dev/commands/app_command.rb +5 -0
  12. data/app/dev/commands/app_command_test.rb +7 -0
  13. data/app/dev/commands/example_command.rb +57 -0
  14. data/app/dev/commands/example_command_test.rb +43 -0
  15. data/app/dev/commands/macro_child_command.rb +32 -0
  16. data/app/dev/commands/macro_child_command_test.rb +7 -0
  17. data/app/dev/commands/macro_parent_command.rb +70 -0
  18. data/app/dev/commands/macro_parent_command_test.rb +7 -0
  19. data/app/dev/commands/my_command.rb +7 -0
  20. data/app/dev/commands/my_command_test.rb +7 -0
  21. data/app/dev/commands/new_command.rb +9 -0
  22. data/app/dev/commands/new_command_test.rb +7 -0
  23. data/app/dev/generators/bench_generator.rb +67 -0
  24. data/app/dev/generators/bench_generator_test.rb +12 -0
  25. data/app/dev/generators/command_generator.rb +51 -0
  26. data/app/dev/generators/command_generator_test.rb +12 -0
  27. data/app/dev/generators/model_generator.rb +46 -0
  28. data/app/dev/generators/model_generator_test.rb +12 -0
  29. data/app/dev/generators/request_generator.rb +63 -0
  30. data/app/dev/generators/request_generator_test.rb +12 -0
  31. data/app/dev_box.rb +13 -0
  32. data/app/happy/axos/axo.rb +50 -0
  33. data/app/happy_box.rb +8 -0
  34. data/app/net/databases/redis_db.rb +5 -0
  35. data/app/net/databases/redis_db_test.rb +12 -0
  36. data/app/net/databases/sqlite_db.rb +11 -0
  37. data/app/net/databases/sqlite_db_test.rb +12 -0
  38. data/app/net/models/app_model.rb +20 -0
  39. data/app/net/models/app_model_test.rb +8 -0
  40. data/app/net/models/post_model.rb +4 -0
  41. data/app/net/models/post_model_test.rb +8 -0
  42. data/app/net/models/user_model.rb +4 -0
  43. data/app/net/models/user_model_test.rb +8 -0
  44. data/app/net_box.rb +21 -0
  45. data/app/web/requests/api_request.rb +61 -0
  46. data/app/web/requests/api_request_test.rb +31 -0
  47. data/app/web/requests/app_request.rb +5 -0
  48. data/app/web/requests/app_request_test.rb +7 -0
  49. data/app/web/requests/assets_request.rb +71 -0
  50. data/app/web/requests/assets_request_test.rb +33 -0
  51. data/app/web/requests/root_request.rb +55 -0
  52. data/app/web/requests/root_request_test.rb +31 -0
  53. data/app/web_box.rb +8 -0
  54. data/app.code.env +11 -0
  55. data/app.env +11 -0
  56. data/app.rb +17 -0
  57. data/app_new/.gitignore +4 -0
  58. data/app_new/Gemfile +31 -0
  59. data/app_new/Procfile +3 -0
  60. data/exe/Gemfile +3 -0
  61. data/exe/Gemfile.lock +13 -0
  62. data/exe/liza +3 -0
  63. data/exe/lizarb +11 -0
  64. data/lib/app.rb +200 -0
  65. data/lib/dev_system/dev/controllers/bench.rb +11 -0
  66. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
  67. data/lib/dev_system/dev/controllers/bench_test.rb +14 -0
  68. data/lib/dev_system/dev/controllers/command/bench_command.rb +24 -0
  69. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
  70. data/lib/dev_system/dev/controllers/command/dev_command.rb +24 -0
  71. data/lib/dev_system/dev/controllers/command/dev_command_test.rb +14 -0
  72. data/lib/dev_system/dev/controllers/command/echo_command.rb +11 -0
  73. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +14 -0
  74. data/lib/dev_system/dev/controllers/command/generate_command.rb +23 -0
  75. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
  76. data/lib/dev_system/dev/controllers/command/test_command.rb +70 -0
  77. data/lib/dev_system/dev/controllers/command/test_command_test.rb +14 -0
  78. data/lib/dev_system/dev/controllers/command/version_command.rb +9 -0
  79. data/lib/dev_system/dev/controllers/command/version_command_test.rb +14 -0
  80. data/lib/dev_system/dev/controllers/command.rb +19 -0
  81. data/lib/dev_system/dev/controllers/command_test.rb +14 -0
  82. data/lib/dev_system/dev/controllers/generator.rb +11 -0
  83. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
  84. data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
  85. data/lib/dev_system/dev/controllers/generators/app_generator.rb +71 -0
  86. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
  87. data/lib/dev_system/dev/controllers/shell/file_shell.rb +29 -0
  88. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +14 -0
  89. data/lib/dev_system/dev/controllers/shell.rb +19 -0
  90. data/lib/dev_system/dev/controllers/shell_test.rb +13 -0
  91. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +19 -0
  92. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
  93. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
  94. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
  95. data/lib/dev_system/dev/controllers/terminal.rb +19 -0
  96. data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
  97. data/lib/dev_system/dev/dev_box.rb +22 -0
  98. data/lib/dev_system/dev/dev_box_test.rb +19 -0
  99. data/lib/dev_system/dev/panels/command_panel.rb +10 -0
  100. data/lib/dev_system/dev/panels/command_panel_test.rb +23 -0
  101. data/lib/dev_system/dev/panels/log_panel.rb +10 -0
  102. data/lib/dev_system/dev/panels/log_panel_test.rb +18 -0
  103. data/lib/dev_system.rb +8 -0
  104. data/lib/happy_system/dev/happy_command.rb +11 -0
  105. data/lib/happy_system/happy/controllers/axo.rb +8 -0
  106. data/lib/happy_system/happy/happy_box.rb +12 -0
  107. data/lib/happy_system/happy/happy_box_test.rb +18 -0
  108. data/lib/happy_system/happy/panels/axo_panel.rb +5 -0
  109. data/lib/{viral.rb → happy_system.rb} +7 -3
  110. data/lib/liza/base/box.rb +40 -0
  111. data/lib/liza/base/box_test.rb +12 -0
  112. data/lib/liza/base/controller.rb +27 -0
  113. data/lib/liza/base/controller_test.rb +12 -0
  114. data/lib/liza/base/panel.rb +38 -0
  115. data/lib/liza/base/panel_test.rb +16 -0
  116. data/lib/liza/meta/part.rb +19 -0
  117. data/lib/liza/meta/part_extension.rb +13 -0
  118. data/lib/liza/meta/part_test.rb +8 -0
  119. data/lib/liza/meta/system.rb +20 -0
  120. data/lib/liza/meta/system_test.rb +13 -0
  121. data/lib/liza/test/test.rb +11 -0
  122. data/lib/liza/test/test_test.rb +108 -0
  123. data/lib/liza/test_parts/test_assertions_part.rb +110 -0
  124. data/lib/liza/test_parts/test_context_part.rb +81 -0
  125. data/lib/liza/test_parts/test_dsl_part.rb +122 -0
  126. data/lib/liza/test_parts/test_subject_part.rb +24 -0
  127. data/lib/liza/unit.rb +149 -0
  128. data/lib/liza/unit_test.rb +79 -0
  129. data/lib/liza.rb +62 -0
  130. data/lib/lizarb/ruby/class.rb +17 -0
  131. data/lib/lizarb/ruby/proc.rb +12 -0
  132. data/lib/lizarb/ruby/string.rb +25 -0
  133. data/lib/lizarb/ruby/time.rb +9 -0
  134. data/lib/{viral → lizarb}/version.rb +2 -2
  135. data/lib/lizarb.rb +68 -0
  136. data/lib/net_system/dev/net_command.rb +24 -0
  137. data/lib/net_system/net/controllers/client/redis_client.rb +28 -0
  138. data/lib/net_system/net/controllers/client/redis_client_test.rb +29 -0
  139. data/lib/net_system/net/controllers/client/sqlite_client.rb +28 -0
  140. data/lib/net_system/net/controllers/client/sqlite_client_test.rb +29 -0
  141. data/lib/net_system/net/controllers/client.rb +5 -0
  142. data/lib/net_system/net/controllers/client_test.rb +14 -0
  143. data/lib/net_system/net/controllers/database/redis_db.rb +11 -0
  144. data/lib/net_system/net/controllers/database/redis_db_test.rb +23 -0
  145. data/lib/net_system/net/controllers/database/sqlite_db.rb +11 -0
  146. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +23 -0
  147. data/lib/net_system/net/controllers/database.rb +33 -0
  148. data/lib/net_system/net/controllers/database_test.rb +14 -0
  149. data/lib/net_system/net/controllers/model.rb +31 -0
  150. data/lib/net_system/net/controllers/model_test.rb +14 -0
  151. data/lib/net_system/net/net_box.rb +20 -0
  152. data/lib/net_system/net/net_box_test.rb +19 -0
  153. data/lib/net_system/net/panels/client_panel.rb +5 -0
  154. data/lib/net_system/net/panels/client_panel_test.rb +18 -0
  155. data/lib/net_system/net/panels/database_panel.rb +12 -0
  156. data/lib/net_system/net/panels/database_panel_test.rb +18 -0
  157. data/lib/net_system.rb +3 -0
  158. data/lib/web_system/dev/web_command.rb +42 -0
  159. data/lib/web_system/web/controllers/request/client_error_request.rb +18 -0
  160. data/lib/web_system/web/controllers/request/not_found_request.rb +18 -0
  161. data/lib/web_system/web/controllers/request/server_error_request.rb +20 -0
  162. data/lib/web_system/web/controllers/request.rb +5 -0
  163. data/lib/web_system/web/controllers/request_test.rb +18 -0
  164. data/lib/web_system/web/panels/request_panel.rb +55 -0
  165. data/lib/web_system/web/panels/request_panel_test.rb +14 -0
  166. data/lib/web_system/web/web_box.rb +12 -0
  167. data/lib/web_system/web/web_box_test.rb +18 -0
  168. data/lib/web_system.rb +5 -0
  169. data/lizarb.gemspec +44 -0
  170. data/sig/{viral.rbs → lizarb.rbs} +1 -1
  171. data/tmp/.gitkeep +0 -0
  172. data/web_files/favicon.ico +0 -0
  173. data/web_files/favicon.svg +948 -0
  174. metadata +226 -13
  175. data/viral.gemspec +0 -45
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "viral/version"
4
-
5
- module Viral
3
+ class HappySystem < Liza::System
6
4
  class Error < StandardError; end
7
5
  # Your code goes here...
6
+
7
+ #
8
+
9
+ set :log_color, :magenta
10
+
11
+ #
8
12
  end
@@ -0,0 +1,40 @@
1
+ module Liza
2
+ class Box < Unit
3
+ inherited_explicitly_sets_system
4
+
5
+ def self.has_panel symbol, panel_name = symbol
6
+ system_klass = get :system
7
+ panel_class = system_klass.const "#{symbol}_panel"
8
+
9
+ _has_panel_define panel_name, "get(:panels)[:#{panel_name}]"
10
+
11
+ panel = panel_class.new panel_name
12
+ add :panels, panel_name, panel
13
+
14
+ panel_class.on_connected self
15
+ end
16
+
17
+ def self.has_controller symbol, panel_name = symbol
18
+ system_klass = get :system
19
+ controller_class = system_klass.const symbol
20
+
21
+ panel = public_send panel_name
22
+
23
+ controller_class.on_connected self, panel
24
+ end
25
+
26
+ def self._has_panel_define name, resource
27
+ class_eval <<-CODE, __FILE__, __LINE__ + 1
28
+
29
+ def self.#{name} &block
30
+ if block_given?
31
+ #{resource}.instance_eval &block
32
+ else
33
+ #{resource}
34
+ end
35
+ end
36
+
37
+ CODE
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ module Liza
2
+ class BoxTest < UnitTest
3
+ test :subject_class do
4
+ assert subject_class == Liza::Box
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :white
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+ module Liza
2
+ class Controller < Unit
3
+ inherited_explicitly_sets_system
4
+
5
+ def self.on_connected box_klass, panel
6
+ set :box, box_klass
7
+ set :panel, panel
8
+ end
9
+
10
+ def self.box
11
+ get :box
12
+ end
13
+
14
+ def self.panel
15
+ get :panel
16
+ end
17
+
18
+ def box
19
+ self.class.box
20
+ end
21
+
22
+ def panel
23
+ self.class.panel
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ module Liza
2
+ class ControllerTest < UnitTest
3
+ test :subject_class do
4
+ assert subject_class == Liza::Controller
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :white
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ module Liza
2
+ class Panel < Unit
3
+ inherited_explicitly_sets_system
4
+
5
+ def self.on_connected box_klass
6
+ set :box, box_klass
7
+ end
8
+
9
+ def self.box
10
+ get :box
11
+ end
12
+
13
+ def box
14
+ self.class.box
15
+ end
16
+
17
+ def initialize name
18
+ @name = name
19
+ end
20
+
21
+ def log string
22
+ source = box.to_s
23
+
24
+ x = source.size
25
+
26
+ source = source.bold.colorize log_color
27
+
28
+ y = source.size
29
+
30
+ source = "#{source}.#{@name}".ljust(LOG_JUST+y-x)
31
+
32
+ string = "#{source} #{string}"
33
+
34
+ super string
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ module Liza
2
+ class PanelTest < UnitTest
3
+ test :subject_class do
4
+ assert subject_class == Liza::Panel
5
+ end
6
+
7
+ def subject
8
+ subject_class.new "name"
9
+ end
10
+
11
+ test :settings do
12
+ assert subject_class.log_level == :normal
13
+ assert subject_class.log_color == :white
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ module Liza
2
+ class Part < Unit
3
+ def self.insertion &block
4
+ if block_given?
5
+ @insertion = block
6
+ else
7
+ @insertion
8
+ end
9
+ end
10
+
11
+ def self.extension &block
12
+ if block_given?
13
+ @extension = block
14
+ else
15
+ @extension
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Liza
2
+ class PartExtension
3
+ def self.solder
4
+ @solder ||= Liza.const first_namespace
5
+ end
6
+
7
+ def initialize solder
8
+ @solder = solder
9
+ end
10
+
11
+ attr_reader :solder
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ module Liza
2
+ class PartTest < Test
3
+ test :subject_class do
4
+ assert subject_class == Liza::Part
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ module Liza
2
+ class System < Unit
3
+
4
+ def self.const name
5
+ const_get name.to_s.camelize
6
+ end
7
+
8
+ def self.insertion key, &block
9
+ if block_given?
10
+ registrar[:"insertion_#{key}"] = block
11
+ else
12
+ registrar[:"insertion_#{key}"]
13
+ end
14
+ end
15
+
16
+ def self.registrar
17
+ @registrar ||= {}
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module Liza
2
+ class SystemTest < UnitTest
3
+ test :subject_class do
4
+ assert subject_class == Liza::System
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :white
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module Liza
2
+ class Test < Unit
3
+
4
+ part :test_assertions
5
+ part :test_dsl
6
+ part :test_context
7
+ part :test_subject
8
+
9
+ end
10
+ end
11
+
@@ -0,0 +1,108 @@
1
+ module Liza
2
+ class TestTest < Test
3
+
4
+ test :settings do
5
+ assert subject_class.log_level == :normal
6
+ assert subject_class.log_color == :white
7
+ end
8
+
9
+ group :basics do
10
+ test :truths do
11
+ assert true
12
+ assert true
13
+ assert true
14
+ end
15
+
16
+ test :falsehoods do
17
+ refute false
18
+ refute false
19
+ refute false
20
+ end
21
+
22
+ test :assertions do
23
+ assert assertions == 0
24
+ refute assertions != 1
25
+ assert assertions == 2
26
+ end
27
+ end
28
+
29
+ test :instance_groups do
30
+ assert assertions == 0
31
+
32
+ group do
33
+ assert true
34
+ assert true
35
+ assert true
36
+ end
37
+
38
+ assert assertions == 2
39
+
40
+ group do
41
+ assert true
42
+ group do
43
+ assert true
44
+ end
45
+ assert true
46
+ end
47
+
48
+ assert assertions == 4
49
+ end
50
+
51
+ group do
52
+ before do
53
+ @a = true
54
+ assert @a
55
+ end
56
+
57
+ group do
58
+ before do
59
+ refute @b
60
+ @b = true
61
+ end
62
+
63
+ test :Test, :inner do
64
+ assert @a
65
+ assert @b
66
+ end
67
+ end
68
+
69
+ test :Test, :outer do
70
+ assert @a
71
+ refute @b
72
+ end
73
+
74
+ after do
75
+ assert @a
76
+ refute @b
77
+ end
78
+ end
79
+
80
+ # group :throwables do
81
+ # test :throw_within_test do
82
+ # assert! true
83
+ # assert! false
84
+ # raise "it should not have reached this line"
85
+ # end
86
+
87
+ # group :throw_within_before do
88
+ # before do
89
+ # assert! false
90
+ # end
91
+
92
+ # test :that_will_not_run do
93
+ # raise "it should not have reached this line"
94
+ # end
95
+ # end
96
+
97
+ # group :throw_within_after do
98
+ # test :that_will_not_run do
99
+ # assert! false
100
+ # end
101
+
102
+ # after do
103
+ # raise "it should not have reached this line"
104
+ # end
105
+ # end
106
+ # end
107
+ end
108
+ end
@@ -0,0 +1,110 @@
1
+ module Liza
2
+ class TestAssertionsPart < Part
3
+ insertion do
4
+ # CLASS
5
+
6
+ def self.totals
7
+ @totals ||= {
8
+ todos: [],
9
+ passes: [],
10
+ fails: [],
11
+ errors: [],
12
+ }
13
+ end
14
+
15
+ def self._assertion_todo msg
16
+ self.totals[:todos] << msg
17
+ end
18
+
19
+ def self._assertion_passed
20
+ self.totals[:passes] << 1
21
+ end
22
+
23
+ def self._assertion_failed msg
24
+ self.totals[:fails] << msg
25
+ end
26
+
27
+ def self._assertion_errored e
28
+ self.totals[:errors] << e
29
+ end
30
+
31
+ # INSTANCE
32
+
33
+ attr_writer :assertions
34
+
35
+ def assertions
36
+ @assertions ||= 0
37
+ end
38
+
39
+ def _inc_assertions
40
+ self.assertions += 1
41
+ end
42
+
43
+ # ASSERTIONS
44
+
45
+ def todo msg
46
+ self.class._assertion_todo msg
47
+ @last_result = :todo
48
+
49
+ _assertion_log __method__, caller if _groups.empty?
50
+ end
51
+
52
+ def _groups
53
+ @_groups ||= []
54
+ end
55
+
56
+ def group kaller: nil, **_words, &block
57
+ block_given? || raise(ArgumentError, "No block given")
58
+
59
+ _groups << block
60
+ instance_exec &block
61
+ _groups.pop
62
+
63
+ kaller ||= caller
64
+ _assertion_log __method__, kaller if _groups.empty?
65
+ end
66
+
67
+ def assert b, msg = "it should have been true", kaller: nil
68
+ if b
69
+ self.class._assertion_passed
70
+ @last_result = :passed
71
+ else
72
+ self.class._assertion_failed msg
73
+ @last_result = :failed
74
+ end
75
+
76
+ kaller ||= caller
77
+ _assertion_log __method__, kaller if _groups.empty?
78
+
79
+ b
80
+ end
81
+
82
+ def refute b, msg = "it should have been false", kaller: nil
83
+ if b
84
+ self.class._assertion_failed msg
85
+ @last_result = :failed
86
+ else
87
+ self.class._assertion_passed
88
+ @last_result = :passed
89
+ end
90
+
91
+ kaller ||= caller
92
+ _assertion_log __method__, kaller if _groups.empty?
93
+
94
+ b
95
+ end
96
+
97
+ def assert! b, msg = "it should have been true"
98
+ critical assert b, msg, kaller: caller
99
+ end
100
+
101
+ def refute! b, msg = "it should have been false"
102
+ critical refute b, msg, kaller: caller
103
+ end
104
+
105
+ def critical passed
106
+ throw :critical, :critical if not passed
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,81 @@
1
+ module Liza
2
+ class TestContextPart < Part
3
+
4
+ insertion do
5
+ def self.context
6
+ @context ||= Liza::TestContextPart::Extension.new self
7
+ end
8
+
9
+ def self.before &block
10
+ block_given? || raise(ArgumentError, "No block given")
11
+
12
+ context.add_before block
13
+ end
14
+
15
+ def self.after &block
16
+ block_given? || raise(ArgumentError, "No block given")
17
+
18
+ context.add_after block
19
+ end
20
+
21
+ def self.group *_words, &block
22
+ block_given? || raise(ArgumentError, "No block given")
23
+
24
+ context.open_group
25
+ instance_exec &block
26
+ context.close_group
27
+ end
28
+ end
29
+
30
+ extension do
31
+ # group
32
+
33
+ def open_group
34
+ befores.push befores.last.dup
35
+ afters.push afters.last.dup
36
+ end
37
+
38
+ def close_group
39
+ befores.pop
40
+ afters.pop
41
+ end
42
+
43
+ # before
44
+
45
+ def befores
46
+ @befores ||= _befores_from_superclass + [[]]
47
+ end
48
+
49
+ def add_before block
50
+ befores.last.push block
51
+ end
52
+
53
+ def _befores_from_superclass
54
+ if solder.superclass.respond_to? :context
55
+ solder.superclass.context.befores.dup
56
+ else
57
+ []
58
+ end
59
+ end
60
+
61
+ # after
62
+
63
+ def afters
64
+ @afters ||= _afters_from_superclass + [[]]
65
+ end
66
+
67
+ def add_after block
68
+ afters.last.push block
69
+ end
70
+
71
+ def _afters_from_superclass
72
+ if solder.superclass.respond_to? :context
73
+ solder.superclass.context.afters.dup
74
+ else
75
+ []
76
+ end
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,122 @@
1
+ module Liza
2
+ class TestDslPart < Part
3
+ insertion do
4
+ def self.test *words, &block
5
+ Liza.log "#{inspect}.test #{words}, &block"
6
+ block_given? || raise(ArgumentError, "No block given")
7
+
8
+ key = [
9
+ block.source_location,
10
+ 'b',
11
+ context.befores.flatten.map(&:source_location),
12
+ 'a',
13
+ context.afters.flatten.map(&:source_location),
14
+ ].flatten.join("-")
15
+
16
+ key.gsub! Lizarb::CUR_DIR, ""
17
+
18
+ instances[key] ||= new words,
19
+ context.befores.flatten.uniq,
20
+ context.afters.flatten.uniq,
21
+ &block
22
+ end
23
+
24
+ def self.instances
25
+ @instances ||= {}
26
+ end
27
+
28
+ def self.call class_index, class_count
29
+ counter_class = "#{class_index.to_s.rjust 3, "0"}/#{class_count.to_s.rjust 3, "0"}"
30
+
31
+ puts "- #{counter_class} #{self} (#{instances.size} tests)".cyan
32
+
33
+ instances.values.each_with_index do |instance, i|
34
+ counter_instance = "#{(i+=1).to_s.rjust 2, '0'}/#{instances.size.to_s.rjust 2, '0'}"
35
+ label = instance.words_as_label
36
+
37
+ puts " #{ counter_class } #{ counter_instance } (#{ label })".light_cyan
38
+
39
+ instance.call
40
+ end
41
+ end
42
+
43
+ #
44
+
45
+ attr_reader :words
46
+
47
+ def initialize words, befores, afters, &block
48
+ @words, @befores, @afters, @block = words, befores, afters, block
49
+ end
50
+
51
+ def call
52
+ catch :critical do
53
+ @befores.each do |bl|
54
+ _call_log "B&", &bl
55
+ instance_exec &bl
56
+ end
57
+
58
+ bl = @block
59
+ _call_log " &", &bl
60
+ instance_exec &bl
61
+
62
+ @afters.each do |bl|
63
+ _call_log "A&", &bl
64
+ instance_exec &bl
65
+ end
66
+ end
67
+ rescue Exception => e
68
+ self.class._assertion_errored e
69
+ _rescue_log e
70
+ ensure
71
+ puts
72
+ end
73
+
74
+ def words_as_label
75
+ label = words.to_s
76
+ label = label[1..-2] if label.start_with? "["
77
+ label = label[1..-2] if label.start_with? "{"
78
+ label
79
+ end
80
+
81
+ def _rescue_log e
82
+ prefix = "error"
83
+
84
+ kaller = e.backtrace
85
+
86
+ source_location = _caller_line_split(kaller[0])[0]
87
+ source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
88
+
89
+ log " #{prefix} #{source_location}"
90
+
91
+ puts "Exception!".red
92
+ puts e.class.to_s.red
93
+ puts e.message.red
94
+ puts
95
+ puts e.backtrace.join("\n").red
96
+ end
97
+
98
+ def _call_log prefix, &block
99
+ source_location = block.source_location.join(":").gsub("#{Lizarb::CUR_DIR}/", "")
100
+ source_location = source_location[0..-1]
101
+ log " #{prefix} #{source_location}"
102
+ end
103
+
104
+ def _assertion_log method_name, kaller
105
+ _inc_assertions
106
+ method_name = method_name.to_s.ljust 6
107
+ prefix = "#{assertions} #{method_name} #{@last_result}"
108
+
109
+ source_location = _caller_line_split(kaller[0])[0]
110
+ source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
111
+
112
+ log " #{prefix} #{source_location}"
113
+ end
114
+
115
+ def _caller_line_split s
116
+ x = s.split ":in `"
117
+ x[1] = x[1][0..-2]
118
+ x
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,24 @@
1
+ module Liza
2
+ class TestSubjectPart < Part
3
+
4
+ insertion do
5
+ def self.subject_class
6
+ @subject_class ||=
7
+ if first_namespace == "Liza"
8
+ Liza.const_get last_namespace[0..-5]
9
+ else
10
+ Object.const_get name[0..-5]
11
+ end
12
+ end
13
+
14
+ def subject_class
15
+ self.class.subject_class
16
+ end
17
+
18
+ def subject
19
+ @subject ||= subject_class.new
20
+ end
21
+ end
22
+
23
+ end
24
+ end