-
Notifications
You must be signed in to change notification settings - Fork 3
/
runner_spec.rb
390 lines (319 loc) · 10.6 KB
/
runner_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
require "spec_helper"
require PROJECT_ROOT + "lib/mango/runner"
describe Mango::Runner do
#################################################################################################
describe "class methods and attributes" do
before(:all) do
@runner = Mango::Runner.new
end
it "is a kind of Thor" do
expect(@runner).to be_a_kind_of(Thor)
end
it "is a kind of Thor::Actions" do
expect(@runner).to be_a_kind_of(Thor::Actions)
end
it "adds runtime options" do
expect(Mango::Runner.class_options).to have_key(:force)
expect(Mango::Runner.class_options).to have_key(:pretend)
expect(Mango::Runner.class_options).to have_key(:quiet)
expect(Mango::Runner.class_options).to have_key(:skip)
end
it "has a source root" do
expect(@runner.source_paths).to include (PROJECT_ROOT + "lib/mango/templates").to_s
end
it "has a create task" do
task = Mango::Runner.tasks["create"]
expect(task.name).to eq("create")
expect(task.description).to eq("Creates a new Mango application at the specified path")
end
end
#################################################################################################
describe "#create" do
before(:all) do
$stdout = StringIO.new
@runner = Mango::Runner.new
@runner.create(RUNNER_ROOT)
end
after(:all) do
RUNNER_ROOT.rmtree
$stdout = STDOUT
end
it "generates the destination root" do
expect(RUNNER_ROOT).to be_a_directory
end
it "generates .gitignore" do
expected = RUNNER_ROOT + ".gitignore"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
.DS_Store
.bundle
.sass-cache
bin
vendor/bundle
EOS
end
it "generates config.ru" do
expected = RUNNER_ROOT + "config.ru"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
require "mango"
run Mango::Application
EOS
end
it "generates Gemfile" do
expected = RUNNER_ROOT + "Gemfile"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
source "http://rubygems.org"
ruby "2.1.2"
gem "mango", "~> 0.9.0"
EOS
end
it "generates Procfile" do
expected = RUNNER_ROOT + "Procfile"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
web: bundle exec puma config.ru -p $PORT
EOS
end
it "generates README.md" do
expected = RUNNER_ROOT + "README.md"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
Your Mango Application Name
===========================
Summary
-------
Getting Started
---------------
Publishing
----------
Credits
-------
EOS
end
###############################################################################################
it "generates content/" do
expect(RUNNER_ROOT + "content").to be_a_directory
end
it "generates content/index.erb" do
expected = RUNNER_ROOT + "content/index.erb"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
---
title: Congratulations!
---
<h1><%= page.title %></h1>
<h2>You did it!</h2>
EOS
end
###############################################################################################
it "generates themes/" do
expect(RUNNER_ROOT + "themes").to be_a_directory
end
it "generates themes/default" do
expect(RUNNER_ROOT + "themes/default").to be_a_directory
end
###############################################################################################
it "generates themes/default/javascripts" do
expect(RUNNER_ROOT + "themes/default/javascripts").to be_a_directory
end
it "generates themes/default/javascripts/timer.coffee" do
expected = RUNNER_ROOT + "themes/default/javascripts/timer.coffee"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
fire = ->
gap = Math.floor(Math.random() * 1201) + 600
setTimeout(fire, gap)
createFirework(30,125,7,5,null,null,null,null,false,true)
window.onload = fire
EOS
end
###############################################################################################
it "generates themes/default/public" do
expect(RUNNER_ROOT + "themes/default/public").to be_a_directory
end
it "generates themes/default/public/favicon.ico" do
expected = RUNNER_ROOT + "themes/default/public/favicon.ico"
expect(expected).to be_a_file
expect(File.read(expected)).to eq("")
end
it "generates themes/default/public/robots.txt" do
expected = RUNNER_ROOT + "themes/default/public/robots.txt"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
#
# To ban all spiders from the entire site uncomment the next two lines:
# User-Agent: *
# Disallow: /
EOS
end
###############################################################################################
it "generates themes/default/public/images" do
expect(RUNNER_ROOT + "themes/default/public/images").to be_a_directory
end
it "generates themes/default/public/images" do
expected = RUNNER_ROOT + "themes/default/public/images/particles.gif"
expect(expected).to be_a_file
File.open(expected, "rb") { |f| expect(f.read.size).to eq(2469) }
end
###############################################################################################
it "generates themes/default/public/javascripts" do
expect(RUNNER_ROOT + "themes/default/public/javascripts").to be_a_directory
end
it "generates themes/default/public/javascripts/fireworks.js" do
expected = RUNNER_ROOT + "themes/default/public/javascripts/fireworks.js"
expect(expected).to be_a_file
expect(File.read(expected).size).to eq(17167)
end
###############################################################################################
it "generates themes/default/public/stylesheets" do
expect(RUNNER_ROOT + "themes/default/public/stylesheets").to be_a_directory
end
it "generates themes/default/public/stylesheets/fireworks.css" do
expected = RUNNER_ROOT + "themes/default/public/stylesheets/fireworks.css"
expect(expected).to be_a_file
expect(File.read(expected).size).to eq(717)
end
it "generates themes/default/public/stylesheets/reset.css" do
expected = RUNNER_ROOT + "themes/default/public/stylesheets/reset.css"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
/* v1.0 | 20080212 */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
/* remember to define focus styles! */
:focus {
outline: 0;
}
/* remember to highlight inserts somehow! */
ins {
text-decoration: none;
}
del {
text-decoration: line-through;
}
/* tables still need 'cellspacing="0"' in the markup */
table {
border-collapse: collapse;
border-spacing: 0;
}
EOS
end
###############################################################################################
it "generates themes/default/stylesheets" do
expect(RUNNER_ROOT + "themes/default/stylesheets").to be_a_directory
end
it "generates themes/default/stylesheets/screen.sass" do
expected = RUNNER_ROOT + "themes/default/stylesheets/screen.sass"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
body
background-color: #D05C12
font-family: "Lobster", arial, serif
margin: 0px auto
text-align: center
text-shadow: 2px 2px 5px #000
h1
color: #29B7DD
font-size: 90pt
margin: 60px 0px 100px 0px
h2
color: #FBAF0D
font-size: 240pt
EOS
end
###############################################################################################
it "generates themes/default/views" do
expect(RUNNER_ROOT + "themes/default/views").to be_a_directory
end
it "generates themes/default/views/404.haml" do
expected = RUNNER_ROOT + "themes/default/views/404.haml"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
!!! 5
%html
%head
%meta{ charset: "utf-8" }
%title The page you were looking for doesn't exist (404)
:css
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
%body
/ This file lives in themes/default/views/404.haml
%div.dialog
%h1 The page you were looking for doesn't exist.
%p You may have mistyped the address or the page may have moved.
EOS
end
it "generates themes/default/views/layout.haml" do
expected = RUNNER_ROOT + "themes/default/views/layout.haml"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
!!! 5
%html
%head
%meta{ charset: "utf-8" }
%title= "Mango: \#{page.title}"
%link{ rel: "stylesheet", type: "text/css", media: "screen", href: "http://fonts.googleapis.com/css?family=Lobster" }
%link{ rel: "stylesheet", type: "text/css", media: "screen", href: "/stylesheets/reset.css" }
%link{ rel: "stylesheet", type: "text/css", media: "screen", href: "/stylesheets/screen.css" }
%link{ rel: "stylesheet", type: "text/css", media: "screen", href: "/stylesheets/fireworks.css" }
%script{ type: "text/javascript", src: "/javascripts/fireworks.js"}
%script{ type: "text/javascript", src: "/javascripts/timer.js"}
%body
%div#fireworks-template
%div#fw.firework
%div#fp.fireworkParticle
%img{ src: "/images/particles.gif" }
%div#fireContainer
= yield
EOS
end
it "generates themes/default/views/page.haml" do
expected = RUNNER_ROOT + "themes/default/views/page.haml"
expect(expected).to be_a_file
expect(File.read(expected)).to eq <<-EOS
= page.content
EOS
end
end
end