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,1315 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the site class
4
+ #
5
+ # @title Geb - Test - Site
6
+ # @author Edin Mustajbegovic <edin@actiontwelve.com>
7
+ # @copyright 2024 Edin Mustajbegovic
8
+ # @license MIT
9
+ #
10
+ # @todo Probably should break these tests into multiple classes, in line with class having modules.
11
+ #
12
+ # @see https://github.com/mainfram-work/geb for more information
13
+
14
+ require "test_helper"
15
+
16
+ class SiteTest < Geb::ApiTest
17
+
18
+ test "that site default initializes" do
19
+
20
+ site = Geb::Site.new
21
+
22
+ assert_instance_of Geb::Site, site
23
+ assert_nil site.site_path
24
+ assert_nil site.template_path
25
+
26
+ end # test "that site default initializes"
27
+
28
+ test "that site validate method sets site path and template path" do
29
+
30
+ site = Geb::Site.new
31
+ test_site_path = "test/site"
32
+
33
+ site.stubs(:site_directory_exists?).returns(false)
34
+ site.validate(test_site_path, nil, true)
35
+ assert test_site_path, site.site_path
36
+ assert_nil site.template_path
37
+ assert site.validated
38
+
39
+ end # test "that site validate method sets site path and template path"
40
+
41
+ test "that site validate method throws an exception if called on validated site" do
42
+
43
+ site = Geb::Site.new
44
+ test_site_path = "test/site"
45
+
46
+ site.stubs(:site_directory_exists?).returns(false)
47
+
48
+ site.validate(test_site_path, nil, true)
49
+
50
+ assert test_site_path, site.site_path
51
+ assert_nil site.template_path
52
+ assert site.validated
53
+
54
+ assert_raises Geb::Site::SiteAlreadyValidated do
55
+ site.validate(test_site_path, nil, true)
56
+ end # assert_raises
57
+
58
+ end # test "that site validates method throws an exception if called on validated site"
59
+
60
+ test "that site validates method throws an exception if site directory exists and force flag is false" do
61
+
62
+ site = Geb::Site.new
63
+ test_site_path = "test/site"
64
+
65
+ site.stubs(:site_directory_exists?).returns(true)
66
+ assert_raises Geb::Site::DirectoryExistsError do
67
+ site.validate(test_site_path, nil, true)
68
+ end # assert_raises
69
+ assert_nil site.site_path
70
+ assert_nil site.template_path
71
+ refute site.validated
72
+
73
+ end # test "that site validates method throws an exception if site directory exists and force flag is false"
74
+
75
+ test "test site validates and uses default template if the template is not specified" do
76
+
77
+ site = Geb::Site.new
78
+ test_site_path = "tmp/test_site"
79
+
80
+ Geb::Config.stubs(:site_directory_exists?).returns(false)
81
+
82
+ site.validate(test_site_path)
83
+
84
+ assert_equal site.site_path, test_site_path
85
+ assert site.template_path.end_with?(Geb::Defaults::DEFAULT_TEMPLATE)
86
+
87
+ end # test "test site validates and uses default template if the template is not specified"
88
+
89
+ test "test site validates and uses specified template if the template is specified" do
90
+
91
+ site = Geb::Site.new
92
+ test_site_path = "tmp/test_site"
93
+ test_template = "/not/real/template"
94
+
95
+ site.stubs(:site_directory_exists?).returns(false)
96
+ site.stubs(:template_directory_exists?).returns(true)
97
+ site.stubs(:is_bundled_template?).returns(false)
98
+ Geb::Config.stubs(:site_directory_has_config?).returns(true)
99
+
100
+ site.validate(test_site_path, test_template)
101
+
102
+ assert_equal site.site_path, test_site_path
103
+ assert_equal site.template_path, test_template
104
+ assert site.validated
105
+
106
+ end # test "test site validates and uses specified template if the template is specified"
107
+
108
+ test "test site validates and uses the URL template specified" do
109
+
110
+ site = Geb::Site.new
111
+ test_site_path = "tmp/test_site"
112
+ test_template_url = "http://www.example.com/template.tar.gz"
113
+ test_template_dir = "/var/tmp/downloaded/template"
114
+
115
+ site.stubs(:validate_template_url).returns(test_template_url)
116
+ site.stubs(:download_template_from_url).returns(test_template_dir)
117
+ site.stubs(:template_directory_exists?).returns(true)
118
+ Geb::Config.stubs(:site_directory_has_config?).returns(true)
119
+
120
+ site.validate(test_site_path, test_template_url)
121
+
122
+ assert_equal site.site_path, test_site_path
123
+ assert_equal site.template_path, test_template_dir
124
+ assert site.validated
125
+
126
+ end # test "test site validates and uses the URL template specified"
127
+
128
+ test "test site validates and uses the bundle template identifier specified" do
129
+
130
+ site = Geb::Site.new
131
+ test_site_path = "tmp/test_site"
132
+ test_template = "bootstrap_jquery"
133
+
134
+ site.validate(test_site_path, test_template)
135
+
136
+ assert_equal site.site_path, test_site_path
137
+ assert site.template_path.end_with?(test_template)
138
+ assert site.validated
139
+
140
+ end # test "test site validates and uses the bundle template identifier specified"
141
+
142
+ test "that template url validation doesn't through any exceptions when it has a working URL" do
143
+
144
+ site = Geb::Site.new
145
+ test_template_url = "http://www.example.com/"+ Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME
146
+
147
+ stub_request(:get, test_template_url).to_return(body: "<html></html>", headers: { 'Content-Type' => 'application/x-gzip' })
148
+
149
+ validated_test_template_url = site.send(:validate_template_url, test_template_url)
150
+
151
+ assert_equal test_template_url, validated_test_template_url
152
+
153
+ end # test "that template url validation doesn't through any exceptions when it has a working URL"
154
+
155
+ test "that template url validation retries with archive filename after first URL query fails" do
156
+
157
+ site = Geb::Site.new
158
+ test_template_url = "http://www.example.com/"
159
+
160
+ stub_request(:get, test_template_url).to_return(body: "<html></html>", headers: { 'Content-Type' => 'text/html' })
161
+ stub_request(:get, test_template_url + Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME).to_return(body: "<html></html>", headers: { 'Content-Type' => 'application/x-gzip' })
162
+
163
+ validated_test_template_url = site.send(:validate_template_url, test_template_url)
164
+
165
+ assert_equal test_template_url + Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME, validated_test_template_url
166
+
167
+ end # test "that template url validation retries with archive filename after first URL query fails"
168
+
169
+ test "that the template url validation throws an exception if the http request fails" do
170
+
171
+ site = Geb::Site.new
172
+ test_template_url = "http://www.example.com/"
173
+
174
+ site.stubs(:fetch_http_response).raises(Geb::Site::InvalidTemplateURL)
175
+
176
+ assert_raises Geb::Site::InvalidTemplateURL do
177
+ site.send(:validate_template_url, test_template_url)
178
+ end # assert_raises
179
+
180
+ end # test "that the template url validation throws an exception if the http request fails"
181
+
182
+ test "that the template url validation correctly detects the template URL access was not successful" do
183
+
184
+ site = Geb::Site.new
185
+ test_template_url = "http://www.example.com/"
186
+
187
+ response_mock = mock()
188
+ response_mock.stubs(:body).returns("<html></html>")
189
+ response_mock.stubs(:headers).returns({ 'Content-Type' => 'application/x-gzip' })
190
+ response_mock.stubs(:[]).with('Content-Type').returns('application/x-gzip') # Stubbing hash-like access to 'Content-Type'
191
+ response_mock.stubs(:is_a?).with(Net::HTTPSuccess).returns(false)
192
+ response_mock.stubs(:code).returns("404")
193
+ site.expects(:fetch_http_response).returns(response_mock).times(2) # expecting a retry
194
+
195
+ error = assert_raises Geb::Site::InvalidTemplateURL do
196
+ site.send(:validate_template_url, test_template_url)
197
+ end # assert_raises
198
+
199
+ assert_includes error.message, "Web server returned 404"
200
+
201
+ end # test "that the template url validation correctly detects the template URL access was not successful"
202
+
203
+ test "that the template url validation correctly detects the template URL is not an archive" do
204
+
205
+ site = Geb::Site.new
206
+ test_template_url = "http://www.example.com/"
207
+
208
+ response_mock = mock()
209
+ response_mock.stubs(:body).returns("<html></html>")
210
+ response_mock.stubs(:headers).returns({ 'Content-Type' => 'text/html' })
211
+ response_mock.stubs(:[]).with('Content-Type').returns('text/html') # Stubbing hash-like access to 'Content-Type'
212
+ response_mock.stubs(:is_a?).with(Net::HTTPSuccess).returns(true)
213
+ site.expects(:fetch_http_response).returns(response_mock).times(2) # expecting a retry
214
+
215
+ error = assert_raises Geb::Site::InvalidTemplateURL do
216
+ site.send(:validate_template_url, test_template_url)
217
+ end # assert_raises
218
+
219
+ assert_includes error.message, "Specified template is not a gzip archive"
220
+
221
+
222
+ end # test "that the template url validation correctly detects the template URL is not an archive"
223
+
224
+ test "that the template url validation correctly retries and doesn't retry depending on the archive url" do
225
+
226
+ site = Geb::Site.new
227
+ test_template_url_should_retry = "http://www.examples.com/"
228
+ test_template_url_should_not_retry = "http://www.examples.com/"+ Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME
229
+
230
+ http_success_sequence = sequence('http_success_sequence')
231
+ response_mock_first_fail = mock()
232
+ response_mock_first_fail.stubs(:body).returns("<html></html>")
233
+ response_mock_first_fail.stubs(:headers).returns({ 'Content-Type' => 'application/x-gzip' })
234
+ response_mock_first_fail.stubs(:[]).with('Content-Type').returns('application/x-gzip') # Stubbing hash-like access to 'Content-Type'
235
+ response_mock_first_fail.stubs(:is_a?).with(Net::HTTPSuccess).returns(false)
236
+ response_mock_first_fail.stubs(:code).returns("200")
237
+ response_mock_second_ok = mock()
238
+ response_mock_second_ok.stubs(:body).returns("<html></html>")
239
+ response_mock_second_ok.stubs(:headers).returns({ 'Content-Type' => 'application/x-gzip' })
240
+ response_mock_second_ok.stubs(:[]).with('Content-Type').returns('application/x-gzip') # Stubbing hash-like access to 'Content-Type'
241
+ response_mock_second_ok.stubs(:is_a?).with(Net::HTTPSuccess).returns(true)
242
+ response_mock_second_ok.stubs(:code).returns("200")
243
+
244
+ site.expects(:fetch_http_response).returns(response_mock_first_fail).once.in_sequence(http_success_sequence) # expecting a retry
245
+ site.expects(:fetch_http_response).returns(response_mock_second_ok).once.in_sequence(http_success_sequence) # expecting a retry
246
+
247
+ validated_template_url = site.send(:validate_template_url, test_template_url_should_retry)
248
+ assert_equal validated_template_url, test_template_url_should_retry + Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME
249
+
250
+ site.expects(:fetch_http_response).returns(response_mock_second_ok).once # expecting no retry
251
+
252
+ validated_template_url = site.send(:validate_template_url, test_template_url_should_not_retry)
253
+
254
+ assert_equal test_template_url_should_not_retry, validated_template_url
255
+
256
+ end # test "that the template url validation correctly retries and doesn't retry depending on the archive url"
257
+
258
+ test "that the fetch http response method returns a response object" do
259
+
260
+ site = Geb::Site.new
261
+ test_template_url = "http://www.example.com/"
262
+
263
+ # mock the http response
264
+ stub_request(:get, test_template_url).to_return(body: "<html></html>", headers: { 'Content-Type' => 'text/html' })
265
+
266
+ response = site.send(:fetch_http_response, test_template_url)
267
+
268
+ assert_instance_of Net::HTTPOK, response
269
+
270
+ end # test "that the fetch http response method returns a response object"
271
+
272
+ test "that the fetch http response method throws an exception if the http request fails" do
273
+
274
+ site = Geb::Site.new
275
+ test_template_url = "http://www.example.com/"
276
+
277
+ # stub the Net::HTTP.get_response to raise an exception
278
+ Net::HTTP.stubs(:get_response).raises(StandardError.new("HTTP request failed"))
279
+
280
+ error = assert_raises Geb::Site::InvalidTemplateURL do
281
+ site.send(:fetch_http_response, test_template_url)
282
+ end # assert_raises
283
+
284
+ assert_includes error.message, "HTTP request failed"
285
+
286
+ end # test "that the fetch http response method throws an exception if the http request fails"
287
+
288
+ test "that the download template actually downloads and extracts the template" do
289
+
290
+ site = Geb::Site.new
291
+ test_template_url = "http://www.example.com/"
292
+
293
+ # stub the http request to return a gzip archive from test files folder
294
+ stub_request(:get, test_template_url)
295
+ .to_return(body: File.open(File.expand_path("../../files/geb-template.tar.gz", __FILE__)).read,
296
+ headers: { 'Content-Type' => 'application/x-gzip' })
297
+
298
+ template_directory = site.send(:download_template_from_url, test_template_url)
299
+
300
+ refute_empty Dir.glob("#{template_directory}/*")
301
+
302
+ end # test "that the download template actually downloads and extracts the template"
303
+
304
+ test "that the download template throws an exception if the download fails" do
305
+
306
+ site = Geb::Site.new
307
+ test_template_url = "http://www.example.com/"
308
+
309
+ # stub the http request to return a gzip archive from test files folder
310
+ stub_request(:get, test_template_url)
311
+ .to_return(body: "Not Found", status: 404, headers: { 'Content-Type' => 'application/x-gzip' })
312
+
313
+ error = assert_raises Geb::Site::InvalidTemplateURL do
314
+ site.send(:download_template_from_url, test_template_url)
315
+ end # assert_raises
316
+
317
+ assert_includes error.message, "Failed to extract template archive: tar: Error opening archive"
318
+
319
+ end # test "that the download template throws an exception if the download fails"
320
+
321
+ test "that the download template throws an exception if the archive is not a gzip archive" do
322
+
323
+ site = Geb::Site.new
324
+ test_template_url = "http://www.example.com/"
325
+
326
+ # stub the http request to return a gzip archive from test files folder
327
+ stub_request(:get, test_template_url)
328
+ .to_return(body: "Actially a gip file",
329
+ headers: { 'Content-Type' => 'text/plain' })
330
+
331
+ error = assert_raises Geb::Site::InvalidTemplateURL do
332
+ site.send(:download_template_from_url, test_template_url)
333
+ end # assert_raises
334
+
335
+ assert_includes error.message, "Failed to extract template archive: tar: Error opening archive"
336
+
337
+ end # test "that the download template throws an exception if the archive is not a gzip archive"
338
+
339
+ test "that the create site method raises an exception if the site is not validated" do
340
+
341
+ site = Geb::Site.new
342
+
343
+ assert_raises Geb::Site::UnvalidatedSiteAndTemplate do
344
+ site.create
345
+ end # assert_raises
346
+
347
+ end # test "that the create site method raises an exception if the site is not validated"
348
+
349
+ test "that the create site method creates a site folder without a template" do
350
+
351
+ site = Geb::Site.new
352
+ test_site_path = "test_site"
353
+
354
+ Dir.mktmpdir do |temp_dir|
355
+
356
+ site.instance_variable_set(:@validated, true)
357
+ site.instance_variable_set(:@site_path, File.join(temp_dir, test_site_path))
358
+ site.instance_variable_set(:@template_path, nil)
359
+ Geb::stubs(:site_directory_has_config?).returns(true)
360
+
361
+ site.create
362
+
363
+ assert Dir.exist?(site.site_path)
364
+ assert Dir.exist?(File.join(site.site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
365
+ assert Dir.exist?(File.join(site.site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR))
366
+
367
+ end # Dir.mktmpdir
368
+
369
+ end # test "that the create site method creates a site folder without a template"
370
+
371
+ test "that the create site method creates a site folder with a template" do
372
+
373
+ site = Geb::Site.new
374
+ test_site_path = "test_site"
375
+
376
+ Dir.mktmpdir do |temp_dir|
377
+
378
+ test_template_path = File.join(temp_dir, "test_template")
379
+ Dir.mkdir(test_template_path)
380
+
381
+ template_paths = []
382
+ template_paths << File.join("assets")
383
+ template_paths << File.join("shared")
384
+ template_paths << File.join("index.html")
385
+ template_paths << File.join("site.webmanifest")
386
+ template_paths << File.join("shared/_header.html")
387
+ template_paths << File.join("shared/_footer.html")
388
+ template_paths.each do |path|
389
+ if path !~ /\./
390
+ FileUtils.mkdir_p(File.join(test_template_path, path))
391
+ else
392
+ FileUtils.mkdir_p(File.dirname(File.join(test_template_path, path)))
393
+ File.open(File.join(test_template_path, path), "w") do |file|
394
+ file.write("This is a dumny file path: #{path}")
395
+ end
396
+ end
397
+ end
398
+ File.open(File.join(test_template_path, Geb::Defaults::SITE_CONFIG_FILENAME), "w") do |file|
399
+ file.write("\n")
400
+ file.write('template_paths: ["assets", "shared", "*.html", "site.webmanifest", "geb.config.yml"]')
401
+ file.write("\n")
402
+ end
403
+
404
+ Geb::stubs(:site_directory_has_config?).returns(true)
405
+ site.instance_variable_set(:@validated, true)
406
+ site.instance_variable_set(:@site_path, File.join(temp_dir, test_site_path))
407
+ site.instance_variable_set(:@template_path, test_template_path)
408
+
409
+ template_paths.each do |path|
410
+ if path !~ /\./
411
+ refute Dir.exist?(File.join(site.site_path, path))
412
+ else
413
+ refute File.exist?(File.join(site.site_path, path))
414
+ end
415
+ end
416
+
417
+ site.create
418
+
419
+ assert Dir.exist?(site.site_path)
420
+ template_paths.each do |path|
421
+ if path !~ /\./
422
+ assert Dir.exist?(File.join(site.site_path, path))
423
+ else
424
+ assert File.exist?(File.join(site.site_path, path))
425
+ File.open(File.join(site.site_path, path), "r") do |file|
426
+ assert_equal file.read, "This is a dumny file path: #{path}"
427
+ end
428
+ end
429
+ end
430
+
431
+ assert Dir.exist?(File.join(site.site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
432
+ assert Dir.exist?(File.join(site.site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR))
433
+
434
+ end # Dir.mktmpdir
435
+
436
+ end # test "that the create site method creates a site folder with a template"
437
+
438
+ test "that the create site method skips the site directory folder creation if folder already exists" do
439
+
440
+ site = Geb::Site.new
441
+ test_site_path = "test_site"
442
+
443
+ site.expects(:site_directory_exists?).returns(true)
444
+
445
+ Dir.mktmpdir do |temp_dir|
446
+
447
+ site.instance_variable_set(:@validated, true)
448
+ site.instance_variable_set(:@site_path, File.join(temp_dir, test_site_path))
449
+ site.instance_variable_set(:@template_path, nil)
450
+ Geb::stubs(:site_directory_has_config?).returns(true)
451
+
452
+ FileUtils.mkdir_p(site.site_path)
453
+
454
+ site.create
455
+
456
+ assert Dir.exist?(site.site_path)
457
+ assert Dir.exist?(File.join(site.site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
458
+ assert Dir.exist?(File.join(site.site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR))
459
+
460
+ end # Dir.mktmpdir
461
+
462
+ end # test "that the create site method skips the site directory folder creation if folder already exists"
463
+
464
+ test "that the load site method loads the site successfully from the current working directory" do
465
+
466
+ site = Geb::Site.new
467
+ test_site_path = "test/site"
468
+
469
+ config = mock('config')
470
+ config.stubs(:site_name).returns("site")
471
+ Geb::Config.stubs(:site_directory_has_config?).returns(true)
472
+ Geb::Config.stubs(:new).returns(config)
473
+
474
+ site.load(test_site_path)
475
+
476
+ assert_equal site.site_path, test_site_path
477
+ assert site.loaded
478
+
479
+ end # test "that the load site method works as expected"
480
+
481
+ test "that the load site method looks up the chain to find the site directory" do
482
+
483
+ site = Geb::Site.new
484
+ test_site_path = "find/site/here/nothere"
485
+
486
+ template_dir_sequence = sequence('template_directory_has_config_sequence')
487
+
488
+ config = mock('config')
489
+ config.stubs(:site_name).returns("nothere")
490
+ Geb::Config.stubs(:site_directory_has_config?).returns(false).once.in_sequence(template_dir_sequence)
491
+ Geb::Config.stubs(:site_directory_has_config?).returns(true).once.in_sequence(template_dir_sequence)
492
+ Geb::Config.stubs(:new).returns(config).once
493
+
494
+ site.load(test_site_path)
495
+
496
+ full_site_path = File.join(Dir.pwd, test_site_path)
497
+
498
+ assert_equal site.site_path, full_site_path.gsub('/nothere', '')
499
+ assert site.loaded
500
+
501
+ end # test "that the load site method looks up the chain to find the site directory"
502
+
503
+ test "that the load site throws an exception if the site directory is not found" do
504
+
505
+ site = Geb::Site.new
506
+ test_site_path = "test/site"
507
+
508
+ site.stubs(:site_directory_exists?).returns(false)
509
+
510
+ error = assert_raises Geb::Site::SiteNotFoundError do
511
+ site.load(test_site_path)
512
+ end # assert_raises
513
+
514
+ assert_includes error.message, "is not and is not in a geb site"
515
+
516
+ end # test "that the load site throws an exception if the site directory is not found"
517
+
518
+ test "that the build pages method builds the pages successfully" do
519
+
520
+ site = Geb::Site.new
521
+ test_site_path = "test/site"
522
+
523
+ site_pages = ["index.html", "about.html", "contact.html"]
524
+
525
+ config = mock('config')
526
+ config.stubs(:site_name).returns("site")
527
+ config.stubs(:output_dir).returns("output")
528
+ config.stubs(:page_extensions).returns(Geb::Defaults::PAGE_EXTENSIONS)
529
+ config.stubs(:template_and_partial_identifier).returns(Geb::Defaults::TEMPLATE_AND_PARTIAL_IDENTIFIER)
530
+ site.instance_variable_set(:@loaded, true)
531
+ site.instance_variable_set(:@site_path, test_site_path)
532
+ site.instance_variable_set(:@site_config, config)
533
+ site.expects(:get_page_files).returns(site_pages)
534
+ site.expects(:clear_site_output_directory).once
535
+ site.expects(:output_site).once
536
+
537
+ page_build_sequence = sequence('page_build_sequence')
538
+ mock_page = mock('page')
539
+
540
+ site_pages.each { |page| Geb::Page.expects(:new).with(site, page).returns(mock_page).once.in_sequence(page_build_sequence) }
541
+ mock_page.expects(:build).times(site_pages.length)
542
+
543
+ site.build_pages
544
+
545
+ end # test "that the build pages method builds the pages successfully"
546
+
547
+ test "that the build pages method throws an exception if site is not loaded" do
548
+
549
+ site = Geb::Site.new
550
+
551
+ site_pages = ["index.html", "about.html", "contact.html"]
552
+
553
+ mock_pages = {}
554
+ site_pages.each { |page| mock_pages[page] = mock('page') }
555
+
556
+ site.instance_variable_set(:@pages, mock_pages)
557
+ site.instance_variable_set(:@loaded, false)
558
+
559
+ assert_equal site_pages.length, site.pages.length
560
+
561
+ error = assert_raises Geb::Site::SiteNotLoadedError do
562
+ site.build_pages
563
+ end # assert_raises
564
+
565
+ assert_includes error.message, "Could not build pages"
566
+
567
+ end # test "that the build pages method throws an exception if site is not loaded"
568
+
569
+ test "that the build pages method throws an exception clear site output throws an exception" do
570
+
571
+ site = Geb::Site.new
572
+ test_site_path = "test/site"
573
+
574
+ site_pages = ["index.html", "about.html", "contact.html"]
575
+
576
+ config = mock('config')
577
+ config.stubs(:site_name).returns("site")
578
+ config.stubs(:output_dir).returns("output")
579
+ config.stubs(:page_extensions).returns(Geb::Defaults::PAGE_EXTENSIONS)
580
+ config.stubs(:template_and_partial_identifier).returns(Geb::Defaults::TEMPLATE_AND_PARTIAL_IDENTIFIER)
581
+ page_mock = mock('page')
582
+ page_mock.expects(:build).times(site_pages.length)
583
+ Geb::Page.expects(:new).returns(page_mock).times(site_pages.length)
584
+
585
+ site.instance_variable_set(:@loaded, true)
586
+ site.instance_variable_set(:@site_path, test_site_path)
587
+ site.instance_variable_set(:@site_config, config)
588
+ site.expects(:get_page_files).returns(site_pages)
589
+ site.expects(:clear_site_output_directory).raises(StandardError.new("Failed to clear site output directory"))
590
+ site.expects(:output_site).never
591
+
592
+ error = assert_raises Geb::Site::FailedToOutputSite do
593
+ site.build_pages
594
+ end # assert_raises
595
+
596
+ assert_includes error.message, "Failed to clear site output directory"
597
+
598
+ end # test "that the build pages method throws an exception clear site output throws an exception"
599
+
600
+ test "that the build pages method throws an exception if the page output throws an exception" do
601
+
602
+ site = Geb::Site.new
603
+ test_site_path = "test/site"
604
+
605
+ site_pages = ["index.html", "about.html", "contact.html"]
606
+
607
+ config = mock('config')
608
+ config.stubs(:site_name).returns("site")
609
+ config.stubs(:output_dir).returns("output")
610
+ config.stubs(:page_extensions).returns(Geb::Defaults::PAGE_EXTENSIONS)
611
+ config.stubs(:template_and_partial_identifier).returns(Geb::Defaults::TEMPLATE_AND_PARTIAL_IDENTIFIER)
612
+
613
+ page_mock = mock('page')
614
+ page_mock.expects(:build).times(site_pages.length)
615
+ Geb::Page.expects(:new).returns(page_mock).times(site_pages.length)
616
+
617
+ site.instance_variable_set(:@loaded, true)
618
+ site.instance_variable_set(:@site_path, test_site_path)
619
+ site.instance_variable_set(:@site_config, config)
620
+ site.expects(:get_page_files).returns(site_pages)
621
+ site.expects(:clear_site_output_directory).once
622
+ site.expects(:output_site).raises(StandardError.new("Failed to output site."))
623
+
624
+ error = assert_raises Geb::Site::FailedToOutputSite do
625
+ site.build_pages
626
+ end # assert_raises
627
+
628
+ assert_includes error.message, "Failed to output site"
629
+
630
+ end # test "that the build pages method throws an exception if the page output throws an exception"
631
+
632
+ test "that get page files method returns a list of page files using defaults" do
633
+
634
+ site = Geb::Site.new
635
+ test_site_path = "test/site"
636
+
637
+ Dir.mktmpdir do |temp_dir|
638
+
639
+ site_path = File.join(temp_dir, test_site_path)
640
+
641
+ site_pages = []
642
+ site_pages << File.join(site_path, "index.html")
643
+ site_pages << File.join(site_path, "about.html")
644
+ site_pages << File.join(site_path, "contact.html")
645
+ site_pages << File.join(site_path, "sub/page.html")
646
+ site_pages << File.join(site_path, "sub/sub/page.html")
647
+ site_pages.sort!
648
+
649
+ FileUtils.mkdir_p(site_path)
650
+
651
+ site_pages.each do |page|
652
+ FileUtils.mkdir_p(File.dirname(page))
653
+ FileUtils.touch(page)
654
+ end
655
+
656
+ pages = site.send(:get_page_files, site_path)
657
+
658
+ assert_equal site_pages, pages
659
+
660
+ end # Dir.mktmpdir
661
+
662
+ end # test "that get page files method returns a list of page files using defaults"
663
+
664
+ test "that get page files method returns a list of page files using custom page extension" do
665
+
666
+ site = Geb::Site.new
667
+ test_site_path = "test/site"
668
+ test_page_extension = [".htm"]
669
+
670
+ Dir.mktmpdir do |temp_dir|
671
+
672
+ site_path = File.join(temp_dir, test_site_path)
673
+
674
+ site_pages = []
675
+ site_pages << File.join(site_path, "index.htm")
676
+ site_pages << File.join(site_path, "about.html")
677
+ site_pages << File.join(site_path, "contact.htm")
678
+ site_pages << File.join(site_path, "sub/page.htm")
679
+ site_pages << File.join(site_path, "sub/sub/page.html")
680
+ site_pages.sort!
681
+
682
+ FileUtils.mkdir_p(site_path)
683
+
684
+ site_pages.each do |page|
685
+ FileUtils.mkdir_p(File.dirname(page))
686
+ FileUtils.touch(page)
687
+ end
688
+
689
+ pages = site.send(:get_page_files, site_path, test_page_extension)
690
+
691
+ assert_equal site_pages.length - 2, pages.length
692
+
693
+ end # Dir.mktmpdir
694
+
695
+ end # test "that get page files method returns a list of page files using custom page extension"
696
+
697
+ test "that the get page files method returns a list of page files while ignoring files with ignore pattern" do
698
+
699
+ site = Geb::Site.new
700
+ test_site_path = "test/site"
701
+ test_page_extension = [".htm"]
702
+ ignore_pattern = /^ignore_/
703
+
704
+ Dir.mktmpdir do |temp_dir|
705
+
706
+ site_path = File.join(temp_dir, test_site_path)
707
+
708
+ site_pages = []
709
+ site_pages << File.join(site_path, "index.htm") # not ignored
710
+ site_pages << File.join(site_path, "about.html") # not matched
711
+ site_pages << File.join(site_path, "ignore_contact.htm") # ignored
712
+ site_pages << File.join(site_path, "sub/page.htm") # not ignored
713
+ site_pages << File.join(site_path, "sub/sub/ignore_page.html") # ignored
714
+ site_pages.sort!
715
+
716
+ FileUtils.mkdir_p(site_path)
717
+
718
+ site_pages.each do |page|
719
+ FileUtils.mkdir_p(File.dirname(page))
720
+ FileUtils.touch(page)
721
+ end
722
+
723
+ pages = site.send(:get_page_files, site_path, test_page_extension, ignore_pattern)
724
+
725
+ assert_equal site_pages.length - 3, pages.length
726
+
727
+ end # Dir.mktmpdir
728
+
729
+ end # test "that the get page files method returns a list of page files while ignoring files with ignore pattern"
730
+
731
+ test "that the get page files method returns a list of page files while ignoring directories specified" do
732
+
733
+ site = Geb::Site.new
734
+ test_site_path = "test/site"
735
+ test_page_extension = [".htm"]
736
+ ignore_pattern = /^ignore_/
737
+
738
+ Dir.mktmpdir do |temp_dir|
739
+
740
+ site_path = File.join(temp_dir, test_site_path)
741
+
742
+ site_pages = []
743
+ site_pages << File.join(site_path, "index.htm") # not ignored
744
+ site_pages << File.join(site_path, "about.html") # not matched
745
+ site_pages << File.join(site_path, "ignore_contact.htm") # ignored
746
+ site_pages << File.join(site_path, "sub/page.htm") # ignored (sub directory)
747
+ site_pages << File.join(site_path, "sub/sub/ignore_page.html") # ignored
748
+ site_pages.sort!
749
+
750
+ ignore_directories = []
751
+ ignore_directories << File.join(site_path, "sub")
752
+
753
+ FileUtils.mkdir_p(site_path)
754
+
755
+ site_pages.each do |page|
756
+ FileUtils.mkdir_p(File.dirname(page))
757
+ FileUtils.touch(page)
758
+ end
759
+
760
+ pages = site.send(:get_page_files, site_path, test_page_extension, ignore_pattern, ignore_directories)
761
+
762
+ assert_equal site_pages.length - 4, pages.length
763
+
764
+ end # Dir.mktmpdir
765
+
766
+ end # test "that the get page files method returns a list of page files while ignoring directories specified"
767
+
768
+ test "that the clear site output directory method clears the output directory" do
769
+
770
+ site = Geb::Site.new
771
+ test_site_path = "test/site"
772
+
773
+ Dir.mktmpdir do |temp_dir|
774
+
775
+ site_path = File.join(temp_dir, test_site_path)
776
+
777
+ FileUtils.mkdir_p(site_path)
778
+ FileUtils.mkdir_p(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
779
+
780
+ # generate some sub-directories and files in the output directory
781
+ FileUtils.mkdir_p(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR, "sub"))
782
+ FileUtils.touch(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR, "sub", "file1.html"))
783
+ FileUtils.touch(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR, "sub", "file2.html"))
784
+ FileUtils.touch(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR, "file3.html"))
785
+
786
+ config = mock('config')
787
+ config.stubs(:output_dir).returns("output")
788
+ site.instance_variable_set(:@site_path, site_path)
789
+ site.instance_variable_set(:@site_config, config)
790
+
791
+ site.send(:clear_site_output_directory)
792
+
793
+ # check to make sure all the files and directories are gone
794
+ refute Dir.exist?(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR, "sub"))
795
+ refute File.exist?(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR, "file3.html"))
796
+
797
+ end # Dir.mktmpdir
798
+
799
+ end # test "that the clear site output directory method clears the output directory"
800
+
801
+ test "that the output site method copies the local output directory to the release output directory" do
802
+
803
+ site = Geb::Site.new
804
+ test_site_path = "test/site"
805
+
806
+ Dir.mktmpdir do |temp_dir|
807
+
808
+ site_path = File.join(temp_dir, test_site_path)
809
+ very_temp_dir = File.join(temp_dir, "very_temp_dir")
810
+
811
+ FileUtils.mkdir_p(site_path)
812
+ FileUtils.mkdir_p(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR))
813
+
814
+ # generate some sub-directories and files in the output directory
815
+ FileUtils.mkdir_p(File.join(very_temp_dir, "sub"))
816
+ FileUtils.touch(File.join(very_temp_dir, "sub", "file1.html"))
817
+ FileUtils.touch(File.join(very_temp_dir, "sub", "file2.html"))
818
+ FileUtils.touch(File.join(very_temp_dir, "file3.html"))
819
+
820
+ config = mock('config')
821
+ config.stubs(:output_dir).returns("output")
822
+ site.instance_variable_set(:@site_path, site_path)
823
+ site.instance_variable_set(:@site_config, config)
824
+
825
+ site.send(:output_site, very_temp_dir)
826
+
827
+ # check to make sure all the files and directories are gone
828
+ assert Dir.exist?(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR, "sub"))
829
+ assert File.exist?(File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR, "file3.html"))
830
+
831
+ end # Dir.mktmpdir
832
+
833
+ end # test "that the output site method copies the local output directory to the release output directory"
834
+
835
+ test "that the release method executes the site build first" do
836
+
837
+ site = Geb::Site.new
838
+ test_site_path = "test/site"
839
+ test_site_release_dir = File.join(test_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR)
840
+
841
+ execution_sequence = sequence('execution_sequence')
842
+ site.expects(:build).once.in_sequence(execution_sequence)
843
+ site.expects(:get_site_release_directory).returns(test_site_release_dir).once.in_sequence(execution_sequence)
844
+ site.expects(:clear_site_release_directory).once.in_sequence(execution_sequence)
845
+ site.expects(:copy_site_to_release_directory).once.in_sequence(execution_sequence)
846
+
847
+ site.instance_variable_set(:@site_path, test_site_path)
848
+
849
+ site.release
850
+
851
+ end # test "that the release method executes the site build first"
852
+
853
+ test "that the site release directory is correctly generated" do
854
+
855
+ site = Geb::Site.new
856
+ test_site_path = "test/site"
857
+
858
+ config = mock('config')
859
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
860
+ site.instance_variable_set(:@site_path, test_site_path)
861
+ site.instance_variable_set(:@site_config, config)
862
+
863
+ site_release_directory = site.get_site_release_directory()
864
+
865
+ assert_equal File.join(test_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR), site_release_directory
866
+
867
+ end # test "that the site release directory is correctly generated"
868
+
869
+ test "that the site release calls correct file operations" do
870
+
871
+ site = Geb::Site.new
872
+ test_site_path = "test/site"
873
+ test_site_output_dir = File.join(test_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::LOCAL_OUTPUT_DIR)
874
+ test_site_release_dir = File.join(test_site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR)
875
+
876
+ execution_sequence = sequence('execution_sequence')
877
+ site.expects(:build).once
878
+ site.stubs(:get_site_release_directory).returns(test_site_release_dir)
879
+ FileUtils.expects(:rm_rf).with(Dir.glob("#{test_site_release_dir}/*")).once.in_sequence(execution_sequence)
880
+ FileUtils.expects(:cp_r).with("#{test_site_output_dir}/.", test_site_release_dir).once.in_sequence(execution_sequence)
881
+
882
+ config = mock('config')
883
+ config.stubs(:output_dir).returns("output")
884
+ site.instance_variable_set(:@site_path, test_site_path)
885
+ site.instance_variable_set(:@site_config, config)
886
+
887
+ site.release
888
+
889
+ end # test "that the site release calls correct file operations"
890
+
891
+ test "that site bundle template method executes as expected" do
892
+
893
+ site = Geb::Site.new
894
+ test_site_path = "test/site"
895
+
896
+ template_paths_config = ["assets", "shared", "*.html", "site.webmanifest", "geb.config.yml"]
897
+ template_file_paths = template_paths_config.map { |path| File.join(test_site_path, path) }
898
+
899
+ config = mock('config')
900
+ config.stubs(:template_paths).returns(template_paths_config)
901
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
902
+ site.instance_variable_set(:@site_path, test_site_path)
903
+ site.instance_variable_set(:@loaded, true)
904
+ site.instance_variable_set(:@site_config, config)
905
+ Dir.stubs(:glob).returns(template_file_paths)
906
+ Geb.expects(:copy_paths_to_directory)
907
+ Open3.expects(:capture3)
908
+
909
+ site.bundle_template()
910
+
911
+ end # test "that site bundle template method executes as expected"
912
+
913
+ test "that the site bundle template method throws an exception if the site is not loaded" do
914
+
915
+ site = Geb::Site.new
916
+ test_site_path = "test/site"
917
+
918
+ template_paths_config = ["assets", "shared", "*.html", "site.webmanifest", "geb.config.yml"]
919
+
920
+ config = mock('config')
921
+ config.stubs(:template_paths).returns(template_paths_config)
922
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
923
+ site.instance_variable_set(:@site_path, test_site_path)
924
+ site.instance_variable_set(:@loaded, false)
925
+
926
+ error = assert_raises Geb::Site::SiteNotFoundError do
927
+ site.bundle_template()
928
+ end
929
+
930
+ assert_includes error.message, "Site not loaded"
931
+
932
+ end # test "that the site bundle template method throws an exception if the site is not loaded"
933
+
934
+ test "that the site bundle template method throws an exception if the template paths are empty" do
935
+
936
+ site = Geb::Site.new
937
+ test_site_path = "test/site"
938
+
939
+ template_paths_config = ["assets", "shared", "*.html", "site.webmanifest", "geb.config.yml"]
940
+
941
+ config = mock('config')
942
+ config.stubs(:template_paths).returns(template_paths_config)
943
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
944
+ site.instance_variable_set(:@site_path, test_site_path)
945
+ site.instance_variable_set(:@site_config, config)
946
+ site.instance_variable_set(:@loaded, true)
947
+
948
+ error = assert_raises Geb::Site::InvalidTemplateSpecification do
949
+ site.bundle_template()
950
+ end
951
+
952
+ assert_includes error.message, "Config template_paths not specified."
953
+
954
+ end # test "that the site bundle template method throws an exception if the template paths are empty"
955
+
956
+ test "that the template archive release path is constructed correctly" do
957
+
958
+ site = Geb::Site.new
959
+ site_path = "test/site"
960
+
961
+ config = mock('config')
962
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
963
+
964
+ site.instance_variable_set(:@site_path, site_path)
965
+ site.instance_variable_set(:@site_config, config)
966
+
967
+ release_path = site.get_template_archive_release_path()
968
+
969
+ assert_equal release_path, File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR, Geb::Defaults::TEMPLATE_ARCHIVE_FILENAME)
970
+
971
+ end # test "that the template archive release path is constructed correctly"
972
+
973
+ test "that launch remot method executes as expected" do
974
+
975
+ site = Geb::Site.new
976
+ test_site_path = "test/site"
977
+ remote_uri = "user@server.com"
978
+
979
+ config = mock('config')
980
+ config.stubs(:remote_uri).returns(remote_uri)
981
+ site.instance_variable_set(:@loaded, true)
982
+ site.instance_variable_set(:@site_path, test_site_path)
983
+ site.instance_variable_set(:@site_config, config)
984
+ Open3.expects(:capture3).with("ssh", remote_uri).once
985
+
986
+ site.launch_remote
987
+
988
+ end # test "that launch remote method executes as expected"
989
+
990
+ test "that launch remote method handles site not loaded exception" do
991
+
992
+ site = Geb::Site.new
993
+ test_site_path = "test/site"
994
+ remote_uri = "user@server.com"
995
+
996
+ config = mock('config')
997
+ config.stubs(:remote_uri).returns(remote_uri)
998
+ site.instance_variable_set(:@loaded, false)
999
+ site.instance_variable_set(:@site_path, test_site_path)
1000
+ site.instance_variable_set(:@site_config, config)
1001
+ Open3.expects(:capture3).with("ssh", remote_uri).never
1002
+
1003
+ error = assert_raises Geb::Site::SiteNotFoundError do
1004
+ site.launch_remote
1005
+ end
1006
+
1007
+ assert_includes error.message, "Site not loaded"
1008
+
1009
+ end # test "that launch remote method handles site not loaded exception"
1010
+
1011
+ test "that launch remote method handles remote uri not specified exception" do
1012
+
1013
+ site = Geb::Site.new
1014
+ test_site_path = "test/site"
1015
+ remote_uri = nil
1016
+
1017
+ config = mock('config')
1018
+ config.stubs(:remote_uri).returns(remote_uri)
1019
+ site.instance_variable_set(:@loaded, true)
1020
+ site.instance_variable_set(:@site_path, test_site_path)
1021
+ site.instance_variable_set(:@site_config, config)
1022
+ Open3.expects(:capture3).with("ssh", remote_uri).never
1023
+
1024
+ error = assert_raises Geb::Site::RemoteURINotConfigured do
1025
+ site.launch_remote
1026
+ end
1027
+
1028
+ assert_includes error.message, "Remote URI not configured in geb.config.yml"
1029
+
1030
+ end # test "that launch remote method handles remote uri not specified exception"
1031
+
1032
+ test "that launch remote method handles Interrupt and IOError exceptions" do
1033
+
1034
+ site = Geb::Site.new
1035
+ test_site_path = "test/site"
1036
+ remote_uri = "user@server.com"
1037
+
1038
+ config = mock('config')
1039
+ config.stubs(:remote_uri).returns(remote_uri)
1040
+ site.instance_variable_set(:@loaded, true)
1041
+ site.instance_variable_set(:@site_path, test_site_path)
1042
+ site.instance_variable_set(:@site_config, config)
1043
+ Open3.expects(:capture3).with("ssh", remote_uri).raises(Interrupt).once
1044
+ Geb.expects(:log).with("Remote session interrupted.").once
1045
+
1046
+ site.launch_remote
1047
+
1048
+ end # test "that launch remote method handles Interrupt and IOError exceptions"
1049
+
1050
+ test "that launch remote method handles general exception while executing external command" do
1051
+
1052
+ site = Geb::Site.new
1053
+ test_site_path = "test/site"
1054
+ remote_uri = "user@server.com"
1055
+
1056
+ config = mock('config')
1057
+ config.stubs(:remote_uri).returns(remote_uri)
1058
+ site.instance_variable_set(:@loaded, true)
1059
+ site.instance_variable_set(:@site_path, test_site_path)
1060
+ site.instance_variable_set(:@site_config, config)
1061
+ Open3.expects(:capture3).with("ssh", remote_uri).raises(StandardError).once
1062
+ Geb.expects(:log).with("Remote session interrupted.").once
1063
+
1064
+ site.launch_remote
1065
+
1066
+ end # test "that launch remote method handles general exception while executing external command"
1067
+
1068
+ test "that upload release to remote method executes as expected" do
1069
+
1070
+ site = Geb::Site.new
1071
+ test_site_path = "test/site"
1072
+ remote_uri = "user@server.com"
1073
+ remote_path = '/var/www/site'
1074
+
1075
+ config = mock('config')
1076
+ config.stubs(:remote_uri).returns(remote_uri)
1077
+ config.stubs(:remote_path).returns(remote_path)
1078
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1079
+ site.expects(:released?).returns(true)
1080
+ site.instance_variable_set(:@loaded, true)
1081
+ site.instance_variable_set(:@site_path, test_site_path)
1082
+ site.instance_variable_set(:@site_config, config)
1083
+ Open3.expects(:popen3).once
1084
+
1085
+ site.upload_release_to_remote
1086
+
1087
+ end # test "that upload release to remote method executes as expected"
1088
+
1089
+ test "that upload release to remote method handles if site has not been released" do
1090
+
1091
+ site = Geb::Site.new
1092
+ test_site_path = "test/site"
1093
+ remote_uri = "user@server.com"
1094
+ remote_path = '/var/www/site'
1095
+
1096
+ config = mock('config')
1097
+ config.stubs(:remote_uri).returns(remote_uri)
1098
+ config.stubs(:remote_path).returns(remote_path)
1099
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1100
+ site.expects(:released?).returns(false)
1101
+ site.instance_variable_set(:@loaded, true)
1102
+ site.instance_variable_set(:@site_path, test_site_path)
1103
+ site.instance_variable_set(:@site_config, config)
1104
+ Open3.expects(:popen3).never
1105
+
1106
+ error = assert_raises Geb::Site::SiteNotReleasedError do
1107
+ site.upload_release_to_remote
1108
+ end
1109
+
1110
+ assert_includes error.message, "Site not released."
1111
+
1112
+ end # test "that upload release to remote method handles if site has not been released"
1113
+
1114
+ test "that upload release to remote method handles if remote uri is not specified" do
1115
+
1116
+ site = Geb::Site.new
1117
+ test_site_path = "test/site"
1118
+ remote_uri = nil
1119
+ remote_path = '/var/www/site'
1120
+
1121
+ config = mock('config')
1122
+ config.stubs(:remote_uri).returns(remote_uri)
1123
+ config.stubs(:remote_path).returns(remote_path)
1124
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1125
+ site.expects(:released?).returns(true)
1126
+ site.instance_variable_set(:@loaded, true)
1127
+ site.instance_variable_set(:@site_path, test_site_path)
1128
+ site.instance_variable_set(:@site_config, config)
1129
+ Open3.expects(:popen3).never
1130
+
1131
+ error = assert_raises Geb::Site::RemoteURINotConfigured do
1132
+ site.upload_release_to_remote
1133
+ end
1134
+
1135
+ assert_includes error.message, "Remote URI not configured in geb.config.yml"
1136
+
1137
+ end # test "that upload release to remote method handles if remote uri is not specified"
1138
+
1139
+ test "that upload release to remote method handles if remote path is not specified" do
1140
+
1141
+ site = Geb::Site.new
1142
+ test_site_path = "test/site"
1143
+ remote_uri = "user@server.com"
1144
+ remote_path = nil
1145
+
1146
+ config = mock('config')
1147
+ config.stubs(:remote_uri).returns(remote_uri)
1148
+ config.stubs(:remote_path).returns(remote_path)
1149
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1150
+ site.expects(:released?).returns(true)
1151
+ site.instance_variable_set(:@loaded, true)
1152
+ site.instance_variable_set(:@site_path, test_site_path)
1153
+ site.instance_variable_set(:@site_config, config)
1154
+ Open3.expects(:popen3).never
1155
+
1156
+ error = assert_raises Geb::Site::RemotePathNotConfigured do
1157
+ site.upload_release_to_remote
1158
+ end
1159
+
1160
+ assert_includes error.message, "Remote Path is not configured in geb.config.yml"
1161
+
1162
+ end # test "that upload release to remote method handles if remote path is not specified"
1163
+
1164
+
1165
+ test "that upload release to remote method handles Interrupt and IOError exceptions" do
1166
+
1167
+ site = Geb::Site.new
1168
+ test_site_path = "test/site"
1169
+ remote_uri = "user@server.com"
1170
+ remote_path = '/var/www/site'
1171
+
1172
+ config = mock('config')
1173
+ config.stubs(:remote_uri).returns(remote_uri)
1174
+ config.stubs(:remote_path).returns(remote_path)
1175
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1176
+ site.expects(:released?).returns(true)
1177
+ site.instance_variable_set(:@loaded, true)
1178
+ site.instance_variable_set(:@site_path, test_site_path)
1179
+ site.instance_variable_set(:@site_config, config)
1180
+ Open3.expects(:popen3).raises(Interrupt).once
1181
+ Geb.expects(:log).with("Upload interrupted.").once
1182
+
1183
+ site.upload_release_to_remote
1184
+
1185
+ end # test "that upload release to remote method handles Interrupt and IOError exceptions"
1186
+
1187
+ test "that upload release to remote method handles general exception while executing external command" do
1188
+
1189
+ site = Geb::Site.new
1190
+ test_site_path = "test/site"
1191
+ remote_uri = "user@server.com"
1192
+ remote_path = '/var/www/site'
1193
+
1194
+ config = mock('config')
1195
+ config.stubs(:remote_uri).returns(remote_uri)
1196
+ config.stubs(:remote_path).returns(remote_path)
1197
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1198
+ site.expects(:released?).returns(true)
1199
+ site.instance_variable_set(:@loaded, true)
1200
+ site.instance_variable_set(:@site_path, test_site_path)
1201
+ site.instance_variable_set(:@site_config, config)
1202
+ Open3.expects(:popen3).raises(Geb::Error).once
1203
+ Geb.expects(:log).with("Upload interrupted.").once
1204
+
1205
+ site.upload_release_to_remote
1206
+
1207
+ end # test "that lupload release to remote method handles general exception while executing external command"
1208
+
1209
+ test "that upload release to remote method handles output from external command" do
1210
+
1211
+ site = Geb::Site.new
1212
+ test_site_path = "test/site"
1213
+ remote_uri = "user@server.com"
1214
+ remote_path = '/var/www/site'
1215
+
1216
+ config = mock('config')
1217
+ config.stubs(:remote_uri).returns(remote_uri)
1218
+ config.stubs(:remote_path).returns(remote_path)
1219
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1220
+ site.expects(:released?).returns(true)
1221
+ site.instance_variable_set(:@loaded, true)
1222
+ site.instance_variable_set(:@site_path, test_site_path)
1223
+ site.instance_variable_set(:@site_config, config)
1224
+
1225
+ mock_stdout = StringIO.new("mocked stdout line 1\nmocked stdout line 2\n")
1226
+ mock_stderr = StringIO.new("mocked stderr line 1\nmocked stderr line 2\n")
1227
+ mock_wait_thr = mock('wait_thr')
1228
+ mock_wait_thr.stubs(:value) #.returns(mock('status', exitstatus: 0))
1229
+
1230
+ Open3.stubs(:popen3).yields(nil, mock_stdout, mock_stderr, mock_wait_thr)
1231
+
1232
+ site.upload_release_to_remote
1233
+
1234
+ end # test "that upload release to remote method handles output from external command"
1235
+
1236
+ test "that the released method returns true if the release directory exists and is not empty" do
1237
+
1238
+ site = Geb::Site.new
1239
+ test_site_path = "site"
1240
+
1241
+ Dir.mktmpdir do |temp_dir|
1242
+
1243
+ site_path = File.join(temp_dir, test_site_path)
1244
+ site_release_path = File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR)
1245
+
1246
+ config = mock('config')
1247
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1248
+ site.instance_variable_set(:@site_path, site_path)
1249
+ site.instance_variable_set(:@site_config, config)
1250
+
1251
+ FileUtils.mkdir_p(site_path)
1252
+ FileUtils.mkdir_p(site_release_path)
1253
+
1254
+ FileUtils.touch(File.join(site_release_path, "dummy_file.html"))
1255
+
1256
+ assert_equal site_release_path, site.get_site_release_directory()
1257
+
1258
+ assert site.released?
1259
+
1260
+ end # Dir.mktmpdir
1261
+
1262
+ end # test "that the released method returns true if the release directory exists and is not empty"
1263
+
1264
+ test "that the released method returns false if the release directory does not exist" do
1265
+
1266
+ site = Geb::Site.new
1267
+ test_site_path = "site"
1268
+
1269
+ Dir.mktmpdir do |temp_dir|
1270
+
1271
+ site_path = File.join(temp_dir, test_site_path)
1272
+ site_release_path = File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR)
1273
+
1274
+ config = mock('config')
1275
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1276
+ site.instance_variable_set(:@site_path, site_path)
1277
+ site.instance_variable_set(:@site_config, config)
1278
+
1279
+ FileUtils.mkdir_p(site_path)
1280
+
1281
+ assert_equal site_release_path, site.get_site_release_directory()
1282
+
1283
+ refute site.released?
1284
+
1285
+ end # Dir.mktmpdir
1286
+
1287
+ end # test "that the released method returns false if the release directory does not exist"
1288
+
1289
+ test "that the released method returns false if the release directory is empty" do
1290
+
1291
+ site = Geb::Site.new
1292
+ test_site_path = "site"
1293
+
1294
+ Dir.mktmpdir do |temp_dir|
1295
+
1296
+ site_path = File.join(temp_dir, test_site_path)
1297
+ site_release_path = File.join(site_path, Geb::Defaults::OUTPUT_DIR, Geb::Defaults::RELEASE_OUTPUT_DIR)
1298
+
1299
+ config = mock('config')
1300
+ config.stubs(:output_dir).returns(Geb::Defaults::OUTPUT_DIR)
1301
+ site.instance_variable_set(:@site_path, site_path)
1302
+ site.instance_variable_set(:@site_config, config)
1303
+
1304
+ FileUtils.mkdir_p(site_path)
1305
+ FileUtils.mkdir_p(site_release_path)
1306
+
1307
+ assert_equal site_release_path, site.get_site_release_directory()
1308
+
1309
+ refute site.released?
1310
+
1311
+ end # Dir.mktmpdir
1312
+
1313
+ end # test "that the released method returns false if the release directory is empty"
1314
+
1315
+ end # class SiteTest < Minitest::Test