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,249 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the template class
4
+ #
5
+ # @title Geb - Test - Template
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 TemplateTest < Geb::ApiTest
15
+
16
+ test "that template default initializes" do
17
+
18
+ template_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
19
+ template_content = "This is a template file"
20
+
21
+ Geb::Template.any_instance.stubs(:template_file_exists?).returns(true)
22
+ File.stubs(:read).returns(template_content).once
23
+
24
+ template = Geb::Template.new(template_path)
25
+
26
+ assert_instance_of Geb::Template, template
27
+ assert_equal template.path, template_path
28
+ assert_equal template.content, template_content
29
+
30
+ end # test "that site default initializes"
31
+
32
+ test "that template constructor throws an error if the template file does not exist" do
33
+
34
+ template_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
35
+
36
+ Geb::Template.any_instance.stubs(:template_file_exists?).returns(false)
37
+
38
+ error = assert_raises Geb::Template::TemplateFileNotFound do
39
+ Geb::Template.new(template_path)
40
+ end
41
+
42
+ assert_includes error.message, "#{template_path}", "Error message does not include the template path"
43
+
44
+ end # test "that template constructor throws an error if the template file does not exist"
45
+
46
+ test "that template constructor throws an error if the template file cannot be read" do
47
+
48
+ template_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
49
+
50
+ Geb::Template.any_instance.stubs(:template_file_exists?).returns(true)
51
+ File.stubs(:read).raises(Errno::ENOENT)
52
+
53
+ assert_raises Geb::Template::TemplateFileReadFailure do
54
+ Geb::Template.new(template_path)
55
+ end
56
+
57
+ end # test "that template constructor throws an error if the template file cannot be read"
58
+
59
+ test "that self.load returns the template content when the template file exists" do
60
+
61
+ template_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
62
+ template_content = "This is a template file"
63
+
64
+ Geb::Template.any_instance.stubs(:template_file_exists?).returns(true)
65
+ File.stubs(:read).returns(template_content)
66
+
67
+ template = Geb::Template.load(template_path)
68
+
69
+ assert_equal template_content, template.content
70
+
71
+ end # test "that self.load returns the template content when the template file exists"
72
+
73
+ test "that self.load returns a cached copy of the template if it was laoded previously" do
74
+
75
+ assert_empty Geb::Template.class_variable_set(:@@loaded_templates, {})
76
+
77
+ template_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
78
+ template_content = "This is a template file"
79
+
80
+ Geb::Template.any_instance.stubs(:template_file_exists?).returns(true)
81
+ File.stubs(:read).returns(template_content).once
82
+
83
+ # assert the loaded_templates class variable is empty
84
+ assert_empty Geb::Template.class_variable_get(:@@loaded_templates)
85
+ template1 = Geb::Template.load(template_path)
86
+ assert_equal 1, Geb::Template.class_variable_get(:@@loaded_templates).length
87
+ template2 = Geb::Template.load(template_path)
88
+ assert_equal 1, Geb::Template.class_variable_get(:@@loaded_templates).length
89
+
90
+ assert_same template1, template2
91
+
92
+ end # test "that self.load returns a cached copy of the template if it was laoded previously"
93
+
94
+ test "that extract template path, finds the template path in the page content" do
95
+
96
+ # initalize the template path
97
+ original_template_path = "shared/templates/_site.html"
98
+
99
+ # generate multiline page content
100
+ page_content = <<-PAGE
101
+ <p>foobar</p>
102
+ <% template: #{original_template_path} %>
103
+ <p>foobar</p>
104
+ PAGE
105
+
106
+ template_path = Geb::Template.extract_template_path(page_content)
107
+
108
+ assert_equal original_template_path, template_path
109
+
110
+ end # test "that extract template path, finds the template path in the page content"
111
+
112
+ test "that extract template path, returns nil if no template path is found in the page content" do
113
+
114
+ # generate multiline page content
115
+ page_content = <<-PAGE
116
+ <p>foobar</p>
117
+ <p>foobar</p>
118
+ PAGE
119
+
120
+ template_path = Geb::Template.extract_template_path(page_content)
121
+
122
+ assert_nil template_path
123
+
124
+ end # test "that extract template path, returns nil if no template path is found in the page content"
125
+
126
+ test "that extract template path, returns the first entry when multiple template definitions are present" do
127
+
128
+ # initalize the template path
129
+ original_template_path = "shared/templates/_site.html"
130
+
131
+ # generate multiline page content
132
+ page_content = <<-PAGE
133
+ <p>foobar</p>
134
+ <% template: #{original_template_path} %>
135
+ <p>foobar</p>
136
+ <% template: shared/templates/_site2.html %>
137
+ <p>foobar</p>
138
+ PAGE
139
+
140
+ template_path = Geb::Template.extract_template_path(page_content)
141
+
142
+ assert_equal original_template_path, template_path
143
+
144
+ end # test "that extract template path, returns the first entry when multiple template definitions are present"
145
+
146
+ test "that extract sections for template, finds the sections in the page content" do
147
+
148
+ # initalize the sections
149
+ original_sections = {
150
+ "header" => "header content",
151
+ "footer" => "footer content"
152
+ }
153
+
154
+ # generate multiline page content
155
+ page_content = <<-PAGE
156
+ <p>foobar</p>
157
+ <% start: header %>
158
+ #{original_sections["header"]}
159
+ <% end: header %>
160
+ <p>foobar</p>
161
+ <% start: footer %>
162
+ #{original_sections["footer"]}
163
+ <% end: footer %>
164
+ <p>foobar</p>
165
+ PAGE
166
+
167
+ sections = Geb::Template.extract_sections_for_template(page_content)
168
+
169
+ assert_equal original_sections, sections
170
+
171
+ end # test "that extract sections for template, finds the sections in the page content"
172
+
173
+ test "that extract sections for template, returns an empty hash if no sections are found in the page content" do
174
+
175
+ # generate multiline page content
176
+ page_content = <<-PAGE
177
+ <p>foobar</p>
178
+ <p>foobar</p>
179
+ PAGE
180
+
181
+ sections = Geb::Template.extract_sections_for_template(page_content)
182
+
183
+ assert_empty sections
184
+
185
+ end # test "that extract sections for template, returns an empty hash if no sections are found in the page content"
186
+
187
+ test "that parse template, returns the template content and sections" do
188
+
189
+ original_template_path = "shared/templates/_site.html"
190
+
191
+ # initalize the sections
192
+ original_sections = {
193
+ "header" => "header content",
194
+ "footer" => "footer content"
195
+ }
196
+
197
+ # generate multiline template content
198
+ template_content = <<-TEMPLATEPAGE
199
+ <div class="header">
200
+ <%= insert: header %>
201
+ </div>
202
+ <div class="footer">
203
+ <%= insert: footer %>
204
+ </div>
205
+ TEMPLATEPAGE
206
+
207
+ parsed_template_content = <<-PARSEDTEMPLATEPAGE
208
+ <div class="header">
209
+ header content
210
+ </div>
211
+ <div class="footer">
212
+ footer content
213
+ </div>
214
+ PARSEDTEMPLATEPAGE
215
+
216
+ Geb::Template.any_instance.stubs(:template_file_exists?).returns(true)
217
+ File.stubs(:read).returns(template_content).once
218
+
219
+ template = Geb::Template.new(original_template_path)
220
+ output = template.parse(original_sections)
221
+
222
+ assert_equal parsed_template_content, output
223
+ refute_includes output, "<%= insert: header %>"
224
+ refute_includes output, "<%= insert: footer %>"
225
+
226
+ end # test "that parse template, returns the template content and sections"
227
+
228
+ test "that that template file exists method finds files" do
229
+
230
+ File.stubs(:read)
231
+
232
+ Dir.mktmpdir do |dir|
233
+
234
+ # generate a temporary file
235
+ file_path = File.join(dir, "template.html")
236
+ non_existent_file_path = File.join(dir, "non_existent_template.html")
237
+ File.write(file_path, "This is a template file")
238
+
239
+ Geb::Template.new(file_path)
240
+
241
+ assert_raises Geb::Template::TemplateFileNotFound do
242
+ Geb::Template.new(non_existent_file_path)
243
+ end # assert_raises
244
+
245
+ end # Dir.mktmpdir
246
+
247
+ end # test "that that template file exists method finds files"
248
+
249
+ end # class TemplateTest < Geb::ApiTest
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the utilities class
4
+ #
5
+ # @title Geb - Test - Utilities
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 UtilitiesTest < Minitest::Test
15
+
16
+ test "that Geb error raises a correct error message" do
17
+
18
+ # assert that the error message is correct
19
+ error = assert_raises(Geb::Error) do
20
+ raise Geb::Error.new("Custom Error", "Default Message")
21
+ end # assert_raises(Geb::Error)
22
+
23
+ assert_equal("Custom Error Default Message", error.message)
24
+
25
+ end # test "that Geb error raises a correct error message"
26
+
27
+ test "that log prints a message to the console and has a trailing newline" do
28
+
29
+ # setup a StringIO to capture standard output
30
+ original_stdout = $stdout
31
+ $stdout = StringIO.new
32
+
33
+ # call the log method
34
+ Geb.log("Test Message")
35
+
36
+ # assert that the message is correct
37
+ assert_equal("Test Message\n", $stdout.string)
38
+
39
+ # reset $stdout
40
+ $stdout = original_stdout
41
+
42
+ end # test "that log prints a message to the console and has a trailing newline"
43
+
44
+ test "that log_start prints a message to the console and does not have a trailing newline" do
45
+
46
+ # setup a StringIO to capture standard output
47
+ original_stdout = $stdout
48
+ $stdout = StringIO.new
49
+
50
+ # call the log method
51
+ Geb.log_start("Test Message")
52
+
53
+ # assert that the message is correct
54
+ assert_equal("Test Message", $stdout.string)
55
+
56
+ # reset $stdout
57
+ $stdout = original_stdout
58
+
59
+ end # test "that log_start prints a message to the console and does not have a trailing newline"
60
+
61
+ test "that logging can be suppressed" do
62
+
63
+ # setup a StringIO to capture standard output
64
+ original_stdout = $stdout
65
+ $stdout = StringIO.new
66
+
67
+ Geb.no_log do
68
+ Geb.log("Test Message")
69
+ end
70
+
71
+ assert_equal("", $stdout.string)
72
+
73
+ Geb.log("Test Message2")
74
+
75
+ assert_equal("Test Message2\n", $stdout.string)
76
+
77
+ # reset $stdout
78
+ $stdout = original_stdout
79
+
80
+ end # test "that logging can be suppressed"
81
+
82
+ test "that copy paths to directory copies files and directories to a destination directory" do
83
+
84
+ # initialize a temporary directory
85
+ Dir.mktmpdir do |tmpdir|
86
+
87
+ test_source_directory = File.join(tmpdir, "source")
88
+ test_destination_directory = File.join(tmpdir, "destination")
89
+ Dir.mkdir(test_source_directory)
90
+ Dir.mkdir(test_destination_directory)
91
+
92
+ file_paths = []
93
+ file_paths << File.join(test_source_directory, "folder1")
94
+ file_paths << File.join(test_source_directory, "folder2")
95
+ file_paths << File.join(test_source_directory, "folder2/subfolder1")
96
+ file_paths << File.join(test_source_directory, "folder2/subfolder2")
97
+ file_paths << File.join(test_source_directory, "file1.txt")
98
+ file_paths << File.join(test_source_directory, "file2.txt")
99
+ file_paths << File.join(test_source_directory, "folder2/file2-1.txt")
100
+ file_paths << File.join(test_source_directory, "folder2/file2-1.txt")
101
+ file_paths << File.join(test_source_directory, "folder2/subfolder2/files2-1-1.txt")
102
+ file_paths.each do |path|
103
+ if path !~ /\./
104
+ FileUtils.mkdir_p(path)
105
+ else
106
+ FileUtils.mkdir_p(File.dirname(path))
107
+ File.open(path, "w") do |file|
108
+ file.write("This is a dumny file path: #{path}")
109
+ end
110
+ end
111
+ end
112
+
113
+ Geb::copy_paths_to_directory(test_source_directory, file_paths, test_destination_directory, true)
114
+
115
+ file_paths.each do |path|
116
+ destination_path = path.gsub(test_source_directory, test_destination_directory)
117
+ if path !~ /\./
118
+ assert Dir.exist?(destination_path)
119
+ else
120
+ assert File.exist?(destination_path)
121
+ end
122
+ end
123
+
124
+ end # Dir.mktmpdir
125
+
126
+ end # test "that copy paths to directory copies files and directories to a destination directory"
127
+
128
+ test "that copy paths to directory raises an error if the file operations fail" do
129
+
130
+ # initialize a temporary directory
131
+ Dir.mktmpdir do |tmpdir|
132
+
133
+ test_source_directory = File.join(tmpdir, "source")
134
+ test_destination_directory = File.join(tmpdir, "destination")
135
+ Dir.mkdir(test_source_directory)
136
+ Dir.mkdir(test_destination_directory)
137
+
138
+ FileUtils.stubs(:mkdir_p).raises(Errno::EACCES)
139
+
140
+ file_paths = []
141
+ file_paths << File.join(test_source_directory, "folder1")
142
+ file_paths << File.join(test_source_directory, "folder2")
143
+ file_paths << File.join(test_source_directory, "folder2/subfolder1")
144
+ file_paths << File.join(test_source_directory, "folder2/subfolder2")
145
+ file_paths << File.join(test_source_directory, "file1.txt")
146
+ file_paths << File.join(test_source_directory, "file2.txt")
147
+ file_paths << File.join(test_source_directory, "folder2/file2-1.txt")
148
+ file_paths << File.join(test_source_directory, "folder2/file2-1.txt")
149
+ file_paths << File.join(test_source_directory, "folder2/subfolder2/files2-1-1.txt")
150
+
151
+ error = assert_raises(Geb::Error) do
152
+ Geb::copy_paths_to_directory(test_source_directory, file_paths, test_destination_directory, true)
153
+ end
154
+
155
+ assert_includes error.message, "Permission denied"
156
+ assert_includes error.message, "Failed to copy paths to directory"
157
+
158
+ end # Dir.mktmpdir
159
+
160
+ end # test "that copy paths to directory raises an error if the file operations fail"
161
+
162
+ end # class UtilitiesTest < Geb::ApiTest
@@ -0,0 +1,199 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the build command class
4
+ #
5
+ # @title Geb - Test - Build 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 TestGebCommandBuild < Geb::CliTest
15
+
16
+ test "that the CLI api call works" do
17
+
18
+ copy_test_site()
19
+
20
+ command = Geb::CLI::Commands::Build.new
21
+
22
+ command_options = { skip_assets: false, skip_pages: false }
23
+
24
+ site_mock = mock('site')
25
+ site_mock.expects(:load).with(Dir.pwd)
26
+ site_mock.expects(:build_assets)
27
+ site_mock.expects(:build_pages)
28
+
29
+ Geb::Site.expects(:new).returns(site_mock)
30
+
31
+ original_stdout = $stdout
32
+ original_stderr = $stderr
33
+
34
+ $stdout = StringIO.new
35
+ $stderr = StringIO.new
36
+
37
+ command.call(**command_options)
38
+
39
+ assert_empty $stderr.string
40
+
41
+ $stdout = original_stdout
42
+ $stderr = original_stderr
43
+
44
+ end # test "that the CLI api call works"
45
+
46
+ test "that the CLI api call works with skip_assets and skip_pages" do
47
+
48
+ copy_test_site()
49
+
50
+ command = Geb::CLI::Commands::Build.new
51
+
52
+ command_options = { skip_assets: true, skip_pages: true }
53
+
54
+ site_mock = mock('site')
55
+ site_mock.expects(:load).with(Dir.pwd)
56
+ site_mock.expects(:build_assets).never
57
+ site_mock.expects(:build_pages).never
58
+
59
+ Geb::Site.expects(:new).returns(site_mock)
60
+
61
+ original_stdout = $stdout
62
+ original_stderr = $stderr
63
+
64
+ $stdout = StringIO.new
65
+ $stderr = StringIO.new
66
+
67
+ command.call(**command_options)
68
+
69
+ assert_empty $stderr.string
70
+
71
+ assert_includes $stdout.string, "Skipping building pages as told"
72
+ assert_includes $stdout.string, "Skipping building assets as told"
73
+
74
+ $stdout = original_stdout
75
+ $stderr = original_stderr
76
+
77
+ end # test "that the CLI api call works with skip_assets and skip_pages"
78
+
79
+ test "that the CLI api call works and handles exceptions" do
80
+
81
+ # initialize new command instance
82
+ command = Geb::CLI::Commands::Build.new
83
+
84
+ command_options = { skip_assets: false, skip_pages: false }
85
+
86
+ Geb::Site.expects(:new).raises(Geb::Error.new("Test Error"))
87
+
88
+ # setup a StringIO to capture standard output and error
89
+ original_stdout = $stdout
90
+ original_stderr = $stderr
91
+
92
+ $stdout = StringIO.new
93
+ $stderr = StringIO.new
94
+
95
+ command.call(**command_options)
96
+
97
+ refute_empty $stderr.string
98
+ assert_includes $stderr.string, "Test Error"
99
+
100
+ $stdout = original_stdout
101
+ $stderr = original_stderr
102
+
103
+ end # test "that the CLI api call works and handles exceptions"
104
+
105
+ test "that command default executes" do
106
+
107
+ copy_test_site()
108
+
109
+ # call geb auto command and capture output and error
110
+ _, stderr, status = Open3.capture3('geb build')
111
+
112
+ # assert that the output contains the expected string
113
+ assert status.success?
114
+ assert_empty stderr
115
+
116
+ end # test "command line"
117
+
118
+ test "that command handles being executed in a non-site directory" do
119
+
120
+ # create a temporary directory
121
+ Dir.mktmpdir do |dir|
122
+
123
+ Dir.chdir(dir)
124
+
125
+ _, stderr, status = Open3.capture3('geb build')
126
+
127
+ assert status.success?
128
+ refute_empty stderr
129
+
130
+ end # Dir.mktmpdir
131
+
132
+ end # test "that command handles being executed in a non-site directory"
133
+
134
+ test "that command handles being executed with skip pages option" do
135
+
136
+ copy_test_site()
137
+
138
+ stdout, stderr, status = Open3.capture3('geb build --skip-pages')
139
+
140
+ assert status.success?
141
+ assert_empty stderr
142
+
143
+ assert_includes stdout, "Skipping building pages as told"
144
+
145
+ end # test "that command handles being executed with skip pages option"
146
+
147
+ test "that command handles being executed with skip assets option" do
148
+
149
+ copy_test_site()
150
+
151
+ stdout, stderr, status = Open3.capture3('geb build --skip-assets')
152
+
153
+ assert status.success?
154
+ assert_empty stderr
155
+
156
+ assert_includes stdout, "Skipping building assets as told"
157
+
158
+ end # test "that command handles being executed with skip assets option"
159
+
160
+ test "that command handles being executed with skip pages and skip assets options" do
161
+
162
+ copy_test_site()
163
+
164
+ stdout, stderr, status = Open3.capture3('geb build --skip-pages --skip-assets')
165
+
166
+ assert status.success?
167
+ assert_empty stderr
168
+
169
+ assert_includes stdout, "Skipping building pages as told"
170
+ assert_includes stdout, "Skipping building assets as told"
171
+ assert_includes stdout, "You told me to skip everything, so I did."
172
+
173
+ end # test "that command handles being executed with skip pages and skip assets options"
174
+
175
+ test "that the command actually builds the site" do
176
+
177
+ copy_test_site()
178
+
179
+ stdout, stderr, status = Open3.capture3('geb build')
180
+
181
+ assert status.success?
182
+ assert_empty stderr
183
+
184
+ assert_includes stdout, "Loading site from path #{Dir.pwd} ... done."
185
+ assert_includes stdout, "Found geb site at path #{Dir.pwd}"
186
+ assert_match(/Building \d* pages for/, stdout)
187
+ assert_includes stdout, "loading page"
188
+ assert_includes stdout, "loading template"
189
+ assert_includes stdout, "loading partial"
190
+ assert_includes stdout, "building page"
191
+ assert_match(/Done building \d* pages for/, stdout)
192
+ assert_includes stdout, "Clearing site output folder"
193
+ assert_includes stdout, "Outputting site to"
194
+ assert_includes stdout, "Building assets for"
195
+ assert_includes stdout, "Done building assets for"
196
+
197
+ end # test "that the command actually builds the site"
198
+
199
+ end # class TestGebCommandBuild < Minitest::Test