lizarb 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.tool-versions +1 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +14 -3
  6. data/README.md +23 -64
  7. data/README_SYSTEMS.md +80 -0
  8. data/Rakefile +3 -1
  9. data/app/dev/benches/app_bench.rb +5 -0
  10. data/app/dev/benches/app_bench_test.rb +7 -0
  11. data/app/dev/benches/loops_bench.rb +183 -0
  12. data/app/dev/benches/loops_bench_test.rb +11 -0
  13. data/app/dev/commands/calculator_command.rb +69 -0
  14. data/app/dev/commands/calculator_command_test.rb +58 -0
  15. data/app/dev/commands/circle_command.rb +70 -0
  16. data/app/dev/commands/circle_command_test.rb +76 -0
  17. data/app/dev/commands/narrative_method_command.rb +60 -0
  18. data/app/dev/commands/narrative_method_command_test.rb +36 -0
  19. data/app/dev/commands/new_command.rb +1 -61
  20. data/app/dev/commands/quadratic_command.rb +66 -0
  21. data/app/dev/commands/quadratic_command_test.rb +47 -0
  22. data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
  23. data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
  24. data/app/dev/generators/bench_generator.rb +18 -0
  25. data/app/dev/generators/bench_generator_test.rb +12 -0
  26. data/app/dev/generators/command_generator/command.rb.erb +26 -0
  27. data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
  28. data/app/dev/generators/command_generator.rb +18 -0
  29. data/app/dev/generators/command_generator_test.rb +12 -0
  30. data/app/dev/generators/record_generator.rb +46 -0
  31. data/app/dev/generators/record_generator_test.rb +12 -0
  32. data/app/dev/generators/request_generator.rb +63 -0
  33. data/app/dev/generators/request_generator_test.rb +12 -0
  34. data/app/net/databases/redis_db_test.rb +2 -2
  35. data/app/net/databases/sqlite_db_test.rb +2 -2
  36. data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
  37. data/app/net/{models/post_model_test.rb → records/app_record_test.rb} +2 -2
  38. data/app/net/records/post_record.rb +4 -0
  39. data/app/net/{models/app_model_test.rb → records/post_record_test.rb} +2 -2
  40. data/app/net/records/user_record.rb +4 -0
  41. data/app/net/{models/user_model_test.rb → records/user_record_test.rb} +2 -2
  42. data/app/net_box.rb +2 -2
  43. data/app/web/requests/api_request.rb +8 -7
  44. data/app/web/requests/assets_request.rb +12 -13
  45. data/app/web/requests/root_request.rb +6 -7
  46. data/app/web/requests/root_request_test.rb +1 -1
  47. data/app/web_box.rb +8 -0
  48. data/app_new/Procfile +1 -1
  49. data/exe/lrb +3 -0
  50. data/lib/app.rb +18 -14
  51. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +29 -0
  52. data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +14 -0
  53. data/lib/dev_system/dev/controllers/bench.rb +11 -0
  54. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
  55. data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench_test.rb} +2 -2
  56. data/lib/dev_system/dev/controllers/command/bench_command.rb +34 -0
  57. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
  58. data/lib/dev_system/dev/controllers/command/generate_command.rb +35 -0
  59. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
  60. data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -0
  61. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +14 -0
  62. data/lib/dev_system/dev/controllers/command/terminal_command.rb +24 -0
  63. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +14 -0
  64. data/lib/dev_system/dev/controllers/command/test_command.rb +6 -2
  65. data/lib/dev_system/dev/controllers/generator.rb +11 -0
  66. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
  67. data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
  68. data/lib/dev_system/dev/controllers/generators/app_generator.rb +96 -0
  69. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
  70. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  71. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  72. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  73. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  74. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  75. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  76. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +29 -0
  77. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +14 -0
  78. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  79. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  80. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  81. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  82. data/lib/dev_system/dev/controllers/shell/file_shell.rb +59 -0
  83. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +150 -0
  84. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  85. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  86. data/lib/dev_system/dev/controllers/shell.rb +31 -0
  87. data/lib/dev_system/dev/controllers/shell_test.rb +46 -0
  88. data/lib/dev_system/dev/controllers/{command/dev_command.rb → terminal/irb_terminal.rb} +2 -2
  89. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
  90. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
  91. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
  92. data/lib/dev_system/dev/controllers/terminal.rb +19 -0
  93. data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
  94. data/lib/dev_system/dev/dev_box.rb +3 -0
  95. data/lib/dev_system/dev/panels/command_panel.rb +21 -1
  96. data/lib/dev_system/dev/panels/log_panel.rb +1 -1
  97. data/lib/lerb.rb +106 -0
  98. data/lib/liza/base/controller.rb +2 -0
  99. data/lib/liza/base/panel.rb +6 -5
  100. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  101. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  102. data/lib/liza/meta/part_extension.rb +6 -1
  103. data/lib/liza/ruby_test.rb +9 -0
  104. data/lib/liza/ruby_tests/module_test.rb +21 -0
  105. data/lib/liza/ruby_tests/string_test.rb +59 -0
  106. data/lib/liza/test/test.rb +3 -1
  107. data/lib/liza/test/test_test.rb +108 -15
  108. data/lib/liza/test_parts/test_assertions_advanced_part.rb +127 -0
  109. data/lib/liza/test_parts/test_assertions_part.rb +7 -6
  110. data/lib/liza/test_parts/test_dsl_part.rb +37 -89
  111. data/lib/liza/test_parts/test_log_part.rb +124 -0
  112. data/lib/liza/test_parts/test_subject_part.rb +6 -1
  113. data/lib/liza/test_parts/test_tree_part.rb +139 -0
  114. data/lib/liza/unit.rb +2 -0
  115. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  116. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  117. data/lib/liza.rb +40 -7
  118. data/lib/lizarb/ruby/class.rb +2 -0
  119. data/lib/lizarb/ruby/module.rb +17 -0
  120. data/lib/lizarb/ruby/proc.rb +12 -0
  121. data/lib/lizarb/ruby/string.rb +26 -2
  122. data/lib/lizarb/version.rb +1 -1
  123. data/lib/lizarb.rb +24 -2
  124. data/lib/net_system/net/controllers/{adapter/redis_adapter.rb → client/redis_client.rb} +2 -2
  125. data/lib/net_system/net/controllers/{adapter/redis_adapter_test.rb → client/redis_client_test.rb} +2 -2
  126. data/lib/net_system/net/controllers/{adapter/sqlite_adapter.rb → client/sqlite_client.rb} +2 -2
  127. data/lib/net_system/net/controllers/{adapter/sqlite_adapter_test.rb → client/sqlite_client_test.rb} +2 -2
  128. data/lib/net_system/net/controllers/client.rb +5 -0
  129. data/lib/net_system/net/controllers/{model_test.rb → client_test.rb} +2 -2
  130. data/lib/net_system/net/controllers/database/redis_db.rb +2 -2
  131. data/lib/net_system/net/controllers/database/redis_db_test.rb +1 -1
  132. data/lib/net_system/net/controllers/database/sqlite_db.rb +2 -2
  133. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +1 -1
  134. data/lib/net_system/net/controllers/database.rb +6 -6
  135. data/lib/net_system/net/controllers/record.rb +31 -0
  136. data/lib/net_system/net/controllers/{adapter_test.rb → record_test.rb} +2 -2
  137. data/lib/net_system/net/net_box.rb +5 -5
  138. data/lib/net_system/net/net_box_test.rb +1 -1
  139. data/lib/net_system/net/panels/client_panel.rb +5 -0
  140. data/lib/net_system/net/panels/{adapter_panel_test.rb → client_panel_test.rb} +2 -2
  141. data/lib/web_system/dev/rack_command.rb +26 -0
  142. data/lib/web_system/dev/request_command.rb +143 -0
  143. data/lib/web_system/dev/web_command.rb +3 -34
  144. data/lib/web_system/web/controllers/rack.rb +8 -0
  145. data/lib/web_system/web/controllers/rack_test.rb +18 -0
  146. data/lib/web_system/web/controllers/request/client_error_request.rb +0 -1
  147. data/lib/web_system/web/controllers/request/not_found_request.rb +0 -1
  148. data/lib/web_system/web/controllers/request/server_error_request.rb +0 -1
  149. data/lib/web_system/web/panels/rack_panel.rb +44 -0
  150. data/lib/web_system/web/panels/rack_panel_test.rb +14 -0
  151. data/lib/web_system/web/panels/request_panel.rb +51 -32
  152. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  153. data/lib/web_system/web/web_box.rb +12 -0
  154. data/lizarb.gemspec +2 -2
  155. data/tmp/.gitkeep +0 -0
  156. metadata +110 -31
  157. data/app/dev/commands/example_command.rb +0 -57
  158. data/app/dev/commands/example_command_test.rb +0 -43
  159. data/app/dev/commands/macro_child_command.rb +0 -32
  160. data/app/dev/commands/macro_child_command_test.rb +0 -7
  161. data/app/dev/commands/macro_parent_command.rb +0 -70
  162. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  163. data/app/dev/commands/my_command.rb +0 -7
  164. data/app/dev/commands/my_command_test.rb +0 -7
  165. data/app/net/models/post_model.rb +0 -4
  166. data/app/net/models/user_model.rb +0 -4
  167. data/lib/liza/test_parts/test_context_part.rb +0 -81
  168. data/lib/net_system/net/controllers/adapter.rb +0 -5
  169. data/lib/net_system/net/controllers/model.rb +0 -31
  170. data/lib/net_system/net/panels/adapter_panel.rb +0 -5
@@ -0,0 +1,140 @@
1
+ class Liza::ControllerRendererPart < Liza::Part
2
+
3
+ class Error < Liza::Error; end
4
+ class RendererNotFound < Error; end
5
+ class EmptyRenderStack < Error; end
6
+
7
+ EMPTY_RENDER_STACK_MESSAGE = <<~STRING
8
+ You called render without ERB keys,
9
+ but the render stack is empty.
10
+ Did you forget to add ERB keys?
11
+ STRING
12
+
13
+ insertion do
14
+ # EXTENSION
15
+
16
+ def self.renderer
17
+ Liza::ControllerRendererPart::Extension
18
+ end
19
+
20
+ def renderer
21
+ @renderer ||= self.class.renderer.new self
22
+ end
23
+
24
+ # CLASS
25
+
26
+ def self.controller_ancestors
27
+ ancestors.take_while { |k| k != Liza::Controller }
28
+ end
29
+
30
+ def self.render_paths
31
+ @render_paths ||= controller_ancestors.map &:source_location_radical
32
+ end
33
+
34
+ def render_paths
35
+ self.class.render_paths
36
+ end
37
+
38
+ def self.renderers
39
+ @renderers ||=
40
+ LERB.load(source_location_radical)
41
+ .map { |lerb| [lerb.key, lerb] }
42
+ .to_h
43
+ end
44
+
45
+ # INSTANCE
46
+
47
+ def render *keys
48
+ if keys.any?
49
+ _log_render_in keys
50
+ renderer.render keys, binding, self
51
+ elsif renderer.stack.any?
52
+ renderer.stack.pop
53
+ else
54
+ raise EmptyRenderStack, EMPTY_RENDER_STACK_MESSAGE, caller
55
+ end
56
+ end
57
+
58
+ def _log_render_in keys
59
+ if renderer.stack.any?
60
+ log "render ↓ #{keys.join ", "}"
61
+ else
62
+ log "render #{"→ " * keys.size}#{keys.join ", "}"
63
+ end
64
+ end
65
+ end
66
+
67
+ extension do
68
+ # CLASS
69
+
70
+ def self.log(...)
71
+ solder.log(...)
72
+ end
73
+
74
+ # INSTANCE
75
+
76
+ def log(...)
77
+ self.class.log(...)
78
+ end
79
+
80
+ def erb_lists
81
+ @erb_lists ||= []
82
+ end
83
+
84
+ def stack
85
+ @stack ||= []
86
+ end
87
+
88
+ def render keys, the_binding, receiver
89
+ erbs = find_erbs_for(keys).to_a
90
+
91
+ erbs.reverse.each do |key, erb|
92
+ t = Time.now
93
+ s = erb.result the_binding, receiver
94
+ _log_render_out key, s.length, t.diff
95
+ s = wrap_comment_tags s, erb if App.mode == :code && erb.tags?
96
+ stack.push s.strip
97
+ end
98
+
99
+ stack.pop
100
+ end
101
+
102
+ def find_erbs_for keys
103
+ ret = {}
104
+ keys.each do |key|
105
+ key = "#{key}.erb"
106
+
107
+ controller = solder.class.controller_ancestors.
108
+ find { |controller| controller.renderers.has_key? key }
109
+
110
+ if controller
111
+ ret[key] = controller.renderers[key]
112
+ else
113
+ raise_renderer_not_found key
114
+ end
115
+ end
116
+
117
+ ret
118
+ end
119
+
120
+ def raise_renderer_not_found key
121
+ render_paths = solder.render_paths.map { |s| " #{s}/#{"#{key}".red}" }.join
122
+ raise RendererNotFound, %|Failed to find ERB #{key}
123
+ Failed to find ERB #{"#{key}".red} in #{solder.class}.render_paths
124
+ #{render_paths}|
125
+ end
126
+
127
+ def _log_render_out key, length, t
128
+ if stack.any?
129
+ log "render #{"↑ #{key}".ljust_blanks 20} with #{length.to_s.rjust_blanks 4} characters in #{t}s"
130
+ else
131
+ log "render #{"← #{key}".ljust_blanks 20} with #{length.to_s.rjust_blanks 4} characters in #{t}s"
132
+ end
133
+ end
134
+
135
+ def wrap_comment_tags s, erb
136
+ "<!-- #{erb.filename.split("/").last}:#{erb.lineno} -->\n#{s}\n<!-- #{erb.filename.split("/").last} -->"
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,16 @@
1
+ class Liza::ControllerRendererPartTest < Liza::Test
2
+
3
+ test :subject_class do
4
+ assert subject_class == Liza::ControllerRendererPart
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.get(:log_level) == :normal
9
+ assert subject_class.get(:log_color) == :white
10
+ assert subject_class.log_level == :normal
11
+ assert subject_class.log_color == :white
12
+
13
+ assert subject_class.settings == {}
14
+ end
15
+
16
+ end
@@ -1,7 +1,12 @@
1
1
  module Liza
2
2
  class PartExtension
3
3
  def self.solder
4
- @solder ||= Liza.const first_namespace
4
+ @solder ||=
5
+ if first_namespace == "Liza"
6
+ Liza.const_get last_namespace[0..-12]
7
+ else
8
+ Object.const_get name[0..-12]
9
+ end
5
10
  end
6
11
 
7
12
  def initialize solder
@@ -0,0 +1,9 @@
1
+ module Liza
2
+ class RubyTest < Test
3
+
4
+ def self.subject_class
5
+ @subject_class ||= Object.const_get last_namespace[0..-5]
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ class Liza::ModuleTest < Liza::RubyTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == Module
5
+ end
6
+
7
+ test :source_location do
8
+ assert Object.source_location == []
9
+
10
+ assert Liza::Command.source_location[1] == 2
11
+ assert AppCommand.source_location[1] == 1
12
+ end
13
+
14
+ test :source_location_radical do
15
+ assert Object.source_location_radical == nil
16
+
17
+ assert Liza::Command.source_location_radical.end_with? "/lib/dev_system/dev/controllers/command"
18
+ assert AppCommand.source_location_radical.end_with? "/app/dev/commands/app_command"
19
+ end
20
+
21
+ end
@@ -0,0 +1,59 @@
1
+ class Liza::StringTest < Liza::RubyTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == String
5
+ end
6
+
7
+ test :initializers do
8
+ s0 = String.new
9
+ s1 = ''
10
+ s2 = ""
11
+
12
+ assert s0.class == String
13
+ assert s1.class == String
14
+ assert s2.class == String
15
+ end
16
+
17
+ test :lpartition do
18
+ todo "write examples"
19
+ end
20
+
21
+ test :rpartition do
22
+ todo "write examples"
23
+ end
24
+
25
+ test :camelcase do
26
+ assert "" == "".camelcase
27
+ assert "A" == "a".camelcase
28
+ assert "Ab" == "ab".camelcase
29
+ assert "AbC" == "ab_c".camelcase
30
+ assert "AbCd" == "ab_cd".camelcase
31
+ assert "Ab" == "ab_".camelcase
32
+ assert "Cd" == "_cd".camelcase
33
+ end
34
+
35
+ test :snakecase do
36
+ assert "" == "".snakecase
37
+ assert "a" == "A".snakecase
38
+ assert "ab" == "Ab".snakecase
39
+ assert "ab_c" == "AbC".snakecase
40
+ assert "ab_cd" == "AbCd".snakecase
41
+ end
42
+
43
+ test :rjust_blanks do
44
+ todo "write examples"
45
+ end
46
+
47
+ test :rjust_zeroes do
48
+ todo "write examples"
49
+ end
50
+
51
+ test :ljust_blanks do
52
+ todo "write examples"
53
+ end
54
+
55
+ test :ljust_zeroes do
56
+ todo "write examples"
57
+ end
58
+
59
+ end
@@ -2,9 +2,11 @@ module Liza
2
2
  class Test < Unit
3
3
 
4
4
  part :test_assertions
5
+ part :test_assertions_advanced
5
6
  part :test_dsl
6
- part :test_context
7
+ part :test_log
7
8
  part :test_subject
9
+ part :test_tree
8
10
 
9
11
  end
10
12
  end
@@ -26,6 +26,74 @@ module Liza
26
26
  end
27
27
  end
28
28
 
29
+ group :assertions do
30
+ test :assert do
31
+ assert 0
32
+ assert 1
33
+ assert :a
34
+ assert "a"
35
+ assert ""
36
+ assert []
37
+ assert [1]
38
+ assert({})
39
+ assert({a: 1})
40
+ assert true
41
+ refute false
42
+ refute nil
43
+ end
44
+
45
+ test :assert_equality do
46
+ assert_equality 0, 0
47
+ assert_equality 1, 1
48
+ assert_equality :a, :a
49
+ assert_equality "a", "a"
50
+ assert_equality "", ""
51
+ assert_equality [], []
52
+ assert_equality [1], [1]
53
+ assert_equality({}, {})
54
+ assert_equality({a: 1}, {a: 1})
55
+ assert_equality true, true
56
+ refute_equality false, true
57
+ refute_equality nil, true
58
+ end
59
+
60
+ test :assert_raises do
61
+ assert_raises StandardError do
62
+ raise RuntimeError
63
+ end
64
+
65
+ assert_raises RuntimeError do
66
+ raise RuntimeError
67
+ end
68
+
69
+ refute_raises RuntimeError do
70
+ raise StandardError
71
+ end
72
+ end
73
+ end
74
+
75
+ group :instance_variables do
76
+ test :instance_variables do
77
+ assert_equality instance_variables, [:@test_words, :@before_stack, :@after_stack, :@test_block]
78
+ end
79
+
80
+ test :test_block do
81
+ assert_equality @test_block.source_location[1], __LINE__ - 1
82
+ end
83
+ end
84
+
85
+ group :tree do
86
+ test :test_tree do
87
+ assert_equality self.class.test_tree.class, Liza::TestTreePart::Extension
88
+ assert_equality self.class.test_tree, self.class.test_tree.parent
89
+
90
+ assert_equality 2, self.class.test_tree.tests.count
91
+ assert_equality 5, self.class.test_tree.children.count
92
+
93
+ assert_equality self.class.test_tree.tests.map(&:first).flatten, [:settings, :instance_groups]
94
+ end
95
+ end
96
+
29
97
  test :instance_groups do
30
98
  assert assertions == 0
31
99
 
@@ -48,32 +116,57 @@ module Liza
48
116
  assert assertions == 4
49
117
  end
50
118
 
51
- group do
119
+ group :class_groups do
52
120
  before do
53
- @a = true
54
- assert @a
121
+ @string = "START"
122
+ assert_equality @string, "START"
55
123
  end
56
124
 
57
- group do
125
+ test :class_groups, :outer_a do
126
+ @string.concat "-123"
127
+ assert_equality @string, "START-123"
128
+ #
129
+ @expectation_outer = "START-123-FINISH"
130
+ end
131
+
132
+ test :class_groups, :outer_b do
133
+ @string.concat "-321"
134
+ assert_equality @string, "START-321"
135
+ #
136
+ @expectation_outer = "START-321-FINISH"
137
+ end
138
+
139
+ group :class_groups_inner do
58
140
  before do
59
- refute @b
60
- @b = true
141
+ @string.concat "-BEGIN"
142
+ assert_equality @string, "START-BEGIN"
61
143
  end
62
144
 
63
- test :Test, :inner do
64
- assert @a
65
- assert @b
145
+ test :class_groups, :inner_a do
146
+ @string.concat "-aaa"
147
+ assert_equality @string, "START-BEGIN-aaa"
148
+ #
149
+ @expectation_inner = "START-BEGIN-aaa-END"
150
+ @expectation_outer = "START-BEGIN-aaa-END-FINISH"
66
151
  end
67
- end
68
152
 
69
- test :Test, :outer do
70
- assert @a
71
- refute @b
153
+ test :class_groups, :inner_b do
154
+ @string.concat "-bbb"
155
+ assert_equality @string, "START-BEGIN-bbb"
156
+ #
157
+ @expectation_inner = "START-BEGIN-bbb-END"
158
+ @expectation_outer = "START-BEGIN-bbb-END-FINISH"
159
+ end
160
+
161
+ after do
162
+ @string.concat "-END"
163
+ assert_equality @string, @expectation_inner
164
+ end
72
165
  end
73
166
 
74
167
  after do
75
- assert @a
76
- refute @b
168
+ @string << "-FINISH"
169
+ assert_equality @string, @expectation_outer
77
170
  end
78
171
  end
79
172
 
@@ -0,0 +1,127 @@
1
+ module Liza
2
+ class TestAssertionsAdvancedPart < Part
3
+ insertion do
4
+
5
+ def assert_equality a, b, msg = nil, kaller: nil
6
+ ret = a == b
7
+
8
+ if ret
9
+ self.class._assertion_passed
10
+ @last_result = :passed
11
+ else
12
+ self.class._assertion_failed msg
13
+ @last_result = :failed
14
+ end
15
+
16
+ kaller ||= caller
17
+ log_test_assertion __method__, kaller if _groups.empty?
18
+
19
+ if log_test_assertion_message?
20
+ msg ||= "#{__method__} #{a}, #{b} (== equality)"
21
+ log_test_assertion_message ret, msg
22
+ end
23
+
24
+ ret
25
+ end
26
+
27
+ def refute_equality a, b, msg = nil, kaller: nil
28
+ ret = a == b
29
+
30
+ if ret
31
+ self.class._assertion_failed msg
32
+ @last_result = :failed
33
+ else
34
+ self.class._assertion_passed
35
+ @last_result = :passed
36
+ end
37
+
38
+ kaller ||= caller
39
+ log_test_assertion __method__, kaller if _groups.empty?
40
+
41
+ if log_test_assertion_message?
42
+ msg ||= "#{__method__} #{a}, #{b} (== equality)"
43
+ log_test_assertion_message !ret, msg
44
+ end
45
+
46
+ ret
47
+ end
48
+
49
+ def assert_equality! a, b, msg = nil
50
+ critical assert_equality a, b, msg, kaller: caller
51
+ end
52
+
53
+ def refute_equality! a, b, msg = nil
54
+ critical refute_equality a, b, msg, kaller: caller
55
+ end
56
+
57
+ def assert_raises exception_klass, msg = nil, kaller: nil, &block
58
+ raise ArgumentError, "No block given" unless block_given?
59
+
60
+ ret = false
61
+ begin
62
+ yield
63
+ rescue => e
64
+ ret = exception_klass === e
65
+ error = e
66
+ end
67
+
68
+ if ret
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
+ log_test_assertion __method__, kaller if _groups.empty?
78
+
79
+ if log_test_assertion_message?
80
+ msg ||= "#{__method__} (#{exception_klass}) #{error.inspect}"
81
+ log_test_assertion_message ret, msg
82
+ end
83
+
84
+ ret
85
+ end
86
+
87
+ def refute_raises exception_klass, msg = nil, kaller: nil, &block
88
+ raise ArgumentError, "No block given" unless block_given?
89
+
90
+ ret = false
91
+ begin
92
+ yield
93
+ rescue => e
94
+ ret = !exception_klass === e
95
+ error = e
96
+ end
97
+
98
+ if ret
99
+ self.class._assertion_failed msg
100
+ @last_result = :failed
101
+ else
102
+ self.class._assertion_passed
103
+ @last_result = :passed
104
+ end
105
+
106
+ kaller ||= caller
107
+ log_test_assertion __method__, kaller if _groups.empty?
108
+
109
+ if log_test_assertion_message?
110
+ msg ||= "#{__method__} (#{exception_klass}) #{error.inspect}"
111
+ log_test_assertion_message !ret, msg
112
+ end
113
+
114
+ ret
115
+ end
116
+
117
+ def assert_raises! e, msg = nil
118
+ critical assert_raises e, msg, kaller: caller
119
+ end
120
+
121
+ def refute_raises! e, msg = nil
122
+ critical refute_raises e, msg, kaller: caller
123
+ end
124
+
125
+ end
126
+ end
127
+ end
@@ -5,10 +5,10 @@ module Liza
5
5
 
6
6
  def self.totals
7
7
  @totals ||= {
8
+ errors: [],
8
9
  todos: [],
9
- passes: [],
10
10
  fails: [],
11
- errors: [],
11
+ passes: [],
12
12
  }
13
13
  end
14
14
 
@@ -46,7 +46,7 @@ module Liza
46
46
  self.class._assertion_todo msg
47
47
  @last_result = :todo
48
48
 
49
- _assertion_log __method__, caller if _groups.empty?
49
+ log_test_assertion __method__, caller if _groups.empty?
50
50
  end
51
51
 
52
52
  def _groups
@@ -61,7 +61,7 @@ module Liza
61
61
  _groups.pop
62
62
 
63
63
  kaller ||= caller
64
- _assertion_log __method__, kaller if _groups.empty?
64
+ log_test_assertion __method__, kaller if _groups.empty?
65
65
  end
66
66
 
67
67
  def assert b, msg = "it should have been true", kaller: nil
@@ -74,7 +74,7 @@ module Liza
74
74
  end
75
75
 
76
76
  kaller ||= caller
77
- _assertion_log __method__, kaller if _groups.empty?
77
+ log_test_assertion __method__, kaller if _groups.empty?
78
78
 
79
79
  b
80
80
  end
@@ -89,7 +89,7 @@ module Liza
89
89
  end
90
90
 
91
91
  kaller ||= caller
92
- _assertion_log __method__, kaller if _groups.empty?
92
+ log_test_assertion __method__, kaller if _groups.empty?
93
93
 
94
94
  b
95
95
  end
@@ -105,6 +105,7 @@ module Liza
105
105
  def critical passed
106
106
  throw :critical, :critical if not passed
107
107
  end
108
+
108
109
  end
109
110
  end
110
111
  end