geb 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +3 -0
  3. data/CHANGELOG.md +37 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/LICENSE +21 -0
  6. data/README.md +384 -0
  7. data/Rakefile +21 -0
  8. data/bin/geb +21 -0
  9. data/lib/geb/cli.rb +40 -0
  10. data/lib/geb/commands/build.rb +59 -0
  11. data/lib/geb/commands/init.rb +70 -0
  12. data/lib/geb/commands/release.rb +54 -0
  13. data/lib/geb/commands/remote.rb +48 -0
  14. data/lib/geb/commands/server.rb +77 -0
  15. data/lib/geb/commands/upload.rb +48 -0
  16. data/lib/geb/commands/version.rb +36 -0
  17. data/lib/geb/config.rb +103 -0
  18. data/lib/geb/defaults.rb +44 -0
  19. data/lib/geb/git.rb +112 -0
  20. data/lib/geb/page.rb +217 -0
  21. data/lib/geb/partial.rb +150 -0
  22. data/lib/geb/samples/basic/assets/css/site.css +7 -0
  23. data/lib/geb/samples/basic/assets/images/android-chrome-192x192.png +0 -0
  24. data/lib/geb/samples/basic/assets/images/android-chrome-512x512.png +0 -0
  25. data/lib/geb/samples/basic/assets/images/apple-touch-icon.png +0 -0
  26. data/lib/geb/samples/basic/assets/images/favicon-16x16.png +0 -0
  27. data/lib/geb/samples/basic/assets/images/favicon-32x32.png +0 -0
  28. data/lib/geb/samples/basic/assets/images/favicon.ico +0 -0
  29. data/lib/geb/samples/basic/assets/images/hero.png +0 -0
  30. data/lib/geb/samples/basic/assets/images/og-thumb.png +0 -0
  31. data/lib/geb/samples/basic/assets/images/twitter-thumb.png +0 -0
  32. data/lib/geb/samples/basic/assets/js/site.js +5 -0
  33. data/lib/geb/samples/basic/geb.config.yml +70 -0
  34. data/lib/geb/samples/basic/index.html +11 -0
  35. data/lib/geb/samples/basic/page.html +11 -0
  36. data/lib/geb/samples/basic/shared/partials/_analytics.html +9 -0
  37. data/lib/geb/samples/basic/shared/partials/_footer.html +3 -0
  38. data/lib/geb/samples/basic/shared/partials/_global_assets.html +19 -0
  39. data/lib/geb/samples/basic/shared/partials/_header.html +0 -0
  40. data/lib/geb/samples/basic/shared/partials/_meta_tags.html +34 -0
  41. data/lib/geb/samples/basic/shared/templates/_blog_post.html +0 -0
  42. data/lib/geb/samples/basic/shared/templates/_site.html +19 -0
  43. data/lib/geb/samples/basic/site.webmanifest +1 -0
  44. data/lib/geb/samples/bootstrap_jquery/assets/css/site.css +7 -0
  45. data/lib/geb/samples/bootstrap_jquery/assets/images/android-chrome-192x192.png +0 -0
  46. data/lib/geb/samples/bootstrap_jquery/assets/images/android-chrome-512x512.png +0 -0
  47. data/lib/geb/samples/bootstrap_jquery/assets/images/apple-touch-icon.png +0 -0
  48. data/lib/geb/samples/bootstrap_jquery/assets/images/favicon-16x16.png +0 -0
  49. data/lib/geb/samples/bootstrap_jquery/assets/images/favicon-32x32.png +0 -0
  50. data/lib/geb/samples/bootstrap_jquery/assets/images/favicon.ico +0 -0
  51. data/lib/geb/samples/bootstrap_jquery/assets/images/hero.png +0 -0
  52. data/lib/geb/samples/bootstrap_jquery/assets/images/og-thumb.png +0 -0
  53. data/lib/geb/samples/bootstrap_jquery/assets/images/twitter-thumb.png +0 -0
  54. data/lib/geb/samples/bootstrap_jquery/assets/js/site.js +5 -0
  55. data/lib/geb/samples/bootstrap_jquery/blog/blog_post_1.html +35 -0
  56. data/lib/geb/samples/bootstrap_jquery/blog/blog_post_2.html +35 -0
  57. data/lib/geb/samples/bootstrap_jquery/blog/blog_post_3.html +35 -0
  58. data/lib/geb/samples/bootstrap_jquery/blog/index.html +17 -0
  59. data/lib/geb/samples/bootstrap_jquery/geb.config.yml +69 -0
  60. data/lib/geb/samples/bootstrap_jquery/index.html +11 -0
  61. data/lib/geb/samples/bootstrap_jquery/page.html +11 -0
  62. data/lib/geb/samples/bootstrap_jquery/shared/partials/_analytics.html +9 -0
  63. data/lib/geb/samples/bootstrap_jquery/shared/partials/_footer.html +3 -0
  64. data/lib/geb/samples/bootstrap_jquery/shared/partials/_global_assets.html +19 -0
  65. data/lib/geb/samples/bootstrap_jquery/shared/partials/_header.html +0 -0
  66. data/lib/geb/samples/bootstrap_jquery/shared/partials/_meta_tags.html +34 -0
  67. data/lib/geb/samples/bootstrap_jquery/shared/templates/_blog_post.html +0 -0
  68. data/lib/geb/samples/bootstrap_jquery/shared/templates/_site.html +19 -0
  69. data/lib/geb/samples/bootstrap_jquery/site.webmanifest +1 -0
  70. data/lib/geb/samples/geb.config.yml +70 -0
  71. data/lib/geb/server.rb +138 -0
  72. data/lib/geb/site/build.rb +189 -0
  73. data/lib/geb/site/core.rb +229 -0
  74. data/lib/geb/site/release.rb +70 -0
  75. data/lib/geb/site/remote.rb +142 -0
  76. data/lib/geb/site/template.rb +208 -0
  77. data/lib/geb/site.rb +83 -0
  78. data/lib/geb/template.rb +166 -0
  79. data/lib/geb/utilities.rb +110 -0
  80. data/lib/geb.rb +36 -0
  81. data/lib/seth.rb +50 -0
  82. data/sig/geb.rbs +4 -0
  83. data/test/api tests/test_cli.rb +200 -0
  84. data/test/api tests/test_config.rb +330 -0
  85. data/test/api tests/test_defaults.rb +62 -0
  86. data/test/api tests/test_git.rb +105 -0
  87. data/test/api tests/test_page.rb +320 -0
  88. data/test/api tests/test_partial.rb +152 -0
  89. data/test/api tests/test_server.rb +416 -0
  90. data/test/api tests/test_site.rb +1315 -0
  91. data/test/api tests/test_template.rb +249 -0
  92. data/test/api tests/test_utilities.rb +162 -0
  93. data/test/command tests/test_geb_build.rb +199 -0
  94. data/test/command tests/test_geb_init.rb +312 -0
  95. data/test/command tests/test_geb_release.rb +166 -0
  96. data/test/command tests/test_geb_remote.rb +66 -0
  97. data/test/command tests/test_geb_server.rb +122 -0
  98. data/test/command tests/test_geb_upload.rb +96 -0
  99. data/test/command tests/test_geb_version.rb +58 -0
  100. data/test/support/geb_api_test.rb +37 -0
  101. data/test/support/geb_cli_test.rb +275 -0
  102. data/test/support/geb_minitest_ext.rb +35 -0
  103. data/test/support/geb_test_helpers.rb +84 -0
  104. data/test/support/geb_web_server_proxy.rb +128 -0
  105. data/test/test_helper.rb +61 -0
  106. metadata +301 -0
@@ -0,0 +1,312 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the init command class
4
+ #
5
+ # @title Geb - Test - Init Command
6
+ # @author Edin Mustajbegovic <edin@actiontwelve.com>
7
+ # @copyright 2024 Edin Mustajbegovic
8
+ # @license MIT
9
+ #
10
+ # @see https://github.com/mainfram-work/geb for more information
11
+
12
+ require "test_helper"
13
+ require "fileutils"
14
+ require "tmpdir"
15
+ require 'webmock/minitest'
16
+
17
+ class TestGebCommandInit < Geb::CliTest
18
+
19
+ test "that the CLI api call works" do
20
+
21
+ # initialize new command instance
22
+ command = Geb::CLI::Commands::Init.new
23
+
24
+ site_path = "path/to/site"
25
+ command_options = { template: "default", skip_template: false, skip_git: false, force: false }
26
+
27
+ site_mock = mock('site')
28
+ site_mock.expects(:validate)
29
+ site_mock.expects(:create)
30
+
31
+ Geb::Site.expects(:new).returns(site_mock)
32
+ Geb::Git.expects(:validate_git_repo)
33
+ Geb::Git.expects(:create_git_repo)
34
+
35
+ original_stdout = $stdout
36
+ original_stderr = $stderr
37
+
38
+ $stdout = StringIO.new
39
+ $stderr = StringIO.new
40
+
41
+ command.call(site_path: site_path, **command_options)
42
+
43
+ assert_empty $stderr.string
44
+
45
+ $stdout = original_stdout
46
+ $stderr = original_stderr
47
+
48
+ end # test "that the CLI api call works"
49
+
50
+ test "that the CLI api call works and handles exceptions" do
51
+
52
+ # initialize new command instance
53
+ command = Geb::CLI::Commands::Init.new
54
+
55
+ site_path = "path/to/site"
56
+ command_options = { template: "default", skip_template: false, skip_git: false, force: false }
57
+
58
+ site_mock = mock('site')
59
+ site_mock.expects(:validate).raises(Geb::Error.new("Test Error"))
60
+ site_mock.stubs(:create)
61
+
62
+ Geb::Site.stubs(:new).returns(site_mock)
63
+ Geb::Git.stubs(:validate_git_repo)
64
+ Geb::Git.stubs(:create_git_repo)
65
+
66
+ # setup a StringIO to capture standard output and error
67
+ original_stdout = $stdout
68
+ original_stderr = $stderr
69
+
70
+ $stdout = StringIO.new
71
+ $stderr = StringIO.new
72
+
73
+ command.call(site_path: site_path, **command_options)
74
+
75
+ refute_empty $stderr.string
76
+ assert_includes $stderr.string, "Test Error"
77
+
78
+ $stdout = original_stdout
79
+ $stderr = original_stderr
80
+
81
+ end # test "that the CLI api call works and handles exceptions"
82
+
83
+ test "that command default executes" do
84
+
85
+ new_site_path = "new_site"
86
+
87
+ stdout, stderr, status = Open3.capture3("geb init #{new_site_path}")
88
+
89
+ assert status.success?
90
+ assert_empty stderr
91
+
92
+ assert_includes stdout, "Validating site path #{new_site_path} ... done."
93
+ assert_includes stdout, "No template specified, using default: #{Geb::Defaults::DEFAULT_TEMPLATE}."
94
+ assert_includes stdout, "Validating template path #{Geb::Defaults::DEFAULT_TEMPLATE_DIR} ... done."
95
+ assert_includes stdout, "Validating proposed site path as a git repository ... done."
96
+ refute_includes stdout, "Skipping git repository validation as told."
97
+
98
+ assert_includes stdout, "Creating site folder: #{new_site_path} ... done."
99
+ assert File.directory?(new_site_path)
100
+
101
+ assert_includes stdout, "Loading template site from path #{Geb::Defaults::DEFAULT_TEMPLATE_DIR} ... done."
102
+ assert_includes stdout, "Resolving directories and files from template site to copy ... done."
103
+ assert_includes stdout, "copying directory and all sub-directories from #{Geb::Defaults::DEFAULT_TEMPLATE_DIR}"
104
+ assert_includes stdout, "copying directory and all sub-directories from"
105
+ assert_includes stdout, "Creating: local and release output folders ...done."
106
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
107
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR))
108
+
109
+ assert_includes stdout, "Initialising git repository ... done."
110
+ refute_includes stdout, "Skipping git repository creation as told."
111
+ assert File.directory?(File.join(new_site_path, ".git"))
112
+ assert File.exist?(File.join(new_site_path, ".gitignore"))
113
+
114
+ end # test "that command default executes"
115
+
116
+ test "that new site can ignore git creation" do
117
+
118
+ new_site_path = "new_site"
119
+
120
+ stdout, stderr, status = Open3.capture3("geb init #{new_site_path} --skip-git")
121
+
122
+ assert status.success?
123
+ assert_empty stderr
124
+
125
+ assert_includes stdout, "Validating site path #{new_site_path} ... done."
126
+ assert_includes stdout, "No template specified, using default: #{Geb::Defaults::DEFAULT_TEMPLATE}."
127
+ assert_match(/Validating template path.*#{Geb::Defaults::DEFAULT_TEMPLATE}.*\.\.\. done\./, stdout)
128
+ assert_includes stdout, "Skipping git repository validation as told."
129
+
130
+ assert_includes stdout, "Creating site folder: #{new_site_path} ... done."
131
+ assert File.directory?(new_site_path)
132
+
133
+
134
+ assert_includes stdout, "Loading template site from path #{Geb::Defaults::DEFAULT_TEMPLATE_DIR} ... done."
135
+ assert_includes stdout, "Resolving directories and files from template site to copy ... done."
136
+ assert_includes stdout, "copying directory and all sub-directories from #{Geb::Defaults::DEFAULT_TEMPLATE_DIR}"
137
+ assert_includes stdout, "copying directory and all sub-directories from"
138
+ assert_includes stdout, "Creating: local and release output folders ...done."
139
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
140
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR))
141
+
142
+ refute_includes stdout, "Initialising git repository ... done."
143
+ assert_includes stdout, "Skipping git repository creation as told."
144
+
145
+ refute File.directory?(File.join(new_site_path, ".git"))
146
+ refute File.exist?(File.join(new_site_path, ".gitignore"))
147
+
148
+ end # test "that new site can ignore git creation"
149
+
150
+ test "that new site can ignore template creation" do
151
+
152
+ new_site_path = "new_site"
153
+
154
+ stdout, stderr, status = Open3.capture3("geb init #{new_site_path} --skip-template")
155
+
156
+ assert status.success?
157
+ assert_empty stderr
158
+
159
+ assert_includes stdout, "Validating site path #{new_site_path} ... done."
160
+ assert_includes stdout, "Skipping template validation as told."
161
+ assert_includes stdout, "Validating proposed site path as a git repository ... done."
162
+ refute_includes stdout, "Skipping git repository validation as told."
163
+
164
+ assert_includes stdout, "Creating site folder: #{new_site_path} ... done."
165
+ assert File.directory?(new_site_path)
166
+
167
+ assert_includes stdout, "Skipping template creation as told."
168
+ assert_includes stdout, "Creating: local and release output folders ...done."
169
+
170
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
171
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR))
172
+
173
+ assert_includes stdout, "Initialising git repository ... done."
174
+ refute_includes stdout, "Skipping git repository creation as told."
175
+ assert File.directory?(File.join(new_site_path, ".git"))
176
+ assert File.exist?(File.join(new_site_path, ".gitignore"))
177
+
178
+ end # test "that new site can ignore template creation"
179
+
180
+ test "that new site can handle specified geb sample template" do
181
+
182
+ new_site_path = "new_site"
183
+ template = "bootstrap_jquery"
184
+
185
+ stdout, stderr, status = Open3.capture3("geb init #{new_site_path} --template #{template}")
186
+
187
+ assert status.success?
188
+ assert_empty stderr
189
+
190
+ template_full_path = File.join(Geb::Defaults::BUNDLED_TEMPLATES_DIR, template)
191
+
192
+ assert_includes stdout, "Validating site path #{new_site_path} ... done."
193
+ assert_includes stdout, "Specified template is a Geb sample: #{template}, using it as site template."
194
+ assert_includes stdout, "Validating template path #{template_full_path} ... done."
195
+ assert_includes stdout, "Validating proposed site path as a git repository ... done."
196
+ refute_includes stdout, "Skipping git repository validation as told."
197
+
198
+ assert_includes stdout, "Creating site folder: #{new_site_path} ... done."
199
+ assert File.directory?(new_site_path)
200
+
201
+ assert_includes stdout, "Loading template site from path #{template_full_path} ... done."
202
+ assert_includes stdout, "Resolving directories and files from template site to copy ... done."
203
+ assert_includes stdout, "copying directory and all sub-directories from #{template_full_path}"
204
+ assert_includes stdout, "copying directory and all sub-directories from"
205
+ assert_includes stdout, "Creating: local and release output folders ...done."
206
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
207
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR))
208
+
209
+ assert_includes stdout, "Initialising git repository ... done."
210
+ refute_includes stdout, "Skipping git repository creation as told."
211
+ assert File.directory?(File.join(new_site_path, ".git"))
212
+ assert File.exist?(File.join(new_site_path, ".gitignore"))
213
+
214
+ end # test "that new site can handle specified geb sample template"
215
+
216
+ test "that invalid specified template is handled correctly" do
217
+
218
+ new_site_path = "new_site"
219
+ template = "invalid_template_just_to_make_sure_3_for_sure"
220
+
221
+ _, stderr, status = Open3.capture3("geb init #{new_site_path} --template #{template}")
222
+
223
+ assert status.success?
224
+ assert_includes stderr, "Invalid template site. Make sure the specified path is a directory and contains a valid geb.config.yml file."
225
+ refute File.directory?(new_site_path)
226
+
227
+ end # test "that invalid specified template is handled correctly"
228
+
229
+ test "that template url is used correctly" do
230
+
231
+ http_proxy = start_proxy
232
+
233
+ new_site_path = "new_site"
234
+ template_url = "#{http_proxy.base_url}/geb-template.tar.gz"
235
+
236
+ http_proxy.stub_request(template_url, { 'Content-Type' => 'application/x-gzip' }) do
237
+ File.read(File.join(File.dirname(__FILE__), "../files", "geb-template.tar.gz"))
238
+ end
239
+
240
+ stdout, stderr, status = Open3.capture3("geb init #{new_site_path} --template #{template_url}")
241
+
242
+ assert status.success?
243
+ assert_empty stderr
244
+
245
+ assert_includes stdout, "Validating site path #{new_site_path} ... done."
246
+ assert_includes stdout, "Validating template URL #{template_url} ... done."
247
+ assert_includes stdout, "Found a gzip archive at template url #{template_url}."
248
+ assert_includes stdout, "Downloading template from URL #{template_url} ... done."
249
+
250
+ assert_includes stdout, "Validating proposed site path as a git repository ... done."
251
+ refute_includes stdout, "Skipping git repository validation as told."
252
+
253
+ assert_includes stdout, "Creating site folder: #{new_site_path} ... done."
254
+ assert File.directory?(new_site_path)
255
+
256
+ assert_match(/Loading template site from path .*\.\.\. done\./, stdout)
257
+ assert_includes stdout, "Creating: local and release output folders ...done."
258
+ assert_includes stdout, "Resolving directories and files from template site to copy ... done."
259
+ assert_match(/copying directory and all sub-directories from .*\.\.\. done\./, stdout)
260
+ assert_match(/copying file from .*\.\.\. done\./, stdout)
261
+
262
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
263
+ assert File.directory?(File.join(new_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR))
264
+
265
+ assert_includes stdout, "Initialising git repository ... done."
266
+ refute_includes stdout, "Skipping git repository creation as told."
267
+
268
+ assert File.directory?(File.join(new_site_path, ".git"))
269
+ assert File.exist?(File.join(new_site_path, ".gitignore"))
270
+
271
+ end # test "that template url is used correctly"
272
+
273
+ test "that invalid template url is handled correctly" do
274
+
275
+ new_site_path = "new_site"
276
+ template_url = "http://www.examplexyz7y.com/geb-template.tar.gz"
277
+
278
+ stdout, stderr, status = Open3.capture3("geb init #{new_site_path} --template #{template_url}")
279
+
280
+ assert status.success?
281
+
282
+ assert_includes stdout, "Validating site path #{new_site_path} ... done."
283
+ assert_includes stdout, "Validating template URL #{template_url}"
284
+ assert_includes stderr, "HTTP error"
285
+
286
+ refute File.directory?(new_site_path)
287
+
288
+ end # test "that invalid template url is handled correctly"
289
+
290
+ test "that template url not being an archive is handled correctly" do
291
+
292
+ http_proxy = start_proxy
293
+
294
+ new_site_path = "new_site"
295
+ template_url = "#{http_proxy.base_url}/geb-template.tar.gz"
296
+
297
+ http_proxy.stub_request(template_url, { 'Content-Type' => 'text/plain' }, "This is not a tar.gz file")
298
+
299
+ stdout, stderr, status = Open3.capture3("geb init #{new_site_path} --template #{template_url}")
300
+
301
+ assert status.success?
302
+
303
+ assert_includes stdout, "Validating site path #{new_site_path} ... done."
304
+
305
+ assert_includes stdout, "Validating template URL #{template_url} ... done."
306
+ assert_includes stderr, "Specified template is not a gzip archive"
307
+
308
+ refute File.directory?(new_site_path)
309
+
310
+ end # test "that template url not being an archive is handled correctly"
311
+
312
+ end # class TestGebCommandInit < Minitest::Test
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the release command class
4
+ #
5
+ # @title Geb - Test - Release Command
6
+ # @author Edin Mustajbegovic <edin@actiontwelve.com>
7
+ # @copyright 2024 Edin Mustajbegovic
8
+ # @license MIT
9
+ #
10
+ # @see https://github.com/mainfram-work/geb for more information
11
+
12
+ require "test_helper"
13
+
14
+ class TestGebCommandRelease < Geb::CliTest
15
+
16
+ test "that the CLI api call works" do
17
+
18
+ copy_test_site()
19
+
20
+ command = Geb::CLI::Commands::Release.new
21
+
22
+ command_options = { with_template: false }
23
+
24
+ site_mock = mock('site')
25
+ site_mock.expects(:load).with(Dir.pwd)
26
+ site_mock.expects(:release)
27
+
28
+ Geb::Site.expects(:new).returns(site_mock)
29
+
30
+ original_stdout = $stdout
31
+ original_stderr = $stderr
32
+
33
+ $stdout = StringIO.new
34
+ $stderr = StringIO.new
35
+
36
+ command.call(**command_options)
37
+
38
+ assert_empty $stderr.string
39
+
40
+ $stdout = original_stdout
41
+ $stderr = original_stderr
42
+
43
+ end # test "that the CLI api call works"
44
+
45
+ test "that the CLI api call works and handles exceptions" do
46
+
47
+ # initialize new command instance
48
+ command = Geb::CLI::Commands::Release.new
49
+
50
+ command_options = { with_template: false }
51
+
52
+ Geb::Site.expects(:new).raises(Geb::Error.new("Test Error"))
53
+
54
+ # setup a StringIO to capture standard output and error
55
+ original_stdout = $stdout
56
+ original_stderr = $stderr
57
+
58
+ $stdout = StringIO.new
59
+ $stderr = StringIO.new
60
+
61
+ command.call(**command_options)
62
+
63
+ refute_empty $stderr.string
64
+ assert_includes $stderr.string, "Test Error"
65
+
66
+ $stdout = original_stdout
67
+ $stderr = original_stderr
68
+
69
+ end # test "that the CLI api call works and handles exceptions"
70
+
71
+ test "that command default executes" do
72
+
73
+ copy_test_site()
74
+
75
+ # call geb auto command and capture output and error
76
+ _, stderr, status = Open3.capture3('geb release')
77
+
78
+ # assert that the output contains the expected string
79
+ assert status.success?
80
+ assert_empty stderr
81
+
82
+ end # test "command line"
83
+
84
+ test "that command handles being executed in a non-site directory" do
85
+
86
+ # create a temporary directory
87
+ Dir.mktmpdir do |dir|
88
+
89
+ # change the current directory to the temporary directory
90
+ Dir.chdir(dir)
91
+
92
+ # call geb auto command and capture output and error
93
+ _, stderr, status = Open3.capture3('geb release')
94
+
95
+ # assert that the output contains the expected string
96
+ assert status.success?
97
+ refute_empty stderr
98
+
99
+ end # Dir.mktmpdir
100
+
101
+ end # test "that command handles being executed in a non-site directory"
102
+
103
+ test "that the command actually builds and releases the site" do
104
+
105
+ copy_test_site()
106
+
107
+ stdout, stderr, status = Open3.capture3('geb release')
108
+
109
+ assert status.success?
110
+ assert_empty stderr
111
+
112
+ assert_includes stdout, "Loading site from path #{Dir.pwd} ... done."
113
+ assert_includes stdout, "Found geb site at path #{Dir.pwd}"
114
+ assert_match(/Building \d* pages for/, stdout)
115
+ assert_includes stdout, "loading page"
116
+ assert_includes stdout, "loading template"
117
+ assert_includes stdout, "loading partial"
118
+ assert_includes stdout, "building page"
119
+ assert_match(/Done building \d* pages for/, stdout)
120
+ assert_includes stdout, "Clearing site output folder"
121
+ assert_match(/Outputting site to.*done/, stdout)
122
+ assert_includes stdout, "Building assets for"
123
+ assert_includes stdout, "Done building assets for"
124
+ assert_match(/Clearing site release folder.*done/, stdout)
125
+ assert_match(/Releasing site to.*done/, stdout)
126
+ refute_match(/Resolving directories and files to include in the template archive.*done/, stdout)
127
+ refute_match(/Creating template archive in.*done/, stdout)
128
+
129
+ end # test "that the command actually builds the site"
130
+
131
+ test "that the command actually builds and releases the site with a template" do
132
+
133
+ copy_test_site()
134
+
135
+ output_archive_filename = File.join(Dir.pwd, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR, Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME)
136
+
137
+ stdout, stderr, status = Open3.capture3('geb release --with_template')
138
+
139
+ assert status.success?
140
+ assert_empty stderr
141
+
142
+ assert_includes stdout, "Loading site from path #{Dir.pwd} ... done."
143
+ assert_includes stdout, "Found geb site at path #{Dir.pwd}"
144
+ assert_match(/Building \d* pages for/, stdout)
145
+ assert_includes stdout, "loading page"
146
+ assert_includes stdout, "loading template"
147
+ assert_includes stdout, "loading partial"
148
+ assert_includes stdout, "building page"
149
+ assert_match(/Done building \d* pages for/, stdout)
150
+ assert_includes stdout, "Clearing site output folder"
151
+ assert_match(/Outputting site to.*done/, stdout)
152
+ assert_includes stdout, "Building assets for"
153
+ assert_includes stdout, "Done building assets for"
154
+ assert_match(/Clearing site release folder.*done/, stdout)
155
+ assert_match(/Releasing site to.*done/, stdout)
156
+ assert_match(/Resolving directories and files to include in the template archive.*done/, stdout)
157
+ assert_match(/copying directory and all sub-directories from.*to.*done/, stdout)
158
+ assert_match(/copying file from.*to.*done/, stdout)
159
+ assert_includes stdout, "Done copying directories and files to the template archive directory."
160
+ assert_match(/Creating template archive in.*done/, stdout)
161
+
162
+ assert File.exist?(output_archive_filename)
163
+
164
+ end # test "that the command actually builds the site with a template"
165
+
166
+ end # class TestGebCommandRelease < Minitest::Test
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the remote command class
4
+ #
5
+ # @title Geb - Test - Remote Command
6
+ # @author Edin Mustajbegovic <edin@actiontwelve.com>
7
+ # @copyright 2024 Edin Mustajbegovic
8
+ # @license MIT
9
+ #
10
+ # @see https://github.com/mainfram-work/geb for more information
11
+
12
+ require "test_helper"
13
+
14
+ class TestGebCommandRemote < Geb::CliTest
15
+
16
+ test "that the CLI api call works" do
17
+
18
+ copy_test_site()
19
+
20
+ command = Geb::CLI::Commands::Remote.new
21
+
22
+ command_options = { }
23
+
24
+ original_stdout = $stdout
25
+ original_stderr = $stderr
26
+
27
+ $stdout = StringIO.new
28
+ $stderr = StringIO.new
29
+
30
+ Open3.expects(:capture3).with("ssh", "user@server.com").returns(["", "", ""])
31
+
32
+ command.call(**command_options)
33
+
34
+ assert_empty $stderr.string
35
+
36
+ $stdout = original_stdout
37
+ $stderr = original_stderr
38
+
39
+ end # test "that the CLI api call works"
40
+
41
+ test "that the CLI api call works with an error" do
42
+
43
+ copy_test_site()
44
+
45
+ command = Geb::CLI::Commands::Remote.new
46
+
47
+ command_options = { }
48
+
49
+ original_stdout = $stdout
50
+ original_stderr = $stderr
51
+
52
+ $stdout = StringIO.new
53
+ $stderr = StringIO.new
54
+
55
+ Geb::Site.expects(:new).raises(Geb::Error.new("Site not loaded"))
56
+
57
+ command.call(**command_options)
58
+
59
+ assert_match(/Site not loaded/, $stderr.string)
60
+
61
+ $stdout = original_stdout
62
+ $stderr = original_stderr
63
+
64
+ end # test "that the CLI api call works with an error"
65
+
66
+ end # class TestGebCommandRemote < Minitest::Test
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the server command class
4
+ #
5
+ # @title Geb - Test - Server Command
6
+ # @author Edin Mustajbegovic <edin@actiontwelve.com>
7
+ # @copyright 2024 Edin Mustajbegovic
8
+ # @license MIT
9
+ #
10
+ # @see https://github.com/mainfram-work/geb for more information
11
+
12
+ require "test_helper"
13
+
14
+ class TestGebCommandServer < Geb::CliTest
15
+
16
+ test "that the CLI api call works" do
17
+
18
+ copy_test_site()
19
+
20
+ command = Geb::CLI::Commands::Server.new
21
+ server_port = Geb::Test::WebServerProxy.find_available_port()
22
+
23
+ command_options = { port: server_port, skip_build: false, skip_auto_build: false }
24
+
25
+ original_stdout = $stdout
26
+ original_stderr = $stderr
27
+
28
+ $stdout = StringIO.new
29
+ $stderr = StringIO.new
30
+
31
+ server_thread = Thread.new do
32
+ command.call(**command_options)
33
+ end
34
+
35
+ sleep 2
36
+
37
+ command.force_shutdown()
38
+ server_thread.join
39
+
40
+ assert_includes($stdout.string, "Loading site from path #{Dir.pwd}")
41
+ assert_includes($stdout.string, "Server running on http://localhost:#{@port}")
42
+ assert_includes($stdout.string, "Watching for changes in [#{Dir.pwd}]")
43
+
44
+ $stdout = original_stdout
45
+ $stderr = original_stderr
46
+
47
+ end # test "that the CLI api call works"
48
+
49
+ test "that the CLI api call works when an error is thrown" do
50
+
51
+ # copy_test_site() # no site, so it should fail
52
+
53
+ command = Geb::CLI::Commands::Server.new
54
+ server_port = Geb::Test::WebServerProxy.find_available_port()
55
+
56
+ command_options = { port: server_port, skip_build: false, skip_auto_build: false }
57
+
58
+ original_stdout = $stdout
59
+ original_stderr = $stderr
60
+
61
+ $stdout = StringIO.new
62
+ $stderr = StringIO.new
63
+
64
+ server_thread = Thread.new do
65
+ command.call(**command_options)
66
+ end
67
+
68
+ sleep 2
69
+
70
+ command.force_shutdown()
71
+ server_thread.join
72
+
73
+ refute_empty $stderr.string
74
+ assert_includes($stdout.string, "Loading site from path #{Dir.pwd}")
75
+ refute_includes($stdout.string, "Server running on http://localhost:#{@port}")
76
+ refute_includes($stdout.string, "Watching for changes in [#{Dir.pwd}]")
77
+
78
+ $stdout = original_stdout
79
+ $stderr = original_stderr
80
+
81
+ end # test "that the CLI api call works when an error is thrown"
82
+
83
+ test "that command default executes" do
84
+
85
+ copy_test_site()
86
+ server_port = Geb::Test::WebServerProxy.find_available_port()
87
+ geb_command = "geb server --port #{server_port}"
88
+
89
+ server_up = lambda do |output, error_output|
90
+ output.include?("Server running on http://localhost:#{server_port}")
91
+ end
92
+
93
+ run_command_with_timeout(geb_command, break_condition: server_up) do |output, error_output|
94
+
95
+ assert_includes output, "Loading site from path #{Dir.pwd}"
96
+ assert_includes output, "Server running on http://localhost:#{server_port}"
97
+ assert_includes output, "Watching for changes in [#{Dir.pwd}]"
98
+
99
+ end # run_command_with_timeout
100
+
101
+ end # test "that command default executes"
102
+
103
+ test "that command handles being executed in a non-site directory" do
104
+
105
+ # create a temporary directory
106
+ Dir.mktmpdir do |dir|
107
+
108
+ # change the current directory to the temporary directory
109
+ Dir.chdir(dir)
110
+
111
+ # call geb auto command and capture output and error
112
+ _, stderr, status = Open3.capture3('geb server')
113
+
114
+ # assert that the output contains the expected string
115
+ assert status.success?
116
+ assert_includes stderr, "is not and is not in a geb site. Could not find geb config file."
117
+
118
+ end # Dir.mktmpdir
119
+
120
+ end # test "that command handles being executed in a non-site directory"
121
+
122
+ end # class TestGebCommandServer < Minitest::Test