geb 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,320 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the page class
4
+ #
5
+ # @title Geb - Test - Page
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 PageTest < Geb::ApiTest
15
+
16
+ test "that page default initializes" do
17
+
18
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
19
+ page_content = "This is a template file"
20
+
21
+ site = mock('site')
22
+ site.stubs(:site_path).returns(Dir.pwd)
23
+
24
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
25
+ Geb::Page.any_instance.stubs(:parse)
26
+ File.stubs(:read).returns(page_content)
27
+
28
+ page = Geb::Page.new(site, page_path)
29
+
30
+ assert_instance_of Geb::Page, page
31
+ assert_equal page.path, page_path
32
+ assert_equal page.content, page_content
33
+
34
+ end # test "that site default initializes"
35
+
36
+ test "that page constructor throws an error if the page file does not exist" do
37
+
38
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
39
+
40
+ site = mock('site')
41
+ site.stubs(:site_path).returns(Dir.pwd)
42
+
43
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(false)
44
+
45
+ error = assert_raises Geb::Page::PageFileNotFound do
46
+ Geb::Page.new(site, page_path)
47
+ end
48
+
49
+ assert_includes(error.message, page_path)
50
+
51
+ end # test "that page constructor throws an error if the page file does not exist"
52
+
53
+ test "that page constructor throws an error if the page file cannot be read" do
54
+
55
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
56
+
57
+ site = mock('site')
58
+ site.stubs(:site_path).returns(Dir.pwd)
59
+
60
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
61
+ File.stubs(:read).raises(Errno::ENOENT)
62
+
63
+ assert_raises Geb::Page::PageFileReadFailure do
64
+ Geb::Page.new(site, page_path)
65
+ end # assert_raises
66
+
67
+ end # test "that page constructor throws an error if the page file cannot be read"
68
+
69
+ test "that page parse method works" do
70
+
71
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
72
+ page_content = "This is a template file"
73
+
74
+ parsed_page_content = "This is a parsed template file"
75
+
76
+ site = mock('site')
77
+ site.stubs(:site_path).returns(Dir.pwd)
78
+
79
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
80
+ Geb::Page.any_instance.stubs(:parse_for_templates).returns(parsed_page_content)
81
+ Geb::Page.any_instance.stubs(:parse_for_partials).returns(parsed_page_content)
82
+ File.stubs(:read).returns(page_content)
83
+
84
+ page = Geb::Page.new(site, page_path)
85
+
86
+ assert_respond_to page, :parse
87
+
88
+ page.parse
89
+
90
+ assert_respond_to page, :parsed_content
91
+ assert_equal page.parsed_content, parsed_page_content
92
+ refute_equal page.parsed_content, page.content
93
+
94
+ end # test "that page parse method works"
95
+
96
+ test "that page parse_for_templates method works" do
97
+
98
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
99
+
100
+ page_content = <<-PAGE
101
+ <% template: test_template.html %>
102
+ <p>foobar</p>
103
+ <% start: header %>
104
+ header content
105
+ <% end: header %>
106
+ <p>foobar</p>
107
+ <% start: footer %>
108
+ footer content
109
+ <% end: footer %>
110
+ <p>foobar</p>
111
+ PAGE
112
+
113
+ original_sections = {
114
+ "header" => "header content",
115
+ "footer" => "footer content"
116
+ }
117
+
118
+ template_parsed_content = <<-TEMPLATE
119
+ <p>foobar</p>
120
+ TEMPLATE
121
+
122
+ site = mock('site')
123
+ site.stubs(:site_path).returns(Dir.pwd)
124
+
125
+ template = mock('template')
126
+ template.stubs(:parse).returns(template_parsed_content)
127
+
128
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
129
+ Geb::Page.any_instance.stubs(:parse)
130
+ File.stubs(:read).returns(page_content)
131
+
132
+ extract_template_path_sequence = sequence('extract_template_path_sequence')
133
+ Geb::Template.stubs(:extract_template_path).returns("test_template.html").once.in_sequence(extract_template_path_sequence)
134
+ Geb::Template.stubs(:extract_template_path).returns(nil).in_sequence(extract_template_path_sequence)
135
+ Geb::Template.stubs(:extract_sections_for_template).returns(original_sections).once.in_sequence(extract_template_path_sequence)
136
+ Geb::Template.stubs(:extract_sections_for_template).returns({}).in_sequence(extract_template_path_sequence)
137
+ Geb::Template.stubs(:load).returns(template)
138
+ Geb::Template.stubs(:parse).returns(template_parsed_content)
139
+
140
+ page = Geb::Page.new(site, page_path)
141
+
142
+ output_content = page.parse_for_templates(page_content)
143
+
144
+ assert_equal output_content, template_parsed_content
145
+
146
+ end # test "that page parse_for_templates method works"
147
+
148
+ test "that page parse_for_templates method raises an exception if page content has sections but no template defintion" do
149
+
150
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
151
+ page_content = <<-PAGE
152
+ <p>foobar</p>
153
+ <% start: header %>
154
+ header content
155
+ <% end: header %>
156
+ <p>foobar</p>
157
+ <% start: footer %>
158
+ footer content
159
+ <% end: footer %>
160
+ <p>foobar</p>
161
+ PAGE
162
+
163
+ site = mock('site')
164
+ site.stubs(:site_path).returns(Dir.pwd)
165
+
166
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
167
+ Geb::Page.any_instance.stubs(:parse)
168
+ File.stubs(:read).returns(page_content)
169
+
170
+ page = Geb::Page.new(site, page_path)
171
+
172
+ assert_raises Geb::Page::PageMissingTemplateDefition do
173
+ page.parse_for_templates(page_content)
174
+ end # assert_raises
175
+
176
+ end # test "that page parse_for_templates method raises an exception if page content has sections but no template defintion"
177
+
178
+ test "that page parse_for_partials method works" do
179
+
180
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
181
+ page_content = <<-PAGE
182
+ <% partial: test_partial.html %>
183
+ <% partial: test_partial2.html %>
184
+ PAGE
185
+
186
+ partial_content = "This is a partial file"
187
+
188
+ site = mock('site')
189
+ site.stubs(:site_path).returns(Dir.pwd)
190
+
191
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
192
+ Geb::Page.any_instance.stubs(:parse)
193
+ File.stubs(:read).returns(page_content)
194
+
195
+ extract_partial_path_sequence = sequence('extract_partial_path_sequence')
196
+ Geb::Partial.stubs(:process_partials).with(Dir.pwd, page_content).returns([2, partial_content]).once.in_sequence(extract_partial_path_sequence)
197
+ Geb::Partial.stubs(:process_partials).with(Dir.pwd, partial_content).returns([0, partial_content]).in_sequence(extract_partial_path_sequence)
198
+
199
+ page = Geb::Page.new(site, page_path)
200
+
201
+ output_content = page.parse_for_partials(page_content)
202
+
203
+ assert_equal output_content, partial_content
204
+
205
+ end # test "that page parse_for_partials method works"
206
+
207
+ test "that page build method works" do
208
+
209
+ site_path = Dir.pwd
210
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
211
+ output_path = File.join(Dir.pwd, "output")
212
+ page_output_path = page_path.gsub(site_path, output_path)
213
+ page_content = "This is a template file"
214
+
215
+ site = mock('site')
216
+ site.stubs(:site_path).returns(site_path)
217
+ site.stubs(:output_path).returns(File.join(Dir.pwd, "output"))
218
+
219
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
220
+ Geb::Page.any_instance.stubs(:parse)
221
+ Geb::Page.any_instance.stubs(:parse_for_templates)
222
+ Geb::Page.any_instance.stubs(:parse_for_partials)
223
+ File.stubs(:read).returns(page_content)
224
+ FileUtils.stubs(:mkdir_p).with(File.dirname(page_output_path)).returns(true)
225
+ File.stubs(:write).with(page_output_path, page_content).returns(true)
226
+
227
+ page = Geb::Page.new(site, page_path)
228
+ page.instance_variable_set(:@parsed_content, page_content)
229
+
230
+ page.build(output_path)
231
+
232
+ end # test "that page build method works"
233
+
234
+ test "that page build method raises an exception if the output directory cannot be created" do
235
+
236
+ site_path = Dir.pwd
237
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
238
+ output_path = File.join(Dir.pwd, "output")
239
+ page_output_path = page_path.gsub(site_path, output_path)
240
+ page_content = "This is a template file"
241
+
242
+ site = mock('site')
243
+ site.stubs(:site_path).returns(site_path)
244
+ site.stubs(:output_path).returns(File.join(Dir.pwd, "output"))
245
+
246
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
247
+ Geb::Page.any_instance.stubs(:parse)
248
+ Geb::Page.any_instance.stubs(:parse_for_templates)
249
+ Geb::Page.any_instance.stubs(:parse_for_partials)
250
+ File.stubs(:read).returns(page_content)
251
+ FileUtils.stubs(:mkdir_p).raises(Errno::EACCES)
252
+ File.stubs(:write).with(page_output_path, page_content).returns(true)
253
+
254
+ page = Geb::Page.new(site, page_path)
255
+ page.instance_variable_set(:@parsed_content, page_content)
256
+
257
+ assert_raises Geb::Page::FailedToOutputPage do
258
+ page.build(output_path)
259
+ end # assert_raises
260
+
261
+ end # test "that page build method raises an exception if the output directory cannot be created"
262
+
263
+ test "that page build method raises an exception if the output file cannot be written" do
264
+
265
+ site_path = Dir.pwd
266
+ page_path = File.join(Dir.pwd, "test", "fixtures", "template.html")
267
+ output_path = File.join(Dir.pwd, "output")
268
+ page_output_path = page_path.gsub(site_path, output_path)
269
+ page_content = "This is a template file"
270
+
271
+ site = mock('site')
272
+ site.stubs(:site_path).returns(site_path)
273
+ site.stubs(:output_path).returns(File.join(Dir.pwd, "output"))
274
+
275
+ Geb::Page.any_instance.stubs(:page_file_exists?).returns(true)
276
+ Geb::Page.any_instance.stubs(:parse)
277
+ Geb::Page.any_instance.stubs(:parse_for_templates)
278
+ Geb::Page.any_instance.stubs(:parse_for_partials)
279
+ File.stubs(:read).returns(page_content)
280
+ FileUtils.stubs(:mkdir_p).with(File.dirname(page_output_path)).returns(true)
281
+ File.stubs(:write).raises(Errno::EACCES)
282
+
283
+ page = Geb::Page.new(site, page_path)
284
+ page.instance_variable_set(:@parsed_content, page_content)
285
+
286
+ assert_raises Geb::Page::FailedToOutputPage do
287
+ page.build(output_path)
288
+ end # assert_raises
289
+
290
+ end # test "that page build method raises an exception if the output file cannot be written"
291
+
292
+ test "that that template file exists method finds files" do
293
+
294
+ site_path = Dir.pwd
295
+ page_content = "This is a template file"
296
+
297
+ site = mock('site')
298
+ site.stubs(:site_path).returns(site_path)
299
+
300
+ Geb::Page.any_instance.stubs(:parse)
301
+ File.stubs(:read).returns(page_content)
302
+
303
+ Dir.mktmpdir do |dir|
304
+
305
+ # generate a temporary file
306
+ file_path = File.join(dir, "template.html")
307
+ non_existent_file_path = File.join(dir, "non_existent_template.html")
308
+ File.write(file_path, "This is a template file")
309
+
310
+ Geb::Page.new(site, file_path)
311
+
312
+ assert_raises Geb::Page::PageFileNotFound do
313
+ Geb::Page.new(site, non_existent_file_path)
314
+ end # assert_raises
315
+
316
+ end # Dir.mktmpdir
317
+
318
+ end # test "that that template file exists method finds files"
319
+
320
+ end # class PageTest < Geb::ApiTest
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Tests the partial class
4
+ #
5
+ # @title Geb - Test - Partial
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 PartialTest < Geb::ApiTest
15
+
16
+ test "that partial default initializes" do
17
+
18
+ partial_path = File.join(Dir.pwd, "test", "partials", "template.html")
19
+ partial_content = "This is a partial file"
20
+
21
+ Geb::Partial.any_instance.stubs(:partial_file_exists?).returns(true)
22
+ File.stubs(:read).returns(partial_content)
23
+
24
+ partial = Geb::Partial.new(partial_path)
25
+
26
+ assert_instance_of Geb::Partial, partial
27
+ assert_equal partial.path, partial_path
28
+ assert_equal partial.content, partial_content
29
+
30
+ end # test "that partial default initializes"
31
+
32
+ test "that partial constructor throws an error if the partial file does not exist" do
33
+
34
+ partial_path = File.join(Dir.pwd, "test", "partials", "template.html")
35
+
36
+ Geb::Partial.any_instance.stubs(:partial_file_exists?).returns(false)
37
+
38
+ error = assert_raises Geb::Partial::PartialFileNotFound do
39
+ Geb::Partial.new(partial_path)
40
+ end
41
+
42
+ assert_includes(error.message, partial_path)
43
+
44
+ end # test "that partial constructor throws an error if the partial file does not exist"
45
+
46
+ test "that partial constructor throws an error if the partial file cannot be read" do
47
+
48
+ partial_path = File.join(Dir.pwd, "test", "partials", "template.html")
49
+
50
+ Geb::Partial.any_instance.stubs(:partial_file_exists?).returns(true)
51
+ File.stubs(:read).raises(Errno::ENOENT)
52
+
53
+ assert_raises Geb::Partial::PartialFileReadFailure do
54
+ Geb::Partial.new(partial_path)
55
+ end # error = assert_raises Geb::Partial::PartialFileNotFound do
56
+
57
+ end # test "that partial constructor throws an error if the page file cannot be read"
58
+
59
+ test "that self.load returns the partial content when the partial file exists" do
60
+
61
+ partial_path = File.join(Dir.pwd, "test", "partials", "template.html")
62
+ partial_content = "This is a partial file"
63
+
64
+ Geb::Partial.any_instance.stubs(:partial_file_exists?).returns(true)
65
+ File.stubs(:read).returns(partial_content)
66
+
67
+ partial = Geb::Partial.load(partial_path)
68
+
69
+ assert_equal partial_content, partial.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 partial if it was laoded previously" do
74
+
75
+ assert_empty Geb::Partial.class_variable_set(:@@loaded_partials, {})
76
+
77
+ partial_path = File.join(Dir.pwd, "test", "partials", "template.html")
78
+ partial_content = "This is a partial file"
79
+
80
+ Geb::Partial.any_instance.stubs(:partial_file_exists?).returns(true)
81
+ File.stubs(:read).returns(partial_content).once
82
+
83
+ # assert the loaded_templates class variable is empty
84
+ assert_empty Geb::Partial.class_variable_get(:@@loaded_partials)
85
+ partial1 = Geb::Partial.load(partial_path)
86
+ assert_equal 1, Geb::Partial.class_variable_get(:@@loaded_partials).length
87
+ partial2 = Geb::Partial.load(partial_path)
88
+ assert_equal 1, Geb::Partial.class_variable_get(:@@loaded_partials).length
89
+
90
+ assert_same partial1, partial2
91
+
92
+ end # test "that self.load returns a cached copy of the template if it was laoded previously"
93
+
94
+ test "that self.process_partials returns the partial content when the partial file exists" do
95
+
96
+ site_path = File.join(Dir.pwd, "test", "site")
97
+ page_content = <<-PAGE
98
+ <div class="partial1-container">
99
+ <%= partial: partial1.html %>
100
+ </div>
101
+ <div class="partial1-container">
102
+ <%= partial: partial2.html %>
103
+ </div>
104
+ PAGE
105
+ parsed_page_content = <<-PARSEDPAGE
106
+ <div class="partial1-container">
107
+ partial 1 content
108
+ </div>
109
+ <div class="partial1-container">
110
+ partial 2 content
111
+ </div>
112
+ PARSEDPAGE
113
+
114
+ # mock the partial object
115
+ partial = mock('partial')
116
+
117
+ # setup a sequence
118
+ partial_sequence = sequence('partial_sequence')
119
+ partial.stubs(:content).returns("partial 1 content").once.in_sequence(partial_sequence)
120
+ partial.stubs(:content).returns("partial 2 content").once.in_sequence(partial_sequence)
121
+ Geb::Partial.stubs(:load).returns(partial)
122
+
123
+ # call the method
124
+ partial_count, content = Geb::Partial.process_partials(site_path, page_content)
125
+
126
+ assert_equal 2, partial_count
127
+ assert_equal parsed_page_content, content
128
+
129
+ end # test "that self.extract_partial_paths returns the partial content when the partial file exists"
130
+
131
+ test "that that partial file exists method finds files" do
132
+
133
+ File.stubs(:read)
134
+
135
+ Dir.mktmpdir do |dir|
136
+
137
+ # generate a temporary file
138
+ file_path = File.join(dir, "partial.html")
139
+ non_existent_file_path = File.join(dir, "non_existent_partial.html")
140
+ File.write(file_path, "This is a partial file")
141
+
142
+ Geb::Partial.new(file_path)
143
+
144
+ assert_raises Geb::Partial::PartialFileNotFound do
145
+ Geb::Partial.new(non_existent_file_path)
146
+ end # assert_raises
147
+
148
+ end # Dir.mktmpdir
149
+
150
+ end # test "that that template file exists method finds files"
151
+
152
+ end # class PartialTest < Geb::ApiTest