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.
- checksums.yaml +7 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +37 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE +21 -0
- data/README.md +384 -0
- data/Rakefile +21 -0
- data/bin/geb +21 -0
- data/lib/geb/cli.rb +40 -0
- data/lib/geb/commands/build.rb +59 -0
- data/lib/geb/commands/init.rb +70 -0
- data/lib/geb/commands/release.rb +54 -0
- data/lib/geb/commands/remote.rb +48 -0
- data/lib/geb/commands/server.rb +77 -0
- data/lib/geb/commands/upload.rb +48 -0
- data/lib/geb/commands/version.rb +36 -0
- data/lib/geb/config.rb +103 -0
- data/lib/geb/defaults.rb +44 -0
- data/lib/geb/git.rb +112 -0
- data/lib/geb/page.rb +217 -0
- data/lib/geb/partial.rb +150 -0
- data/lib/geb/samples/basic/assets/css/site.css +7 -0
- data/lib/geb/samples/basic/assets/images/android-chrome-192x192.png +0 -0
- data/lib/geb/samples/basic/assets/images/android-chrome-512x512.png +0 -0
- data/lib/geb/samples/basic/assets/images/apple-touch-icon.png +0 -0
- data/lib/geb/samples/basic/assets/images/favicon-16x16.png +0 -0
- data/lib/geb/samples/basic/assets/images/favicon-32x32.png +0 -0
- data/lib/geb/samples/basic/assets/images/favicon.ico +0 -0
- data/lib/geb/samples/basic/assets/images/hero.png +0 -0
- data/lib/geb/samples/basic/assets/images/og-thumb.png +0 -0
- data/lib/geb/samples/basic/assets/images/twitter-thumb.png +0 -0
- data/lib/geb/samples/basic/assets/js/site.js +5 -0
- data/lib/geb/samples/basic/geb.config.yml +70 -0
- data/lib/geb/samples/basic/index.html +11 -0
- data/lib/geb/samples/basic/page.html +11 -0
- data/lib/geb/samples/basic/shared/partials/_analytics.html +9 -0
- data/lib/geb/samples/basic/shared/partials/_footer.html +3 -0
- data/lib/geb/samples/basic/shared/partials/_global_assets.html +19 -0
- data/lib/geb/samples/basic/shared/partials/_header.html +0 -0
- data/lib/geb/samples/basic/shared/partials/_meta_tags.html +34 -0
- data/lib/geb/samples/basic/shared/templates/_blog_post.html +0 -0
- data/lib/geb/samples/basic/shared/templates/_site.html +19 -0
- data/lib/geb/samples/basic/site.webmanifest +1 -0
- data/lib/geb/samples/bootstrap_jquery/assets/css/site.css +7 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/android-chrome-192x192.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/android-chrome-512x512.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/apple-touch-icon.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/favicon-16x16.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/favicon-32x32.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/favicon.ico +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/hero.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/og-thumb.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/images/twitter-thumb.png +0 -0
- data/lib/geb/samples/bootstrap_jquery/assets/js/site.js +5 -0
- data/lib/geb/samples/bootstrap_jquery/blog/blog_post_1.html +35 -0
- data/lib/geb/samples/bootstrap_jquery/blog/blog_post_2.html +35 -0
- data/lib/geb/samples/bootstrap_jquery/blog/blog_post_3.html +35 -0
- data/lib/geb/samples/bootstrap_jquery/blog/index.html +17 -0
- data/lib/geb/samples/bootstrap_jquery/geb.config.yml +69 -0
- data/lib/geb/samples/bootstrap_jquery/index.html +11 -0
- data/lib/geb/samples/bootstrap_jquery/page.html +11 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_analytics.html +9 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_footer.html +3 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_global_assets.html +19 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_header.html +0 -0
- data/lib/geb/samples/bootstrap_jquery/shared/partials/_meta_tags.html +34 -0
- data/lib/geb/samples/bootstrap_jquery/shared/templates/_blog_post.html +0 -0
- data/lib/geb/samples/bootstrap_jquery/shared/templates/_site.html +19 -0
- data/lib/geb/samples/bootstrap_jquery/site.webmanifest +1 -0
- data/lib/geb/samples/geb.config.yml +70 -0
- data/lib/geb/server.rb +138 -0
- data/lib/geb/site/build.rb +189 -0
- data/lib/geb/site/core.rb +229 -0
- data/lib/geb/site/release.rb +70 -0
- data/lib/geb/site/remote.rb +142 -0
- data/lib/geb/site/template.rb +208 -0
- data/lib/geb/site.rb +83 -0
- data/lib/geb/template.rb +166 -0
- data/lib/geb/utilities.rb +110 -0
- data/lib/geb.rb +36 -0
- data/lib/seth.rb +50 -0
- data/sig/geb.rbs +4 -0
- data/test/api tests/test_cli.rb +200 -0
- data/test/api tests/test_config.rb +330 -0
- data/test/api tests/test_defaults.rb +62 -0
- data/test/api tests/test_git.rb +105 -0
- data/test/api tests/test_page.rb +320 -0
- data/test/api tests/test_partial.rb +152 -0
- data/test/api tests/test_server.rb +416 -0
- data/test/api tests/test_site.rb +1315 -0
- data/test/api tests/test_template.rb +249 -0
- data/test/api tests/test_utilities.rb +162 -0
- data/test/command tests/test_geb_build.rb +199 -0
- data/test/command tests/test_geb_init.rb +312 -0
- data/test/command tests/test_geb_release.rb +166 -0
- data/test/command tests/test_geb_remote.rb +66 -0
- data/test/command tests/test_geb_server.rb +122 -0
- data/test/command tests/test_geb_upload.rb +96 -0
- data/test/command tests/test_geb_version.rb +58 -0
- data/test/support/geb_api_test.rb +37 -0
- data/test/support/geb_cli_test.rb +275 -0
- data/test/support/geb_minitest_ext.rb +35 -0
- data/test/support/geb_test_helpers.rb +84 -0
- data/test/support/geb_web_server_proxy.rb +128 -0
- data/test/test_helper.rb +61 -0
- metadata +301 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
3
|
+
# Tests the server class
|
|
4
|
+
#
|
|
5
|
+
# @title Geb - Test - Server
|
|
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 TestServer < Geb::ApiTest
|
|
15
|
+
|
|
16
|
+
test "that server initializer handles the auto_build flag set to true" do
|
|
17
|
+
|
|
18
|
+
site_mock = mock('site')
|
|
19
|
+
site_mock.stubs(:site_path).returns('site_path')
|
|
20
|
+
site_mock.stubs(:get_site_output_directory).returns('site_path/output')
|
|
21
|
+
site_mock.stubs(:get_site_release_directory).returns('site_path/release')
|
|
22
|
+
|
|
23
|
+
http_server_mock = mock('webric_httpserver')
|
|
24
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
25
|
+
|
|
26
|
+
file_watcher_mock = mock('file_watcher')
|
|
27
|
+
file_watcher_mock.stubs(:ignore)
|
|
28
|
+
|
|
29
|
+
WEBrick::HTTPServer.expects(:new).returns(http_server_mock)
|
|
30
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
31
|
+
|
|
32
|
+
server = Geb::Server.new(site_mock, 3456, true)
|
|
33
|
+
|
|
34
|
+
assert_instance_of Geb::Server, server
|
|
35
|
+
|
|
36
|
+
refute_nil server.instance_variable_get(:@http_server)
|
|
37
|
+
refute_nil server.instance_variable_get(:@file_watcher)
|
|
38
|
+
|
|
39
|
+
end # test "that server initializer handles the auto_build flag set to true"
|
|
40
|
+
|
|
41
|
+
test "that server initializer handles the auto_build flag set to false" do
|
|
42
|
+
|
|
43
|
+
site_mock = mock('site')
|
|
44
|
+
site_mock.stubs(:site_path).returns('site_path')
|
|
45
|
+
site_mock.stubs(:get_site_output_directory).returns('site_path/output')
|
|
46
|
+
site_mock.stubs(:get_site_release_directory).returns('site_path/release')
|
|
47
|
+
|
|
48
|
+
http_server_mock = mock('webric_httpserver')
|
|
49
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
50
|
+
|
|
51
|
+
file_watcher_mock = mock('file_watcher')
|
|
52
|
+
file_watcher_mock.stubs(:ignore)
|
|
53
|
+
|
|
54
|
+
WEBrick::HTTPServer.expects(:new).returns(http_server_mock)
|
|
55
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
56
|
+
|
|
57
|
+
server = Geb::Server.new(site_mock, 3456, false)
|
|
58
|
+
|
|
59
|
+
assert_instance_of Geb::Server, server
|
|
60
|
+
|
|
61
|
+
refute_nil server.instance_variable_get(:@http_server)
|
|
62
|
+
assert_nil server.instance_variable_get(:@file_watcher)
|
|
63
|
+
|
|
64
|
+
end # test "that server initializer handles the auto_build flag set to false"
|
|
65
|
+
|
|
66
|
+
test "that server start method starts the http server and file watcher" do
|
|
67
|
+
|
|
68
|
+
site_mock = mock('site')
|
|
69
|
+
site_mock.stubs(:site_path).returns('site_path')
|
|
70
|
+
site_mock.stubs(:get_site_output_directory).returns('site_path/output')
|
|
71
|
+
site_mock.stubs(:get_site_release_directory).returns('site_path/release')
|
|
72
|
+
|
|
73
|
+
http_server_mock = mock('webric_httpserver')
|
|
74
|
+
http_server_mock.expects(:start)
|
|
75
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
76
|
+
|
|
77
|
+
file_watcher_mock = mock('file_watcher')
|
|
78
|
+
file_watcher_mock.stubs(:ignore)
|
|
79
|
+
file_watcher_mock.expects(:start)
|
|
80
|
+
|
|
81
|
+
WEBrick::HTTPServer.stubs(:new).returns(http_server_mock)
|
|
82
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
83
|
+
|
|
84
|
+
server = Geb::Server.new(site_mock, 3456, true)
|
|
85
|
+
|
|
86
|
+
server.start
|
|
87
|
+
|
|
88
|
+
sleep 0.1
|
|
89
|
+
|
|
90
|
+
http_server_thread = server.instance_variable_get(:@http_server_thread)
|
|
91
|
+
file_watcher_thread = server.instance_variable_get(:@file_watcher_thread)
|
|
92
|
+
|
|
93
|
+
refute_nil server.instance_variable_get(:@http_server_thread)
|
|
94
|
+
refute_nil server.instance_variable_get(:@file_watcher_thread)
|
|
95
|
+
assert_instance_of Thread, server.instance_variable_get(:@http_server_thread)
|
|
96
|
+
assert_instance_of Thread, server.instance_variable_get(:@file_watcher_thread)
|
|
97
|
+
|
|
98
|
+
http_server_thread.kill
|
|
99
|
+
file_watcher_thread.kill
|
|
100
|
+
|
|
101
|
+
end # test "that server start method starts the http server and file watcher"
|
|
102
|
+
|
|
103
|
+
test "that server start methods starts the http server and not the file watcher" do
|
|
104
|
+
|
|
105
|
+
site_mock = mock('site')
|
|
106
|
+
site_mock.stubs(:site_path).returns('site_path')
|
|
107
|
+
site_mock.stubs(:get_site_output_directory).returns('site_path/output')
|
|
108
|
+
site_mock.stubs(:get_site_release_directory).returns('site_path/release')
|
|
109
|
+
|
|
110
|
+
http_server_mock = mock('webric_httpserver')
|
|
111
|
+
http_server_mock.expects(:start)
|
|
112
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
113
|
+
|
|
114
|
+
file_watcher_mock = mock('file_watcher')
|
|
115
|
+
file_watcher_mock.stubs(:ignore)
|
|
116
|
+
file_watcher_mock.expects(:start).never
|
|
117
|
+
|
|
118
|
+
WEBrick::HTTPServer.stubs(:new).returns(http_server_mock)
|
|
119
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
120
|
+
|
|
121
|
+
server = Geb::Server.new(site_mock, 3456, false)
|
|
122
|
+
|
|
123
|
+
server.start
|
|
124
|
+
|
|
125
|
+
sleep 0.1
|
|
126
|
+
|
|
127
|
+
http_server_thread = server.instance_variable_get(:@http_server_thread)
|
|
128
|
+
file_watcher_thread = server.instance_variable_get(:@file_watcher_thread)
|
|
129
|
+
|
|
130
|
+
refute_nil server.instance_variable_get(:@http_server_thread)
|
|
131
|
+
assert_nil server.instance_variable_get(:@file_watcher_thread)
|
|
132
|
+
assert_instance_of Thread, server.instance_variable_get(:@http_server_thread)
|
|
133
|
+
assert_nil file_watcher_thread
|
|
134
|
+
|
|
135
|
+
http_server_thread.kill
|
|
136
|
+
|
|
137
|
+
end # test "that server start methods starts the http server and not the file watcher"
|
|
138
|
+
|
|
139
|
+
test "that server stop method stops the http server and file watcher" do
|
|
140
|
+
|
|
141
|
+
site_mock = mock('site')
|
|
142
|
+
site_mock.stubs(:site_path).returns('site_path')
|
|
143
|
+
site_mock.stubs(:get_site_output_directory).returns('site_path/output')
|
|
144
|
+
site_mock.stubs(:get_site_release_directory).returns('site_path/release')
|
|
145
|
+
|
|
146
|
+
http_server_mock = mock('webric_httpserver')
|
|
147
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
148
|
+
http_server_mock.expects(:start)
|
|
149
|
+
http_server_mock.expects(:shutdown)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
file_watcher_mock = mock('file_watcher')
|
|
153
|
+
file_watcher_mock.stubs(:ignore)
|
|
154
|
+
file_watcher_mock.expects(:start)
|
|
155
|
+
file_watcher_mock.expects(:stop)
|
|
156
|
+
|
|
157
|
+
WEBrick::HTTPServer.stubs(:new).returns(http_server_mock)
|
|
158
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
159
|
+
|
|
160
|
+
server = Geb::Server.new(site_mock, 3456, true)
|
|
161
|
+
|
|
162
|
+
server.start
|
|
163
|
+
|
|
164
|
+
sleep 0.1
|
|
165
|
+
|
|
166
|
+
server.stop
|
|
167
|
+
|
|
168
|
+
refute server.instance_variable_get(:@http_server_thread).alive?
|
|
169
|
+
refute server.instance_variable_get(:@file_watcher_thread).alive?
|
|
170
|
+
|
|
171
|
+
end # test "that server stop method stops the http server and file watcher"
|
|
172
|
+
|
|
173
|
+
test "that server stop method stops the http server and not the file watcher" do
|
|
174
|
+
|
|
175
|
+
site_mock = mock('site')
|
|
176
|
+
site_mock.stubs(:site_path).returns('site_path')
|
|
177
|
+
site_mock.stubs(:get_site_output_directory).returns('site_path/output')
|
|
178
|
+
site_mock.stubs(:get_site_release_directory).returns('site_path/release')
|
|
179
|
+
|
|
180
|
+
http_server_mock = mock('webric_httpserver')
|
|
181
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
182
|
+
http_server_mock.expects(:start)
|
|
183
|
+
http_server_mock.expects(:shutdown)
|
|
184
|
+
|
|
185
|
+
file_watcher_mock = mock('file_watcher')
|
|
186
|
+
file_watcher_mock.stubs(:ignore)
|
|
187
|
+
file_watcher_mock.expects(:start).never
|
|
188
|
+
|
|
189
|
+
WEBrick::HTTPServer.stubs(:new).returns(http_server_mock)
|
|
190
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
191
|
+
|
|
192
|
+
server = Geb::Server.new(site_mock, 3456, false)
|
|
193
|
+
|
|
194
|
+
server.start
|
|
195
|
+
|
|
196
|
+
sleep 0.1
|
|
197
|
+
|
|
198
|
+
server.stop
|
|
199
|
+
|
|
200
|
+
refute server.instance_variable_get(:@http_server_thread).alive?
|
|
201
|
+
assert_nil server.instance_variable_get(:@file_watcher_thread)
|
|
202
|
+
|
|
203
|
+
end # test "that server stop method stops the http server and not the file watcher"
|
|
204
|
+
|
|
205
|
+
test "that server get_http_server method returns a webrick http server instance" do
|
|
206
|
+
|
|
207
|
+
# get the next available port
|
|
208
|
+
port = Geb::Test::WebServerProxy.find_available_port
|
|
209
|
+
|
|
210
|
+
# create a temporary directory
|
|
211
|
+
Dir.mktmpdir do |dir|
|
|
212
|
+
|
|
213
|
+
site_mock = mock('site')
|
|
214
|
+
site_mock.stubs(:site_path).returns(dir)
|
|
215
|
+
site_mock.stubs(:get_site_output_directory).returns(dir)
|
|
216
|
+
site_mock.stubs(:get_site_release_directory).returns(dir)
|
|
217
|
+
http_server_mock = mock('webric_httpserver')
|
|
218
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
219
|
+
file_watcher_mock = mock('file_watcher')
|
|
220
|
+
file_watcher_mock.stubs(:ignore)
|
|
221
|
+
|
|
222
|
+
WEBrick::HTTPServer.stubs(:new).returns(http_server_mock)
|
|
223
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
224
|
+
|
|
225
|
+
geb_server = Geb::Server.new(site_mock, port, true)
|
|
226
|
+
|
|
227
|
+
WEBrick::HTTPServer.unstub(:new)
|
|
228
|
+
|
|
229
|
+
original_stdout = $stdout
|
|
230
|
+
original_stderr = $stderr
|
|
231
|
+
|
|
232
|
+
$stdout = StringIO.new
|
|
233
|
+
$stderr = StringIO.new
|
|
234
|
+
|
|
235
|
+
http_server = geb_server.send(:get_http_server)
|
|
236
|
+
|
|
237
|
+
# restore stdout and stderr
|
|
238
|
+
$stdout = original_stdout
|
|
239
|
+
$stderr = original_stderr
|
|
240
|
+
|
|
241
|
+
assert_instance_of WEBrick::HTTPServer, http_server
|
|
242
|
+
assert_equal port, http_server.config[:Port]
|
|
243
|
+
assert_equal dir, http_server.config[:DocumentRoot]
|
|
244
|
+
|
|
245
|
+
end # Dir.mktmpdir
|
|
246
|
+
|
|
247
|
+
end # test "that server get_http_server method returns a webrick http server instance"
|
|
248
|
+
|
|
249
|
+
test "that server get_file_watcher method returns a listen instance" do
|
|
250
|
+
|
|
251
|
+
# create a temporary directory
|
|
252
|
+
Dir.mktmpdir do |dir|
|
|
253
|
+
|
|
254
|
+
site_mock = mock('site')
|
|
255
|
+
site_mock.stubs(:site_path).returns(dir)
|
|
256
|
+
site_mock.stubs(:get_site_output_directory).returns(dir)
|
|
257
|
+
site_mock.stubs(:get_site_release_directory).returns(dir)
|
|
258
|
+
http_server_mock = mock('webric_httpserver')
|
|
259
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
260
|
+
file_watcher_mock = mock('file_watcher')
|
|
261
|
+
file_watcher_mock.stubs(:ignore)
|
|
262
|
+
|
|
263
|
+
WEBrick::HTTPServer.stubs(:new).returns(http_server_mock)
|
|
264
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
265
|
+
|
|
266
|
+
geb_server = Geb::Server.new(site_mock, 8888, true)
|
|
267
|
+
|
|
268
|
+
Listen.unstub(:to)
|
|
269
|
+
file_watcher = geb_server.send(:get_file_watcher)
|
|
270
|
+
backend = file_watcher.instance_variable_get(:@backend)
|
|
271
|
+
adapter = backend.instance_variable_get(:@adapter)
|
|
272
|
+
config = adapter.instance_variable_get(:@config)
|
|
273
|
+
|
|
274
|
+
assert_instance_of Listen::Listener, file_watcher
|
|
275
|
+
assert_includes config.directories.first.to_s, dir
|
|
276
|
+
|
|
277
|
+
end # Dir.mktmpdir
|
|
278
|
+
|
|
279
|
+
end # test "that server get_file_watcher method returns a listen instance"
|
|
280
|
+
|
|
281
|
+
test "that the server detects file changes and rebuilds the site" do
|
|
282
|
+
|
|
283
|
+
# create a temporary directory
|
|
284
|
+
Dir.mktmpdir do |dir|
|
|
285
|
+
|
|
286
|
+
site_dir = File.join(dir, 'newsite')
|
|
287
|
+
site_output_directory = File.join(site_dir, 'output/local')
|
|
288
|
+
site_release_directory = File.join(site_dir, 'output/release')
|
|
289
|
+
|
|
290
|
+
file_path_add = File.join(site_dir, 'add.html')
|
|
291
|
+
file_path_modify = File.join(site_dir, 'modify.html')
|
|
292
|
+
file_path_delete = File.join(site_dir, 'delete.html')
|
|
293
|
+
|
|
294
|
+
FileUtils.mkdir_p(site_dir)
|
|
295
|
+
FileUtils.mkdir_p(site_output_directory)
|
|
296
|
+
FileUtils.mkdir_p(site_release_directory)
|
|
297
|
+
|
|
298
|
+
FileUtils.touch(file_path_modify)
|
|
299
|
+
File.write(file_path_modify, 'modify file original content')
|
|
300
|
+
FileUtils.touch(file_path_delete)
|
|
301
|
+
File.write(file_path_delete, 'delete file content')
|
|
302
|
+
|
|
303
|
+
site_mock = mock('site')
|
|
304
|
+
site_mock.stubs(:site_path).returns(site_dir)
|
|
305
|
+
site_mock.stubs(:get_site_output_directory).returns(site_output_directory)
|
|
306
|
+
site_mock.stubs(:get_site_release_directory).returns(site_release_directory)
|
|
307
|
+
site_mock.expects(:build).times(1)
|
|
308
|
+
|
|
309
|
+
http_server_mock = mock('webric_httpserver')
|
|
310
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
311
|
+
file_watcher_mock = mock('file_watcher')
|
|
312
|
+
file_watcher_mock.stubs(:ignore)
|
|
313
|
+
|
|
314
|
+
WEBrick::HTTPServer.stubs(:new).returns(http_server_mock)
|
|
315
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
316
|
+
|
|
317
|
+
geb_server = Geb::Server.new(site_mock, 8888, true)
|
|
318
|
+
|
|
319
|
+
Listen.unstub(:to)
|
|
320
|
+
|
|
321
|
+
log_output = ""
|
|
322
|
+
Geb.stubs(:log_start) { |*args| log_output << args.first }
|
|
323
|
+
Geb.stubs(:log) { |*args| log_output << args.first }
|
|
324
|
+
|
|
325
|
+
# initialize a sequence
|
|
326
|
+
Geb.expects(:log_start).times(1).with("Found changes, rebuilding site ... ")
|
|
327
|
+
Geb.expects(:log).times(4)
|
|
328
|
+
|
|
329
|
+
file_watcher = geb_server.send(:get_file_watcher)
|
|
330
|
+
|
|
331
|
+
file_watcher.start
|
|
332
|
+
|
|
333
|
+
sleep 0.5
|
|
334
|
+
|
|
335
|
+
FileUtils.touch(file_path_add)
|
|
336
|
+
File.write(file_path_add, 'add file content')
|
|
337
|
+
File.write(file_path_modify, 'modify file modified content')
|
|
338
|
+
FileUtils.rm(file_path_delete)
|
|
339
|
+
|
|
340
|
+
sleep 0.5
|
|
341
|
+
|
|
342
|
+
file_watcher.stop
|
|
343
|
+
|
|
344
|
+
end # Dir.mktmpdir
|
|
345
|
+
|
|
346
|
+
end # test "that the server detects file changes and rebuilds the site"
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
test "that the server detects file changes handles exception is build fails" do
|
|
350
|
+
|
|
351
|
+
# create a temporary directory
|
|
352
|
+
Dir.mktmpdir do |dir|
|
|
353
|
+
|
|
354
|
+
site_dir = File.join(dir, 'newsite')
|
|
355
|
+
site_output_directory = File.join(site_dir, 'output/local')
|
|
356
|
+
site_release_directory = File.join(site_dir, 'output/release')
|
|
357
|
+
|
|
358
|
+
file_path_add = File.join(site_dir, 'add.html')
|
|
359
|
+
file_path_modify = File.join(site_dir, 'modify.html')
|
|
360
|
+
file_path_delete = File.join(site_dir, 'delete.html')
|
|
361
|
+
|
|
362
|
+
FileUtils.mkdir_p(site_dir)
|
|
363
|
+
FileUtils.mkdir_p(site_output_directory)
|
|
364
|
+
FileUtils.mkdir_p(site_release_directory)
|
|
365
|
+
|
|
366
|
+
FileUtils.touch(file_path_modify)
|
|
367
|
+
File.write(file_path_modify, 'modify file original content')
|
|
368
|
+
FileUtils.touch(file_path_delete)
|
|
369
|
+
File.write(file_path_delete, 'delete file content')
|
|
370
|
+
|
|
371
|
+
site_mock = mock('site')
|
|
372
|
+
site_mock.stubs(:site_path).returns(site_dir)
|
|
373
|
+
site_mock.stubs(:get_site_output_directory).returns(site_output_directory)
|
|
374
|
+
site_mock.stubs(:get_site_release_directory).returns(site_release_directory)
|
|
375
|
+
site_mock.expects(:build).raises(Geb::Error, "Build failed")
|
|
376
|
+
|
|
377
|
+
http_server_mock = mock('webric_httpserver')
|
|
378
|
+
http_server_mock.stubs(:config).returns({:Port => 3456, :DocumentRoot => 'site_path/output'})
|
|
379
|
+
file_watcher_mock = mock('file_watcher')
|
|
380
|
+
file_watcher_mock.stubs(:ignore)
|
|
381
|
+
|
|
382
|
+
WEBrick::HTTPServer.stubs(:new).returns(http_server_mock)
|
|
383
|
+
Listen.stubs(:to).returns(file_watcher_mock)
|
|
384
|
+
|
|
385
|
+
geb_server = Geb::Server.new(site_mock, 8888, true)
|
|
386
|
+
|
|
387
|
+
Listen.unstub(:to)
|
|
388
|
+
|
|
389
|
+
log_output = ""
|
|
390
|
+
Geb.stubs(:log_start) { |*args| log_output << args.first }
|
|
391
|
+
Geb.stubs(:log) { |*args| log_output << args.first }
|
|
392
|
+
|
|
393
|
+
# initialize a sequence
|
|
394
|
+
Geb.expects(:log_start).times(1).with("Found changes, rebuilding site ... ")
|
|
395
|
+
Geb.expects(:log).times(4)
|
|
396
|
+
|
|
397
|
+
file_watcher = geb_server.send(:get_file_watcher)
|
|
398
|
+
|
|
399
|
+
file_watcher.start
|
|
400
|
+
|
|
401
|
+
sleep 0.5
|
|
402
|
+
|
|
403
|
+
FileUtils.touch(file_path_add)
|
|
404
|
+
File.write(file_path_add, 'add file content')
|
|
405
|
+
File.write(file_path_modify, 'modify file modified content')
|
|
406
|
+
FileUtils.rm(file_path_delete)
|
|
407
|
+
|
|
408
|
+
sleep 0.5
|
|
409
|
+
|
|
410
|
+
file_watcher.stop
|
|
411
|
+
|
|
412
|
+
end # Dir.mktmpdir
|
|
413
|
+
|
|
414
|
+
end # test "that the server detects file changes and rebuilds the site"
|
|
415
|
+
|
|
416
|
+
end # class TestServer < Geb::ApiTest
|