lizarb 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) 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/dev_box.rb +24 -4
  27. data/app/happy_box.rb +1 -1
  28. data/app/net/databases/sqlite_db_test.rb +5 -5
  29. data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
  30. data/app/net/records/app_record_test.rb +8 -0
  31. data/app/net/records/post_record.rb +4 -0
  32. data/app/net/records/post_record_test.rb +8 -0
  33. data/app/net/records/user_record.rb +4 -0
  34. data/app/net/records/user_record_test.rb +8 -0
  35. data/app/net_box.rb +7 -7
  36. data/app/web/requests/api_request.rb +8 -7
  37. data/app/web/requests/assets_request.rb +12 -13
  38. data/app/web/requests/root_request.rb +6 -7
  39. data/app/web/requests/root_request_test.rb +1 -1
  40. data/app/web_box.rb +9 -1
  41. data/exe/lrb +3 -0
  42. data/lib/app.rb +19 -15
  43. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +27 -0
  44. data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench/not_found_bench_test.rb} +3 -5
  45. data/lib/dev_system/dev/controllers/bench.rb +5 -7
  46. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +37 -39
  47. data/lib/dev_system/dev/controllers/bench_test.rb +8 -10
  48. data/lib/dev_system/dev/controllers/command/bench_command.rb +20 -12
  49. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +8 -10
  50. data/lib/dev_system/dev/controllers/command/echo_command.rb +5 -7
  51. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +8 -10
  52. data/lib/dev_system/dev/controllers/command/generate_command.rb +22 -12
  53. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +8 -10
  54. data/lib/dev_system/dev/controllers/command/not_found_command.rb +27 -0
  55. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +12 -0
  56. data/lib/dev_system/dev/controllers/command/terminal_command.rb +22 -0
  57. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +12 -0
  58. data/lib/dev_system/dev/controllers/command/test_command.rb +64 -49
  59. data/lib/dev_system/dev/controllers/command/test_command_test.rb +8 -10
  60. data/lib/dev_system/dev/controllers/command/version_command.rb +4 -6
  61. data/lib/dev_system/dev/controllers/command/version_command_test.rb +8 -10
  62. data/lib/dev_system/dev/controllers/command.rb +11 -13
  63. data/lib/dev_system/dev/controllers/command_test.rb +8 -10
  64. data/lib/dev_system/dev/controllers/generator.rb +5 -7
  65. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +35 -37
  66. data/lib/dev_system/dev/controllers/generator_test.rb +8 -10
  67. data/lib/dev_system/dev/controllers/generators/app_generator.rb +122 -47
  68. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +8 -10
  69. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  70. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  71. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  72. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  73. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  74. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  75. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +27 -0
  76. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +12 -0
  77. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  78. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  79. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  80. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  81. data/lib/dev_system/dev/controllers/shell/file_shell.rb +56 -26
  82. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +143 -7
  83. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  84. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  85. data/lib/dev_system/dev/controllers/shell.rb +26 -14
  86. data/lib/dev_system/dev/controllers/shell_test.rb +42 -9
  87. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +11 -13
  88. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +8 -10
  89. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +6 -8
  90. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +8 -10
  91. data/lib/dev_system/dev/controllers/terminal.rb +11 -13
  92. data/lib/dev_system/dev/controllers/terminal_test.rb +8 -10
  93. data/lib/dev_system/dev/dev_box.rb +33 -16
  94. data/lib/dev_system/dev/dev_box_test.rb +12 -14
  95. data/lib/dev_system/dev/panels/bench_panel.rb +3 -0
  96. data/lib/dev_system/dev/panels/bench_panel_test.rb +12 -0
  97. data/lib/dev_system/dev/panels/command_panel.rb +24 -6
  98. data/lib/dev_system/dev/panels/command_panel_test.rb +15 -17
  99. data/lib/dev_system/dev/panels/generator_panel.rb +3 -0
  100. data/lib/dev_system/dev/panels/generator_panel_test.rb +12 -0
  101. data/lib/dev_system/dev/panels/log_panel.rb +9 -6
  102. data/lib/dev_system/dev/panels/log_panel_test.rb +11 -13
  103. data/lib/dev_system/dev/panels/shell_panel.rb +3 -0
  104. data/lib/dev_system/dev/panels/shell_panel_test.rb +12 -0
  105. data/lib/dev_system/dev/panels/terminal_panel.rb +3 -0
  106. data/lib/dev_system/dev/panels/terminal_panel_test.rb +12 -0
  107. data/lib/happy_system/happy/controllers/axo.rb +4 -5
  108. data/lib/happy_system/happy/happy_box.rb +6 -9
  109. data/lib/happy_system/happy/happy_box_test.rb +11 -13
  110. data/lib/happy_system/happy/panels/axo_panel.rb +1 -3
  111. data/lib/lerb.rb +106 -0
  112. data/lib/liza/base/box.rb +71 -26
  113. data/lib/liza/base/box_test.rb +7 -9
  114. data/lib/liza/base/controller.rb +19 -19
  115. data/lib/liza/base/controller_test.rb +7 -9
  116. data/lib/liza/base/panel.rb +40 -24
  117. data/lib/liza/base/panel_test.rb +10 -12
  118. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  119. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  120. data/lib/liza/meta/part.rb +12 -14
  121. data/lib/liza/meta/part_extension.rb +14 -11
  122. data/lib/liza/meta/part_test.rb +4 -6
  123. data/lib/liza/meta/system.rb +12 -14
  124. data/lib/liza/meta/system_test.rb +8 -10
  125. data/lib/liza/ruby_test.rb +7 -0
  126. data/lib/liza/ruby_tests/module_test.rb +21 -0
  127. data/lib/liza/ruby_tests/string_test.rb +59 -0
  128. data/lib/liza/test/test.rb +7 -8
  129. data/lib/liza/test/test_test.rb +168 -76
  130. data/lib/liza/test_parts/test_assertions_advanced_part.rb +125 -0
  131. data/lib/liza/test_parts/test_assertions_part.rb +81 -82
  132. data/lib/liza/test_parts/test_dsl_part.rb +44 -98
  133. data/lib/liza/test_parts/test_log_part.rb +122 -0
  134. data/lib/liza/test_parts/test_subject_part.rb +16 -18
  135. data/lib/liza/test_parts/test_tree_part.rb +137 -0
  136. data/lib/liza/unit.rb +108 -102
  137. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  138. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  139. data/lib/liza/unit_test.rb +69 -71
  140. data/lib/liza.rb +5 -0
  141. data/lib/lizarb/ruby/module.rb +17 -0
  142. data/lib/lizarb/ruby/string.rb +10 -2
  143. data/lib/lizarb/version.rb +1 -1
  144. data/lib/lizarb.rb +24 -2
  145. data/lib/net_system/dev/net_command.rb +10 -12
  146. data/lib/net_system/net/controllers/client/redis_client.rb +19 -21
  147. data/lib/net_system/net/controllers/client/redis_client_test.rb +20 -22
  148. data/lib/net_system/net/controllers/client/sqlite_client.rb +19 -21
  149. data/lib/net_system/net/controllers/client/sqlite_client_test.rb +20 -22
  150. data/lib/net_system/net/controllers/client.rb +1 -3
  151. data/lib/net_system/net/controllers/client_test.rb +8 -10
  152. data/lib/net_system/net/controllers/database/redis_db.rb +6 -8
  153. data/lib/net_system/net/controllers/database/redis_db_test.rb +15 -17
  154. data/lib/net_system/net/controllers/database/sqlite_db.rb +6 -8
  155. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +15 -17
  156. data/lib/net_system/net/controllers/database.rb +21 -23
  157. data/lib/net_system/net/controllers/database_test.rb +8 -10
  158. data/lib/net_system/net/controllers/record.rb +29 -0
  159. data/lib/net_system/net/controllers/record_test.rb +12 -0
  160. data/lib/net_system/net/net_box.rb +11 -16
  161. data/lib/net_system/net/net_box_test.rb +12 -14
  162. data/lib/net_system/net/panels/client_panel.rb +1 -3
  163. data/lib/net_system/net/panels/client_panel_test.rb +11 -13
  164. data/lib/net_system/net/panels/database_panel.rb +6 -8
  165. data/lib/net_system/net/panels/database_panel_test.rb +11 -13
  166. data/lib/web_system/dev/rack_command.rb +35 -0
  167. data/lib/web_system/dev/request_command.rb +143 -0
  168. data/lib/web_system/dev/web_command.rb +6 -39
  169. data/lib/web_system/web/controllers/rack.rb +6 -0
  170. data/lib/web_system/web/controllers/rack_test.rb +16 -0
  171. data/lib/web_system/web/controllers/request/client_error_request.rb +9 -12
  172. data/lib/web_system/web/controllers/request/not_found_request.rb +9 -12
  173. data/lib/web_system/web/controllers/request/server_error_request.rb +10 -13
  174. data/lib/web_system/web/controllers/request.rb +1 -3
  175. data/lib/web_system/web/controllers/request_test.rb +11 -13
  176. data/lib/web_system/web/panels/rack_panel.rb +42 -0
  177. data/lib/web_system/web/panels/rack_panel_test.rb +12 -0
  178. data/lib/web_system/web/panels/request_panel.rb +54 -37
  179. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  180. data/lib/web_system/web/web_box.rb +16 -8
  181. data/lib/web_system/web/web_box_test.rb +11 -13
  182. data/lizarb.gemspec +2 -2
  183. metadata +76 -28
  184. data/app/dev/commands/example_command.rb +0 -57
  185. data/app/dev/commands/example_command_test.rb +0 -43
  186. data/app/dev/commands/macro_child_command.rb +0 -32
  187. data/app/dev/commands/macro_child_command_test.rb +0 -7
  188. data/app/dev/commands/macro_parent_command.rb +0 -70
  189. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  190. data/app/dev/commands/my_command.rb +0 -7
  191. data/app/dev/commands/my_command_test.rb +0 -7
  192. data/app/dev/generators/model_generator.rb +0 -46
  193. data/app/net/models/app_model_test.rb +0 -8
  194. data/app/net/models/post_model.rb +0 -4
  195. data/app/net/models/post_model_test.rb +0 -8
  196. data/app/net/models/user_model.rb +0 -4
  197. data/app/net/models/user_model_test.rb +0 -8
  198. data/app_new/.gitignore +0 -4
  199. data/app_new/Gemfile +0 -31
  200. data/app_new/Procfile +0 -3
  201. data/lib/dev_system/dev/controllers/command/dev_command.rb +0 -24
  202. data/lib/liza/test_parts/test_context_part.rb +0 -81
  203. data/lib/net_system/net/controllers/model.rb +0 -31
  204. data/lib/net_system/net/controllers/model_test.rb +0 -14
@@ -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
@@ -1,29 +1,59 @@
1
- class DevSystem
2
- class FileShell < Shell
3
- require "fileutils"
4
-
5
- def self.create_folder folder, write_log = true
6
- log "Creating folder #{folder}" if write_log
7
- FileUtils.mkdir_p folder
8
- end
9
-
10
- def self.write folder, filename, content
11
- create_folder folder, false
12
- fname = "#{folder}/#{filename}"
13
- log "Writing #{fname} with #{content.size} bytes"
14
- File.write fname, content
15
- end
16
-
17
- def self.touch folder, filename
18
- create_folder folder, false
19
- fname = "#{folder}/#{filename}"
20
- log "Touching #{fname}"
21
- FileUtils.touch fname
22
- end
23
-
24
- def self.gitkeep folder
25
- touch folder, ".gitkeep"
26
- end
1
+ class DevSystem::FileShell < DevSystem::Shell
27
2
 
3
+ def self._raise_if_blank path
4
+ raise ArgumentError, "Path is required" if path.nil? || path.to_s.empty?
28
5
  end
6
+
7
+ def self._raise_if_not_exists path
8
+ raise ArgumentError, "File does not exist at '#{path}'" unless exist? path
9
+ end
10
+
11
+ #
12
+
13
+ def self.exist? path
14
+ log :normal, "Checking if file exists at '#{path}'"
15
+ _raise_if_blank path
16
+
17
+ File.exist? path
18
+ end
19
+
20
+ def self.size path
21
+ log :normal, "Getting size of file at '#{path}'"
22
+ _raise_if_not_exists path
23
+
24
+ File.size path
25
+ end
26
+
27
+ #
28
+
29
+ def self.directory? path
30
+ log :normal, "Checking if '#{path}' is a directory"
31
+ _raise_if_blank path
32
+
33
+ File.directory? path
34
+ end
35
+
36
+ def self.file? path
37
+ log :normal, "Checking if '#{path}' is a file"
38
+ _raise_if_blank path
39
+
40
+ File.file? path
41
+ end
42
+
43
+ #
44
+
45
+ def self.touch path
46
+ log :normal, "Touching '#{path}'"
47
+ _raise_if_blank path
48
+
49
+ dir = File.dirname(path)
50
+ DevSystem::DirShell.create dir
51
+
52
+ FileUtils.touch path
53
+ end
54
+
55
+ def self.gitkeep path
56
+ touch "#{path}/.gitkeep"
57
+ end
58
+
29
59
  end
@@ -1,14 +1,150 @@
1
- class DevSystem
2
- class FileShellTest < ShellTest
1
+ class DevSystem::FileShellTest < DevSystem::ShellTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::FileShell
3
+ # before do
4
+ # puts tmp.to_s.magenta
5
+ # end
6
+
7
+ def tmp_dir
8
+ @tmp_dir ||= begin
9
+ name = self.class.name.split("::").map(&:snakefy).join "_"
10
+ time = Time.now.strftime "%Y%m%d_%H%M%S"
11
+ random = SecureRandom.hex 4
12
+ ret = Pathname.new(Dir.pwd).join "tmp/test_#{App.mode}_#{name}_#{time}_#{random}"
13
+ FileUtils.mkdir_p ret
14
+ log "Created tmp_dir: #{ret}"
15
+ ret
16
+ end
17
+ end
18
+
19
+ after do
20
+ # NOTE: @tmp_dir does not create a new directory for each test
21
+ if @tmp_dir
22
+ FileUtils.rm_rf @tmp_dir
23
+ log "Removed tmp_dir: #{@tmp_dir}"
24
+ end
25
+ end
26
+
27
+ #
28
+
29
+ test :subject_class do
30
+ assert subject_class == DevSystem::FileShell
31
+ end
32
+
33
+ test :settings do
34
+ assert subject_class.log_level == :normal
35
+ assert subject_class.log_color == :green
36
+ end
37
+
38
+ #
39
+
40
+ test :subject_class, :exist?, :true do
41
+ assert subject_class.exist? __FILE__
42
+ end
43
+
44
+ test :subject_class, :exist?, :false do
45
+ refute subject_class.exist? "does_not_exist_#{rand 999}"
46
+ end
47
+
48
+ test :subject_class, :exist?, :raise do
49
+ assert_raises ArgumentError do
50
+ subject_class.exist? nil
51
+ end
52
+
53
+ assert_raises ArgumentError do
54
+ subject_class.exist? ""
55
+ end
56
+ end
57
+
58
+ #
59
+
60
+ test :subject_class, :size, true do
61
+ assert subject_class.size(__FILE__).positive?
62
+ end
63
+
64
+ test :subject_class, :size, :raise do
65
+ assert_raises ArgumentError do
66
+ subject_class.size nil
67
+ end
68
+
69
+ assert_raises ArgumentError do
70
+ subject_class.size ""
71
+ end
72
+
73
+ assert_raises ArgumentError do
74
+ subject_class.size "does_not_exist_#{rand 999}"
75
+ end
76
+ end
77
+
78
+ #
79
+
80
+ test :subject_class, :directory?, true do
81
+ assert subject_class.directory? Dir.pwd
82
+ end
83
+
84
+ test :subject_class, :directory?, false do
85
+ refute subject_class.directory? __FILE__
86
+ refute subject_class.directory? "does_not_exist"
87
+ end
88
+
89
+ test :subject_class, :directory?, :raise do
90
+ assert_raises ArgumentError do
91
+ subject_class.directory? nil
92
+ end
93
+
94
+ assert_raises ArgumentError do
95
+ subject_class.directory? ""
96
+ end
97
+ end
98
+
99
+ test :subject_class, :file?, true do
100
+ assert subject_class.file? __FILE__
101
+ end
102
+
103
+ test :subject_class, :file?, false do
104
+ refute subject_class.file? Dir.pwd
105
+ refute subject_class.file? "does_not_exist_#{rand 999}"
106
+ end
107
+
108
+ test :subject_class, :file?, :raise do
109
+ assert_raises ArgumentError do
110
+ subject_class.file? nil
6
111
  end
7
112
 
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
113
+ assert_raises ArgumentError do
114
+ subject_class.file? ""
11
115
  end
116
+ end
117
+
118
+ #
119
+
120
+ test :subject_class, :touch, true do
121
+ path = tmp_dir.join "touch_#{Time.now.to_i}"
122
+ refute subject_class.exist? path
12
123
 
124
+ assert subject_class.touch path
125
+ assert subject_class.exist? path
13
126
  end
127
+
128
+ test :subject_class, :touch, :raise do
129
+ assert_raises ArgumentError do
130
+ subject_class.touch nil
131
+ end
132
+
133
+ assert_raises ArgumentError do
134
+ subject_class.touch ""
135
+ end
136
+ end
137
+
138
+ #
139
+
140
+ test :subject_class, :gitkeep do
141
+ path = tmp_dir.join "gitkeep_#{Time.now.to_i}"
142
+ refute subject_class.exist? path
143
+
144
+ assert subject_class.gitkeep path
145
+ assert subject_class.exist? path
146
+ end
147
+
148
+ #
149
+
14
150
  end
@@ -0,0 +1,23 @@
1
+ class DevSystem::TextShell < 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.read path
11
+ end
12
+
13
+ def self.write path, content, create_dir: nil
14
+ log "Writing #{content.to_s.size} characters (#{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.write path, content
21
+ end
22
+
23
+ end
@@ -0,0 +1,84 @@
1
+ class DevSystem::TextShellTest < DevSystem::FileShellTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::TextShell
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, true do
15
+ assert subject_class.read(__FILE__).size.positive?
16
+ end
17
+
18
+ test :subject_class, :read, :raise do
19
+ assert_raises ArgumentError do
20
+ subject_class.read nil
21
+ end
22
+
23
+ assert_raises ArgumentError do
24
+ subject_class.read ""
25
+ end
26
+
27
+ assert_raises ArgumentError do
28
+ subject_class.read "does_not_exist_#{rand 999}"
29
+ end
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
+ assert_equality s1.encoding, s2.encoding
64
+
65
+ assert_equality s1.encoding, Encoding::UTF_8
66
+ assert_equality s2.encoding, Encoding::UTF_8
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
+ assert subject_class.write path, "content", create_dir: true
79
+
80
+ assert subject_class.exist? path
81
+ assert subject_class.read(path) == "content"
82
+ end
83
+
84
+ end
@@ -1,19 +1,31 @@
1
- class DevSystem
2
- class Shell < Liza::Controller
3
- def windows?
4
- RUBY_PLATFORM =~ /win32/
5
- end
1
+ class DevSystem::Shell < Liza::Controller
6
2
 
7
- def unix?
8
- linux? || mac?
9
- end
3
+ # Check if the current platform is Windows
4
+ def self.windows?
5
+ @windows || Gem.win_platform?
6
+ end
7
+
8
+ # Check if the current platform is Unix or Unix-like
9
+ def self.unix?
10
+ @unix || !windows?
11
+ end
10
12
 
11
- def linux?
12
- RUBY_PLATFORM =~ /linux/
13
- end
13
+ # Check if the current platform is Linux
14
+ def self.linux?
15
+ @linux || (unix? && RbConfig::CONFIG['host_os'].include?("linux"))
16
+ end
14
17
 
15
- def mac?
16
- RUBY_PLATFORM =~ /darwin/
17
- end
18
+ # Check if the current platform is Mac OS
19
+ def self.mac?
20
+ @mac || (unix? && RbConfig::CONFIG['host_os'].include?("darwin"))
18
21
  end
22
+
23
+ # Return the current operating system as a symbol
24
+ def self.os
25
+ return :windows if windows?
26
+ return :linux if linux?
27
+ return :mac if mac?
28
+ :unix
29
+ end
30
+
19
31
  end
@@ -1,13 +1,46 @@
1
- class DevSystem
2
- class ShellTest < Liza::ControllerTest
1
+ class DevSystem::ShellTest < Liza::ControllerTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::Shell
6
- end
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::Shell
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, :windows? do
15
+ original = subject_class.windows?
16
+ subject_class.instance_variable_set(:@windows, true)
17
+ assert subject_class.windows?
18
+ ensure
19
+ subject_class.instance_variable_set(:@windows, original)
20
+ end
7
21
 
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
11
- end
22
+ test :subject_class, :unix? do
23
+ original = subject_class.unix?
24
+ subject_class.instance_variable_set(:@unix, true)
25
+ assert subject_class.unix?
26
+ ensure
27
+ subject_class.instance_variable_set(:@unix, original)
12
28
  end
29
+
30
+ test :subject_class, :linux? do
31
+ original = subject_class.linux?
32
+ subject_class.instance_variable_set(:@linux, true)
33
+ assert subject_class.linux?
34
+ ensure
35
+ subject_class.instance_variable_set(:@linux, original)
36
+ end
37
+
38
+ test :subject_class, :mac? do
39
+ original = subject_class.mac?
40
+ subject_class.instance_variable_set(:@mac, true)
41
+ assert subject_class.mac?
42
+ ensure
43
+ subject_class.instance_variable_set(:@mac, original)
44
+ end
45
+
13
46
  end
@@ -1,19 +1,17 @@
1
- class DevSystem
2
- class IrbTerminal < Terminal
1
+ class DevSystem::IrbTerminal < DevSystem::Terminal
3
2
 
4
- def self.call args
5
- log :higher, "Called #{self}.#{__method__} with args #{args}"
3
+ def self.call args
4
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
6
5
 
7
- # https://github.com/ruby/ruby/blob/master/lib/irb.rb
8
- require "irb"
6
+ # https://github.com/ruby/ruby/blob/master/lib/irb.rb
7
+ require "irb"
9
8
 
10
- IRB.setup(nil)
11
- workspace = IRB::WorkSpace.new(binding)
12
- irb = IRB::Irb.new(workspace)
13
- IRB.conf[:MAIN_CONTEXT] = irb.context
14
-
15
- irb.eval_input
16
- end
9
+ IRB.setup(nil)
10
+ workspace = IRB::WorkSpace.new(binding)
11
+ irb = IRB::Irb.new(workspace)
12
+ IRB.conf[:MAIN_CONTEXT] = irb.context
17
13
 
14
+ irb.eval_input
18
15
  end
16
+
19
17
  end
@@ -1,14 +1,12 @@
1
- class DevSystem
2
- class IrbTerminalTest < TerminalTest
1
+ class DevSystem::IrbTerminalTest < DevSystem::TerminalTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == DevSystem::IrbTerminal
6
- end
7
-
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :green
11
- end
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::IrbTerminal
5
+ end
12
6
 
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
13
10
  end
11
+
14
12
  end