lizarb 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.tool-versions +1 -0
  4. data/Gemfile +1 -0
  5. data/Gemfile.lock +7 -4
  6. data/README.md +23 -64
  7. data/README_SYSTEMS.md +80 -0
  8. data/Rakefile +3 -1
  9. data/app/dev/benches/loops_bench.rb +35 -0
  10. data/app/dev/commands/calculator_command.rb +69 -0
  11. data/app/dev/commands/calculator_command_test.rb +58 -0
  12. data/app/dev/commands/circle_command.rb +70 -0
  13. data/app/dev/commands/circle_command_test.rb +76 -0
  14. data/app/dev/commands/narrative_method_command.rb +60 -0
  15. data/app/dev/commands/narrative_method_command_test.rb +36 -0
  16. data/app/dev/commands/quadratic_command.rb +66 -0
  17. data/app/dev/commands/quadratic_command_test.rb +47 -0
  18. data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
  19. data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
  20. data/app/dev/generators/bench_generator.rb +2 -51
  21. data/app/dev/generators/command_generator/command.rb.erb +26 -0
  22. data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
  23. data/app/dev/generators/command_generator.rb +2 -35
  24. data/app/dev/generators/record_generator.rb +46 -0
  25. data/app/dev/generators/{model_generator_test.rb → record_generator_test.rb} +2 -2
  26. data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
  27. data/app/net/{models/post_model_test.rb → records/app_record_test.rb} +2 -2
  28. data/app/net/records/post_record.rb +4 -0
  29. data/app/net/{models/app_model_test.rb → records/post_record_test.rb} +2 -2
  30. data/app/net/records/user_record.rb +4 -0
  31. data/app/net/{models/user_model_test.rb → records/user_record_test.rb} +2 -2
  32. data/app/web/requests/api_request.rb +8 -7
  33. data/app/web/requests/assets_request.rb +12 -13
  34. data/app/web/requests/root_request.rb +6 -7
  35. data/app/web/requests/root_request_test.rb +1 -1
  36. data/app/web_box.rb +8 -0
  37. data/app_new/Procfile +1 -1
  38. data/exe/lrb +3 -0
  39. data/lib/app.rb +18 -14
  40. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +29 -0
  41. data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +14 -0
  42. data/lib/dev_system/dev/controllers/command/bench_command.rb +11 -1
  43. data/lib/dev_system/dev/controllers/command/generate_command.rb +14 -2
  44. data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -0
  45. data/lib/dev_system/dev/controllers/command/{dev_command_test.rb → not_found_command_test.rb} +2 -2
  46. data/lib/dev_system/dev/controllers/command/{dev_command.rb → terminal_command.rb} +1 -1
  47. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +14 -0
  48. data/lib/dev_system/dev/controllers/command/test_command.rb +6 -2
  49. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +1 -1
  50. data/lib/dev_system/dev/controllers/generators/app_generator.rb +30 -5
  51. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  52. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  53. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  54. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  55. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  56. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  57. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +29 -0
  58. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +14 -0
  59. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  60. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  61. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  62. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  63. data/lib/dev_system/dev/controllers/shell/file_shell.rb +56 -26
  64. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +143 -7
  65. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  66. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  67. data/lib/dev_system/dev/controllers/shell.rb +26 -14
  68. data/lib/dev_system/dev/controllers/shell_test.rb +42 -9
  69. data/lib/dev_system/dev/panels/command_panel.rb +21 -1
  70. data/lib/dev_system/dev/panels/log_panel.rb +1 -1
  71. data/lib/lerb.rb +106 -0
  72. data/lib/liza/base/controller.rb +2 -0
  73. data/lib/liza/base/panel.rb +6 -5
  74. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  75. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  76. data/lib/liza/meta/part_extension.rb +6 -1
  77. data/lib/liza/ruby_test.rb +9 -0
  78. data/lib/liza/ruby_tests/module_test.rb +21 -0
  79. data/lib/liza/ruby_tests/string_test.rb +59 -0
  80. data/lib/liza/test/test.rb +3 -1
  81. data/lib/liza/test/test_test.rb +108 -15
  82. data/lib/liza/test_parts/test_assertions_advanced_part.rb +127 -0
  83. data/lib/liza/test_parts/test_assertions_part.rb +7 -6
  84. data/lib/liza/test_parts/test_dsl_part.rb +37 -89
  85. data/lib/liza/test_parts/test_log_part.rb +124 -0
  86. data/lib/liza/test_parts/test_tree_part.rb +139 -0
  87. data/lib/liza/unit.rb +2 -0
  88. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  89. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  90. data/lib/liza.rb +5 -0
  91. data/lib/lizarb/ruby/module.rb +17 -0
  92. data/lib/lizarb/ruby/string.rb +10 -2
  93. data/lib/lizarb/version.rb +1 -1
  94. data/lib/lizarb.rb +24 -2
  95. data/lib/net_system/net/controllers/record.rb +31 -0
  96. data/lib/net_system/net/controllers/{model_test.rb → record_test.rb} +2 -2
  97. data/lib/web_system/dev/rack_command.rb +26 -0
  98. data/lib/web_system/dev/request_command.rb +143 -0
  99. data/lib/web_system/dev/web_command.rb +3 -34
  100. data/lib/web_system/web/controllers/rack.rb +8 -0
  101. data/lib/web_system/web/controllers/rack_test.rb +18 -0
  102. data/lib/web_system/web/controllers/request/client_error_request.rb +0 -1
  103. data/lib/web_system/web/controllers/request/not_found_request.rb +0 -1
  104. data/lib/web_system/web/controllers/request/server_error_request.rb +0 -1
  105. data/lib/web_system/web/panels/rack_panel.rb +44 -0
  106. data/lib/web_system/web/panels/rack_panel_test.rb +14 -0
  107. data/lib/web_system/web/panels/request_panel.rb +51 -32
  108. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  109. data/lib/web_system/web/web_box.rb +12 -0
  110. data/lizarb.gemspec +2 -2
  111. metadata +68 -25
  112. data/app/dev/commands/example_command.rb +0 -57
  113. data/app/dev/commands/example_command_test.rb +0 -43
  114. data/app/dev/commands/macro_child_command.rb +0 -32
  115. data/app/dev/commands/macro_child_command_test.rb +0 -7
  116. data/app/dev/commands/macro_parent_command.rb +0 -70
  117. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  118. data/app/dev/commands/my_command.rb +0 -7
  119. data/app/dev/commands/my_command_test.rb +0 -7
  120. data/app/dev/generators/model_generator.rb +0 -46
  121. data/app/net/models/post_model.rb +0 -4
  122. data/app/net/models/user_model.rb +0 -4
  123. data/lib/liza/test_parts/test_context_part.rb +0 -81
  124. data/lib/net_system/net/controllers/model.rb +0 -31
@@ -0,0 +1,29 @@
1
+ class DevSystem
2
+ class NotFoundBench < Bench
3
+
4
+ def self.call args
5
+ # 1. LOG
6
+
7
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
8
+ puts
9
+
10
+ # 2. FIND generators
11
+
12
+ App.eager_load_all
13
+ benches = Liza::Bench.descendants
14
+
15
+ log "Liza comes with #{benches.count} benches you can use."
16
+ puts
17
+
18
+ log "Here they are:"
19
+ puts
20
+
21
+ # 3. LIST benches
22
+
23
+ keys = benches.map { |k| k.last_namespace.snakecase[0..-7] }.sort
24
+ keys.reject! { |s| s == "not_found" }
25
+ keys.each { |s| log "liza bench #{s}" }
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class NotFoundBenchTest < BenchTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::NotFoundBench
6
+ end
7
+
8
+ test :settings do
9
+ assert subject_class.log_level == :normal
10
+ assert subject_class.log_color == :green
11
+ end
12
+
13
+ end
14
+ end
@@ -9,16 +9,26 @@ class DevSystem
9
9
 
10
10
  # 2. FIND bench
11
11
 
12
+ return call_not_found args if args.none?
13
+
12
14
  bench = args[0]
13
15
 
14
16
  log({bench:})
15
17
 
16
- bench_klass = Liza.const "#{bench}_bench"
18
+ begin
19
+ bench_klass = Liza.const "#{bench}_bench"
20
+ rescue Liza::ConstNotFound
21
+ bench_klass = NotFoundBench
22
+ end
17
23
 
18
24
  # 3. CALL
19
25
 
20
26
  bench_klass.call args[1..-1]
21
27
  end
22
28
 
29
+ def self.call_not_found args
30
+ Liza::NotFoundBench.call args
31
+ end
32
+
23
33
  end
24
34
  end
@@ -9,15 +9,27 @@ class DevSystem
9
9
 
10
10
  # 2. FIND generator
11
11
 
12
+ return call_not_found args if args.none?
13
+
12
14
  generator = args[0]
13
15
 
14
16
  log({generator:})
15
17
 
16
- generator_klass = Liza.const "#{generator}_generator"
18
+ #
19
+
20
+ begin
21
+ generator_class = Liza.const "#{generator}_generator"
22
+ rescue Liza::ConstNotFound
23
+ generator_class = NotFoundGenerator
24
+ end
17
25
 
18
26
  # 3. CALL
19
27
 
20
- generator_klass.call args[1..-1]
28
+ generator_class.call args[1..-1]
29
+ end
30
+
31
+ def self.call_not_found args
32
+ Liza::NotFoundGenerator.call args
21
33
  end
22
34
  end
23
35
  end
@@ -0,0 +1,29 @@
1
+ class DevSystem
2
+ class NotFoundCommand < Command
3
+
4
+ def self.call args
5
+ # 1. LOG
6
+
7
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
8
+ puts
9
+
10
+ # 2. FIND commands
11
+
12
+ App.eager_load_all
13
+ commands = Liza::Command.descendants
14
+
15
+ log "Liza comes with #{commands.count} commands you can use."
16
+ puts
17
+
18
+ log "Here they are:"
19
+ puts
20
+
21
+ # 3. LIST commands
22
+
23
+ keys = commands.map { |k| k.last_namespace.snakecase[0..-9] }.sort
24
+ keys.reject! { |s| s == "not_found" }
25
+ keys.each { |s| log "liza #{s}" }
26
+ end
27
+
28
+ end
29
+ end
@@ -1,8 +1,8 @@
1
1
  class DevSystem
2
- class DevCommandTest < CommandTest
2
+ class NotFoundCommandTest < CommandTest
3
3
 
4
4
  test :subject_class do
5
- assert subject_class == DevSystem::DevCommand
5
+ assert subject_class == DevSystem::NotFoundCommand
6
6
  end
7
7
 
8
8
  test :settings do
@@ -1,5 +1,5 @@
1
1
  class DevSystem
2
- class DevCommand < Command
2
+ class TerminalCommand < Command
3
3
 
4
4
  def self.call args
5
5
  # 1. LOG
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class TerminalCommandTest < CommandTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::TerminalCommand
6
+ end
7
+
8
+ test :settings do
9
+ assert subject_class.log_level == :normal
10
+ assert subject_class.log_color == :green
11
+ end
12
+
13
+ end
14
+ end
@@ -8,6 +8,10 @@ class DevSystem
8
8
 
9
9
  now = Time.now
10
10
  test_classes = Liza::Test.descendants
11
+
12
+ if Lizarb::IS_APP_DIR
13
+ test_classes = test_classes.select { |tc| tc.source_location[0].include? Lizarb::APP_DIR }
14
+ end
11
15
 
12
16
  test_classes = _call_sort test_classes
13
17
 
@@ -34,8 +38,8 @@ class DevSystem
34
38
  tc_liza = tc_namespaced.select &proc_liza
35
39
  tc_system = tc_namespaced.reject &proc_liza
36
40
 
37
- tc_app.sort_by! { |tc| Object.const_source_location(tc.name)[0] }
38
- tc_liza.sort_by! { |tc| Object.const_source_location(tc.name)[0] }
41
+ tc_app.sort_by! &:source_location
42
+ tc_liza.sort_by! &:source_location
39
43
 
40
44
  [tc_liza, tc_system, tc_app].flatten
41
45
  end
@@ -31,7 +31,7 @@ class DevSystem
31
31
  end
32
32
 
33
33
  def call
34
- FileShell.write folder, filename, content
34
+ TextShell.write "#{folder}/#{filename}", "#{content}\n"
35
35
  end
36
36
 
37
37
  %w|folder filename content|.each do |s|
@@ -3,7 +3,10 @@ class DevSystem
3
3
 
4
4
  def self.call args
5
5
  log :higher, "Called #{self}.#{__method__} with args #{args}"
6
+ new.call args
7
+ end
6
8
 
9
+ def call args
7
10
  # setup
8
11
 
9
12
  name = args.shift || "app_1"
@@ -20,7 +23,7 @@ class DevSystem
20
23
  require "fileutils"
21
24
  FileUtils.cp_r from, to, verbose: true
22
25
 
23
- `cd #{to}; git init .`
26
+ `cd #{to}; git init -b main`
24
27
 
25
28
  # extra
26
29
 
@@ -29,18 +32,22 @@ class DevSystem
29
32
  FileShell.gitkeep "#{to}/lib"
30
33
  FileShell.gitkeep "#{to}/tmp"
31
34
 
32
- FileShell.create_folder "#{to}/app"
35
+ DirShell.create "#{to}/app"
33
36
 
34
37
  # systems
35
38
 
36
- App.systems.keys.each { |system_name| copy to, system_name }
39
+ # App.systems.keys.each { |system_name| copy to, system_name }
40
+ copy to, :dev
37
41
 
38
42
  FileUtils.rm "#{to}/app/dev/commands/new_command.rb"
39
43
  FileUtils.rm "#{to}/app/dev/commands/new_command_test.rb"
40
44
 
45
+ `rm -rf #{to}/app/dev/generators/record_generator*`
46
+ `rm -rf #{to}/app/dev/generators/request_generator*`
47
+
41
48
  FileUtils.cp_r "#{Lizarb::APP_DIR}/.ruby-version", "#{to}/.ruby-version", verbose: true
42
49
  FileUtils.cp_r "#{Lizarb::APP_DIR}/README.md", "#{to}/README.md", verbose: true
43
- FileUtils.cp_r "#{Lizarb::APP_DIR}/app.rb", "#{to}/app.rb", verbose: true
50
+ TextShell.write "#{to}/app.rb", render("app.rb")
44
51
  FileUtils.cp_r "#{Lizarb::APP_DIR}/app.env", "#{to}/app.env", verbose: true
45
52
  FileUtils.cp_r "#{Lizarb::APP_DIR}/app.code.env", "#{to}/app.code.env", verbose: true
46
53
 
@@ -49,7 +56,7 @@ class DevSystem
49
56
  log "Liza Application initialized at `#{to}`"
50
57
  end
51
58
 
52
- def self.copy name, system_name
59
+ def copy name, system_name
53
60
  from = "#{Lizarb::APP_DIR}/app/#{system_name}_box.rb"
54
61
  to = "#{name}/app"
55
62
  if File.exist? from
@@ -69,3 +76,21 @@ class DevSystem
69
76
 
70
77
  end
71
78
  end
79
+
80
+ __END__
81
+
82
+ # app.rb.erb
83
+ App.call ARGV do
84
+
85
+ # Systems help you organize your application's dependencies and RAM memory usage.
86
+ # Learn more: http://guides.lizarb.org/systems.html
87
+
88
+ system :dev
89
+
90
+ # Modes help you organize your application's behavior and settings.
91
+ # Learn more: http://guides.lizarb.org/modes.html
92
+
93
+ mode :code
94
+ mode :demo
95
+
96
+ end
@@ -0,0 +1,18 @@
1
+ class <%= name.camelize %>Generator < Liza::Generator
2
+ main_dsl
3
+
4
+ FOLDER = "app/dev/<%= name %>s"
5
+
6
+ generate :controller do
7
+ folder FOLDER
8
+ filename "#{name}_<%= name %>.rb"
9
+ content render "<%= name %>.rb"
10
+ end
11
+
12
+ generate :controller_test do
13
+ folder FOLDER
14
+ filename "#{name}_<%= name %>_test.rb"
15
+ content render "<%= name %>_test.rb"
16
+ end
17
+
18
+ end
@@ -0,0 +1,12 @@
1
+ class <%= name.camelize %>GeneratorTest < Liza::GeneratorTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == <%= name.camelize %>Generator
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ end
@@ -0,0 +1,9 @@
1
+ class <%%= name.camelize %><%= name.camelize %> < Liza::<%= name.camelize %>
2
+
3
+ end
4
+
5
+ __END__
6
+
7
+ # text.txt.erb
8
+ Called <%%%= self %>.<%%%= __method__ %>
9
+ @args: <%%%= @args %>
@@ -0,0 +1,12 @@
1
+ class <%%= name.camelize %><%= name.camelize %>Test < Liza::<%= name.camelize %>Test
2
+
3
+ test :subject_class do
4
+ assert subject_class == <%%= name.camelize %><%= name.camelize %>
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ end
@@ -0,0 +1,30 @@
1
+ class DevSystem::GeneratorGenerator < Liza::Generator
2
+ main_dsl
3
+
4
+ FOLDER = "app/dev/generators"
5
+
6
+ generate :controller do
7
+ folder FOLDER
8
+ filename "#{name}_generator.rb"
9
+ content render "generator.rb"
10
+ end
11
+
12
+ generate :controller_test do
13
+ folder FOLDER
14
+ filename "#{name}_generator_test.rb"
15
+ content render "generator_test.rb"
16
+ end
17
+
18
+ generate :template do
19
+ folder "#{FOLDER}/#{name}_generator"
20
+ filename "#{name}.rb.erb"
21
+ content render "template.rb"
22
+ end
23
+
24
+ generate :template_test do
25
+ folder "#{FOLDER}/#{name}_generator"
26
+ filename "#{name}_test.rb.erb"
27
+ content render "template_test.rb"
28
+ end
29
+
30
+ end
@@ -0,0 +1,12 @@
1
+ class DevSystem::GeneratorGeneratorTest < Liza::GeneratorTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::GeneratorGenerator
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ end
@@ -0,0 +1,29 @@
1
+ class DevSystem
2
+ class NotFoundGenerator < Generator
3
+
4
+ def self.call args
5
+ # 1. LOG
6
+
7
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
8
+ puts
9
+
10
+ # 2. FIND generators
11
+
12
+ App.eager_load_all
13
+ generators = Liza::Generator.descendants
14
+
15
+ log "Liza comes with #{generators.count} generators you can use."
16
+ puts
17
+
18
+ log "Here they are:"
19
+ puts
20
+
21
+ # 3. LIST generators
22
+
23
+ keys = generators.map { |k| k.last_namespace.snakecase[0..-11] }.sort
24
+ keys.reject! { |s| s == "not_found" }
25
+ keys.each { |s| log "liza generate #{s}" }
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class NotFoundGeneratorTest < GeneratorTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::NotFoundGenerator
6
+ end
7
+
8
+ test :settings do
9
+ assert subject_class.log_level == :normal
10
+ assert subject_class.log_color == :green
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ class DevSystem::BinShell < DevSystem::FileShell
2
+
3
+ set :create_dir, true
4
+
5
+ def self.read path
6
+ log "Reading #{path}"
7
+ _raise_if_blank path
8
+ _raise_if_not_exists path
9
+
10
+ File.binread path
11
+ end
12
+
13
+ def self.write path, content, create_dir: nil
14
+ log "Writing #{content&.size.to_i} bytes (#{content.encoding}) to #{path}"
15
+ _raise_if_blank path
16
+
17
+ create_dir = get :create_dir if create_dir.nil?
18
+ DevSystem::DirShell.create File.dirname path if create_dir
19
+
20
+ File.binwrite path, content
21
+ end
22
+ end
@@ -0,0 +1,87 @@
1
+ class DevSystem::BinShellTest < DevSystem::FileShellTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::BinShell
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ #
13
+
14
+ test :subject_class, :read, :raise do
15
+ assert_raises ArgumentError do
16
+ subject_class.read nil
17
+ end
18
+
19
+ assert_raises ArgumentError do
20
+ subject_class.read ""
21
+ end
22
+
23
+ assert_raises ArgumentError do
24
+ subject_class.read "does_not_exist_#{rand 999}"
25
+ end
26
+ end
27
+
28
+ test :subject_class, :read, true do
29
+ assert subject_class.read(__FILE__).size.positive?
30
+ end
31
+
32
+ #
33
+
34
+ test :subject_class, :write, :raise do
35
+ assert_raises ArgumentError do
36
+ subject_class.write nil, "content"
37
+ end
38
+
39
+ assert_raises ArgumentError do
40
+ subject_class.write "", "content"
41
+ end
42
+ end
43
+
44
+ test :subject_class, :write, true do
45
+ path = tmp_dir.join "write_#{Time.now.to_i}"
46
+
47
+ refute subject_class.exist? path
48
+ assert subject_class.write path, "content"
49
+
50
+ assert subject_class.exist? path
51
+ assert subject_class.read(path) == "content"
52
+ end
53
+
54
+ test :subject_class, :write, :encoding do
55
+ path = tmp_dir.join "write_#{Time.now.to_i}"
56
+ s1 = "content"
57
+
58
+ refute subject_class.exist? path
59
+ assert subject_class.write path, s1
60
+
61
+ s2 = subject_class.read path
62
+ assert_equality s1, s2
63
+ refute_equality s1.encoding, s2.encoding
64
+
65
+ assert_equality s1.encoding, Encoding::UTF_8
66
+ assert_equality s2.encoding, Encoding::ASCII_8BIT
67
+ end
68
+
69
+ test :subject_class, :write, :create_dir do
70
+ path = tmp_dir.join "write_dir_#{Time.now.to_i}/a/b/c"
71
+
72
+ refute subject_class.exist? path
73
+
74
+ assert_raises Errno::ENOENT do
75
+ assert subject_class.write path, "content", create_dir: false
76
+ end
77
+
78
+ refute subject_class.exist? path
79
+
80
+ refute_raises Errno::ENOENT do
81
+ assert subject_class.write path, "content", create_dir: true
82
+ end
83
+
84
+ assert subject_class.exist? path
85
+ end
86
+
87
+ end
@@ -0,0 +1,27 @@
1
+ class DevSystem::DirShell < DevSystem::FileShell
2
+
3
+ # OVERRIDES
4
+
5
+ def self.exist? path
6
+ log :normal, "Checking if directory exists at '#{path}'"
7
+
8
+ directory? path
9
+ end
10
+
11
+ def self.size path
12
+ log :normal, "Getting size of directory at '#{path}'"
13
+ _raise_if_not_exists path
14
+
15
+ Pathname.new(path).children.inject(0) { |sum, f| sum + f.size }
16
+ end
17
+
18
+ # CUSTOM
19
+
20
+ def self.create path
21
+ log :normal, "Creating directory at '#{path}'"
22
+ _raise_if_blank path
23
+
24
+ Pathname.new(path).mkpath
25
+ end
26
+
27
+ end
@@ -0,0 +1,73 @@
1
+ class DevSystem::DirShellTest < DevSystem::FileShellTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::DirShell
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ #
13
+
14
+ test :subject_class, :exist?, :raise do
15
+ assert_raises ArgumentError do
16
+ subject_class.exist? nil
17
+ end
18
+
19
+ assert_raises ArgumentError do
20
+ subject_class.exist? ""
21
+ end
22
+ end
23
+
24
+ test :subject_class, :exist?, true do
25
+ assert subject_class.exist? Dir.pwd
26
+ assert subject_class.exist? Liza::Shell.source_location_radical
27
+ end
28
+
29
+ test :subject_class, :exist?, false do
30
+ refute subject_class.exist? "does_not_exist"
31
+ refute subject_class.exist? Liza::DirShell.source_location_radical
32
+ end
33
+
34
+ test :subject_class, :size, :raise do
35
+ assert_raises ArgumentError do
36
+ subject_class.size nil
37
+ end
38
+
39
+ assert_raises ArgumentError do
40
+ subject_class.size ""
41
+ end
42
+
43
+ assert_raises ArgumentError do
44
+ subject_class.size "does_not_exist"
45
+ end
46
+ end
47
+
48
+ test :subject_class, :size, true do
49
+ assert subject_class.size(Dir.pwd).positive?
50
+ assert subject_class.size(Liza::Shell.source_location_radical).positive?
51
+ end
52
+
53
+ #
54
+
55
+ test :subject_class, :create, :raise do
56
+ assert_raises ArgumentError do
57
+ subject_class.create nil
58
+ end
59
+
60
+ assert_raises ArgumentError do
61
+ subject_class.create ""
62
+ end
63
+ end
64
+
65
+ test :subject_class, :create, true do
66
+ path = tmp_dir.join "create_#{Time.now.to_i}"
67
+ refute subject_class.exist? path
68
+
69
+ subject_class.create path
70
+ assert subject_class.exist? path
71
+ end
72
+
73
+ end