slinky 0.2.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/slinky.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{slinky}
8
- s.version = "0.2.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mwylde"]
12
- s.date = %q{2011-04-21}
12
+ s.date = %q{2011-08-09}
13
13
  s.default_executable = %q{slinky}
14
14
  s.description = %q{A static file server for rich javascript apps that automatically compiles SASS, HAML, CoffeeScript and more}
15
15
  s.email = %q{mwylde@wesleyan.edu}
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
+ ".rspec",
23
24
  "Gemfile",
24
25
  "LICENSE.txt",
25
26
  "README.md",
@@ -27,12 +28,15 @@ Gem::Specification.new do |s|
27
28
  "VERSION",
28
29
  "bin/slinky",
29
30
  "lib/slinky.rb",
31
+ "lib/slinky/builder.rb",
30
32
  "lib/slinky/compiled_file.rb",
33
+ "lib/slinky/compilers.rb",
31
34
  "lib/slinky/compilers/coffee-compiler.rb",
32
35
  "lib/slinky/compilers/coffee-helper",
33
36
  "lib/slinky/compilers/haml-compiler.rb",
34
37
  "lib/slinky/compilers/sass-compiler.rb",
35
38
  "lib/slinky/em-popen3.rb",
39
+ "lib/slinky/manifest.rb",
36
40
  "lib/slinky/runner.rb",
37
41
  "lib/slinky/server.rb",
38
42
  "slinky.gemspec",
@@ -57,35 +61,50 @@ Gem::Specification.new do |s|
57
61
  s.add_runtime_dependency(%q<eventmachine_httpserver>, [">= 0.2.0"])
58
62
  s.add_runtime_dependency(%q<rainbow>, [">= 1.1.1"])
59
63
  s.add_runtime_dependency(%q<haml>, [">= 3.0.0"])
64
+ s.add_runtime_dependency(%q<sass>, [">= 3.1.1"])
60
65
  s.add_runtime_dependency(%q<coffee-script>, [">= 2.2.0"])
61
- s.add_development_dependency(%q<bacon>, [">= 0"])
66
+ s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
67
+ s.add_runtime_dependency(%q<yui-compressor>, [">= 0.9.6"])
68
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
62
69
  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
63
70
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
64
71
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
65
- s.add_development_dependency(%q<rcov>, [">= 0"])
72
+ s.add_development_dependency(%q<cover_me>, [">= 1.0.0.rc6"])
73
+ s.add_development_dependency(%q<fakefs>, [">= 0"])
74
+ s.add_development_dependency(%q<em-http-request>, [">= 0"])
66
75
  else
67
76
  s.add_dependency(%q<eventmachine>, [">= 0.12.0"])
68
77
  s.add_dependency(%q<eventmachine_httpserver>, [">= 0.2.0"])
69
78
  s.add_dependency(%q<rainbow>, [">= 1.1.1"])
70
79
  s.add_dependency(%q<haml>, [">= 3.0.0"])
80
+ s.add_dependency(%q<sass>, [">= 3.1.1"])
71
81
  s.add_dependency(%q<coffee-script>, [">= 2.2.0"])
72
- s.add_dependency(%q<bacon>, [">= 0"])
82
+ s.add_dependency(%q<mime-types>, [">= 1.16"])
83
+ s.add_dependency(%q<yui-compressor>, [">= 0.9.6"])
84
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
73
85
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
74
86
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
75
87
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
76
- s.add_dependency(%q<rcov>, [">= 0"])
88
+ s.add_dependency(%q<cover_me>, [">= 1.0.0.rc6"])
89
+ s.add_dependency(%q<fakefs>, [">= 0"])
90
+ s.add_dependency(%q<em-http-request>, [">= 0"])
77
91
  end
78
92
  else
79
93
  s.add_dependency(%q<eventmachine>, [">= 0.12.0"])
80
94
  s.add_dependency(%q<eventmachine_httpserver>, [">= 0.2.0"])
81
95
  s.add_dependency(%q<rainbow>, [">= 1.1.1"])
82
96
  s.add_dependency(%q<haml>, [">= 3.0.0"])
97
+ s.add_dependency(%q<sass>, [">= 3.1.1"])
83
98
  s.add_dependency(%q<coffee-script>, [">= 2.2.0"])
84
- s.add_dependency(%q<bacon>, [">= 0"])
99
+ s.add_dependency(%q<mime-types>, [">= 1.16"])
100
+ s.add_dependency(%q<yui-compressor>, [">= 0.9.6"])
101
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
85
102
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
86
103
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
87
104
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
88
- s.add_dependency(%q<rcov>, [">= 0"])
105
+ s.add_dependency(%q<cover_me>, [">= 1.0.0.rc6"])
106
+ s.add_dependency(%q<fakefs>, [">= 0"])
107
+ s.add_dependency(%q<em-http-request>, [">= 0"])
89
108
  end
90
109
  end
91
110
 
data/spec/slinky_spec.rb CHANGED
@@ -1,7 +1,318 @@
1
- require 'spec_helper'
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'em-http'
2
3
 
3
4
  describe "Slinky" do
4
- it "fails" do
5
- should.flunk "hey buddy, you should probably rename this file and start specing for real"
5
+ context "Runner" do
6
+ it "should output help" do
7
+ $stdout.should_receive(:puts).with(/Usage: slinky/)
8
+ lambda { ::Slinky::Runner.new(["--help"]).run }.should raise_error SystemExit
9
+ end
10
+
11
+ it "should output a version" do
12
+ $stdout.should_receive(:puts).with(/slinky \d+\.\d+\.\d+/)
13
+ FakeFS.deactivate!
14
+ lambda { ::Slinky::Runner.new(["--version"]).run }.should raise_error SystemExit
15
+ FakeFS.activate!
16
+ end
17
+ end
18
+
19
+ context "Manifest" do
20
+ before :each do
21
+ @mprod = Slinky::Manifest.new("/src", :devel => false, :build_to => "/build")
22
+ @mdevel = Slinky::Manifest.new("/src")
23
+ @md_prod = @mprod.manifest_dir
24
+ @md_devel = @mdevel.manifest_dir
25
+ end
26
+
27
+ it "should build manifest dir with all files in current dir" do
28
+ @md_prod.files.collect{|f| f.source}.should == ["/src/test.haml"]
29
+ @md_devel.files.collect{|f| f.source}.should == ["/src/test.haml"]
30
+ end
31
+
32
+ it "should build manifest with all files in fs" do
33
+ @mprod.files.collect{|f|
34
+ f.source
35
+ }.sort.should == @files.collect{|x| "/src/" + x}.sort
36
+ @mdevel.files.collect{|f|
37
+ f.source
38
+ }.sort.should == @files.collect{|x| "/src/" + x}.sort
39
+ end
40
+
41
+ it "should find files in the manifest by path" do
42
+ @mdevel.find_by_path("test.haml").source.should == "/src/test.haml"
43
+ @mdevel.find_by_path("asdf.haml").should == nil
44
+ @mdevel.find_by_path("l1/l2/test.txt").source.should == "/src/l1/l2/test.txt"
45
+ @mdevel.find_by_path("l1/test.css").source.should == "/src/l1/test.sass"
46
+ end
47
+
48
+ it "should produce the correct scripts string for production" do
49
+ @mprod.scripts_string.should == '<script type="text/javscript" src="/scripts.js"></script>'
50
+ end
51
+
52
+ it "should produce the correct scripts string for devel" do
53
+ @mdevel.scripts_string.should == '<script type="text/javascript" src="l1/test5.js"></script><script type="text/javascript" src="l1/l2/test6.js"></script><script type="text/javascript" src="l1/test2.js"></script><script type="text/javascript" src="l1/l2/test3.js"></script><script type="text/javascript" src="l1/test.js"></script>'
54
+ end
55
+
56
+ it "should produce the correct styles string for production" do
57
+ @mprod.styles_string.should == '<link rel="stylesheet" href="/styles.css" />'
58
+ end
59
+
60
+ it "should produce the correct styles string for development" do
61
+ File.open("/src/l1/l2/bad.sass", "w+"){|f|
62
+ f.write "require('../test.sass')\ncolor: red;"
63
+ }
64
+ manifest = Slinky::Manifest.new("/src")
65
+ @mdevel.styles_string.should == '<link rel="stylesheet" href="l1/test.css" /><link rel="stylesheet" href="l1/l2/test2.css" />'
66
+ end
67
+
68
+ it "should allow the creation of ManifestFiles" do
69
+ mf = Slinky::ManifestFile.new("/src/test.haml", "", @mprod)
70
+ end
71
+
72
+ it "should correctly determine output_path" do
73
+ mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
74
+ mf.output_path.to_s.should == "/src/test.html"
75
+ mf = Slinky::ManifestFile.new("/src/l1/test.js", "/src/build", @mprod)
76
+ mf.output_path.to_s.should == "/src/l1/test.js"
77
+ end
78
+
79
+ it "should correctly determine relative_output_path" do
80
+ mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
81
+ mf.relative_output_path.to_s.should == "test.html"
82
+ mf = Slinky::ManifestFile.new("/src/l1/test.js", "/src/build", @mprod)
83
+ mf.relative_output_path.to_s.should == "l1/test.js"
84
+ end
85
+
86
+ it "should build tmp file without directives" do
87
+ original = "/src/test.haml"
88
+ mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
89
+ path = mf.handle_directives mf.source
90
+ File.read(original).match(/slinky_scripts|slinky_styles/).should_not == nil
91
+ File.read(path).match(/slinky_scripts|slinky_styles/).should == nil
92
+ end
93
+
94
+ it "should compile files that need it" do
95
+ $stdout.should_receive(:puts).with("Compiled /src/test.haml".foreground(:green))
96
+ mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
97
+ build_path = mf.process mf.build_to
98
+ build_path.to_s.split(".")[-1].should == "html"
99
+ File.read("/src/test.haml").match("<head>").should == nil
100
+ File.read(build_path).match("<head>").should_not == nil
101
+
102
+ $stdout.should_receive(:puts).with("Compiled /src/test.haml".foreground(:green))
103
+ mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
104
+ build_path = mf.process "/src/build/test.html"
105
+ File.read("/src/build/test.html").match("<head>").should_not == nil
106
+ end
107
+
108
+ it "should report errors for bad files" do
109
+ File.open("/src/l1/l2/bad.sass", "w+"){|f|
110
+ f.write "color: red;"
111
+ }
112
+ $stderr.should_receive(:puts).with(/Failed on/)
113
+ mf = Slinky::ManifestFile.new("/src/l1/l2/bad.sass", "/src/build", @mprod)
114
+ build_path = mf.process
115
+ build_path.should == nil
116
+ end
117
+
118
+ it "shouldn't crash on syntax errors" do
119
+ File.open("/src/l1/asdf.haml", "w+"){|f|
120
+ f.write("%h1{:width => 50px}")
121
+ }
122
+ $stderr.should_receive(:puts).with(/Failed on/)
123
+ mf = Slinky::ManifestFile.new("/src/l1/asdf.haml", "/src/build", @mprod)
124
+ build_path = mf.process
125
+ build_path.should == nil
126
+ end
127
+
128
+ it "should properly determine build directives" do
129
+ mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
130
+ mf.find_directives.should == {:slinky_scripts => [], :slinky_styles => []}
131
+ mf = Slinky::ManifestFile.new("/src/l1/test.js", "/src/build", @mprod)
132
+ mf.find_directives.should == {:slinky_require => ["test2.js", "l2/test3.js"]}
133
+ end
134
+
135
+ it "should properly determine build_to path" do
136
+ mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
137
+ mf.build_to.should == Pathname.new("/src/build/test.html")
138
+ mf = Slinky::ManifestFile.new("/src/l1/test.js", "/src/build", @mprod)
139
+ mf.build_to.should == Pathname.new("/src/build/test.js")
140
+ end
141
+
142
+ it "should build both compiled files and non-compiled files" do
143
+ $stdout.should_receive(:puts).with("Compiled /src/test.haml".foreground(:green))
144
+ mf = Slinky::ManifestFile.new("/src/test.haml", "/src/build", @mprod)
145
+ path = mf.build
146
+ path.to_s.should == "/src/build/test.html"
147
+ File.read("/src/test.haml").match("<head>").should == nil
148
+ File.read(path).match("<head>").should_not == nil
149
+
150
+ $stdout.should_not_receive(:puts)
151
+ mf = Slinky::ManifestFile.new("/src/l1/l2/test.txt", "/src/build/l1/l2", @mprod)
152
+ path = mf.build
153
+ path.to_s.should == "/src/build/l1/l2/test.txt"
154
+ File.read("/src/build/l1/l2/test.txt").should == "hello\n"
155
+ end
156
+
157
+ it "should match files" do
158
+ mf = Slinky::ManifestFile.new("/src/l1/l2/test.txt", "/src/build/l1/l2", @mprod)
159
+ mf.matches?("test.txt").should == true
160
+ mf = Slinky::ManifestFile.new("/src/l1/test.sass", "", @prod)
161
+ mf.matches?("test.css").should == true
162
+ mf.matches?("test.sass").should == true
163
+ end
164
+
165
+ it "should correctly build the dependency graph" do
166
+ @mprod.build_dependency_graph.collect{|x| x.collect{|y| y.source}}.sort.should ==
167
+ [["/src/l1/test2.js", "/src/l1/test.js"],
168
+ ["/src/l1/l2/test3.coffee", "/src/l1/test.js"],
169
+ ["/src/l1/test5.js", "/src/l1/test2.js"],
170
+ ["/src/l1/l2/test6.js", "/src/l1/l2/test3.coffee"]].sort
171
+ end
172
+
173
+ it "should fail if a required file isn't in the manifest" do
174
+ FileUtils.rm("/src/l1/test2.js")
175
+ manifest = Slinky::Manifest.new("/src", :devel => false, :build_to => "/build")
176
+ $stderr.should_receive(:puts).with("Could not find file test2.js required by /src/l1/test.js".foreground(:red))
177
+ proc {
178
+ manifest.build_dependency_graph
179
+ }.should raise_error Slinky::FileNotFoundError
180
+ end
181
+
182
+ it "should build a correct dependency list" do
183
+ @mprod.dependency_list.collect{|x| x.source}.should == ["/src/test.haml", "/src/l1/test.sass", "/src/l1/test5.js", "/src/l1/l2/test.txt", "/src/l1/l2/test2.css", "/src/l1/l2/test6.js", "/src/l1/l2/l3/test2.txt", "/src/l1/test2.js", "/src/l1/l2/test3.coffee", "/src/l1/test.js"]
184
+ end
185
+
186
+ it "should fail if there is a cycle in the dependency graph" do
187
+ File.open("/src/l1/test5.js", "w+"){|f| f.write("slinky_require('test.js')")}
188
+ manifest = Slinky::Manifest.new("/src", :devel => false, :build_to => "/build")
189
+ $stderr.should_receive(:puts).with("Dependencies /src/l1/test2.js -> /src/l1/test.js, /src/l1/test5.js -> /src/l1/test2.js, /src/l1/test.js -> /src/l1/test5.js could not be satisfied".foreground(:red))
190
+ proc { manifest.dependency_list }.should raise_error Slinky::DependencyError
191
+ end
192
+
193
+ it "should ignore the build directory" do
194
+ $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(6).times
195
+ Slinky::Builder.build("/src", "/src/build")
196
+ File.exists?("/src/build/build").should_not == true
197
+ File.exists?("/src/build/test.html").should == true
198
+ Slinky::Builder.build("/src", "/src/build")
199
+ File.exists?("/src/build/build").should_not == true
200
+ end
201
+
202
+ it "should combine and compress javascript" do
203
+ $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
204
+ @mprod.build
205
+ File.exists?("/build/scripts.js").should == true
206
+ File.size("/build/scripts.js").should > 90
207
+ File.read("/build/scripts.js").match('"Hello, world"').should_not == nil
208
+ File.exists?("/build/l1/test.js").should == false
209
+ end
210
+
211
+ it "should combine and compress css" do
212
+ $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
213
+ @mprod.build
214
+ File.exists?("/build/styles.css").should == true
215
+ File.size("/build/styles.css").should > 25
216
+ File.read("/build/styles.css").match(/color:red/).should_not == nil
217
+ File.exists?("/build/l1/test.css").should == false
218
+ end
219
+
220
+ it "should modify css urls to point to correct paths when compiled" do
221
+ $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
222
+ @mprod.build
223
+ css = File.read("/build/styles.css")
224
+ css.include?("url('/l1/asdf.png')").should == true
225
+ css.include?("url('l1/bg.png')").should == true
226
+ css.include?("url('l1/l2/l3/hello.png')").should == true
227
+ end
228
+ end
229
+
230
+ context "Server" do
231
+ before :each do
232
+ @resp = double("EventMachine::DelegatedHttpResponse")
233
+ @resp.stub(:content=){|c| @content = c}
234
+ @resp.stub(:content){ @content }
235
+ end
236
+
237
+ it "path_for_uri should work correctly" do
238
+ Slinky::Server.path_for_uri("http://localhost:124/test/hello/asdf.js?query=string&another").should == "test/hello/asdf.js"
239
+ end
240
+
241
+ it "should serve files" do
242
+ @resp.should_receive(:content_type).with(MIME::Types.type_for("/src/l1/test.js").first)
243
+ Slinky::Server.serve_file @resp, "/src/l1/test.js"
244
+ @resp.content.should == File.read("/src/l1/test.js")
245
+ end
246
+
247
+ it "should serve 404s" do
248
+ @resp.should_receive(:status=).with(404)
249
+ Slinky::Server.serve_file @resp, "/src/asdf/faljshd"
250
+ @resp.content.should == "File not found"
251
+ end
252
+
253
+ it "should handle static files" do
254
+ mf = Slinky::ManifestFile.new("/src/l1/l2/test.txt", nil, @mdevel)
255
+ @resp.should_receive(:content_type).with(MIME::Types.type_for("/src/l1/le/test.txt").first)
256
+ Slinky::Server.handle_file @resp, mf
257
+ @resp.content.should == File.read("/src/l1/l2/test.txt")
258
+ end
259
+
260
+ it "should handle compiled files" do
261
+ mf = Slinky::ManifestFile.new("/src/l1/test.sass", nil, @mdevel)
262
+ @resp.should_receive(:content_type).with(MIME::Types.type_for("test.css").first)
263
+ $stdout.should_receive(:puts).with("Compiled /src/l1/test.sass".foreground(:green))
264
+ Slinky::Server.handle_file @resp, mf
265
+ @resp.content.should == Slinky::SassCompiler::compile(File.read("/src/l1/test.sass"), "")
266
+ end
267
+
268
+ it "should handle non-existant files" do
269
+ mf = Slinky::ManifestFile.new("/src/l1/asdf.txt", nil, @mdevel)
270
+ @resp.should_receive(:status=).with(404)
271
+ Slinky::Server.handle_file @resp, mf
272
+ @resp.content.should == "File not found"
273
+ end
274
+
275
+ it "should accept a port option" do
276
+ port = 53453
277
+ $stdout.should_receive(:puts).with(/Started static file server on port #{port}/)
278
+ run_for 0.3 do
279
+ Slinky::Runner.new(["start","--port", port.to_s]).run
280
+ end
281
+ end
282
+
283
+ # it "should serve files for realz" do
284
+ # $stdout.should_receive(:puts).with(/Started static file server on port 43453/)
285
+ # @results = []
286
+ # run_for 3 do
287
+ # Slinky::Runner.new(["start","--port", "43453", "--src-dir", "/src"]).run
288
+ # base = "http://localhost:43453"
289
+ # multi = EventMachine::MultiRequest.new
290
+
291
+ # # add multiple requests to the multi-handler
292
+ # multi.add(EventMachine::HttpRequest.new("#{base}/index.html").get)
293
+ # multi.add(EventMachine::HttpRequest.new(base).get)
294
+ # multi.callback do
295
+ # multi.responses[:succeeded].size.should == 2
296
+ # multi.responses[:succeeded].each{|r|
297
+ # $stderr.puts r.response
298
+ # r.response.include?("hello").should == true
299
+ # }
300
+ # multi.responses[:failed].size.should == 0
301
+ # EM.stop_event_loop
302
+ # end
303
+ # end
304
+ # end
305
+ end
306
+ context "Builder" do
307
+ before :each do
308
+ @compilation_subs = {".sass" => ".css", ".coffee" => ".js", ".haml" => ".html"}
309
+ end
310
+ it "should build manifest to build directory" do
311
+ $stdout.should_receive(:puts).with(/Compiled \/src\/.+/).exactly(3).times
312
+ Slinky::Builder.build("/src", "/build")
313
+ File.exists?("/build").should == true
314
+ File.exists?("/build/scripts.js").should == true
315
+ File.exists?("/build/l1/l2/test.txt").should == true
316
+ end
6
317
  end
7
318
  end
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,116 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'slinky'
5
+ require 'fakefs/safe'
6
+ require 'fileutils'
7
+ require 'open-uri'
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+
14
+ module FakeFS
15
+ class File
16
+ def self.absolute_path(*args)
17
+ RealFile.absolute_path(*args)
18
+ end
19
+ end
9
20
  end
10
- require 'bacon'
11
21
 
12
- $LOAD_PATH.unshift(File.dirname(__FILE__))
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
- require 'static-runner'
15
22
 
16
- Bacon.summary_on_exit
23
+ module Slinky
24
+ module CoffeeCompiler
25
+ def CoffeeCompiler::compile s, file
26
+ FakeFS.deactivate!
27
+ o = CoffeeScript::compile(s)
28
+ FakeFS.activate!
29
+ o
30
+ end
31
+ end
32
+ end
33
+
34
+ RSpec.configure do |config|
35
+ config.before :all do
36
+ FakeFS.activate!
37
+ FileUtils.mkdir("/tmp")
38
+ end
39
+ config.before :each do
40
+ FileUtils.rm_rf("/src") rescue nil
41
+ FileUtils.mkdir("/src")
42
+ FileUtils.mkdir_p("/src/l1/l2/l3")
43
+ File.open("/src/test.haml", "w+"){|f|
44
+ f.write <<eos
45
+ !!!5
46
+ %head
47
+ slinky_scripts
48
+ slinky_styles
49
+ :plain
50
+ does this screw it up?
51
+ %body
52
+ h1. hello
53
+ eos
54
+ }
55
+
56
+ File.open("/src/l1/test.sass", "w+"){|f|
57
+ f.write <<eos
58
+ h1
59
+ color: red
60
+ background-image: url("bg.png")
61
+ eos
62
+ }
63
+
64
+ File.open("/src/l1/l2/test2.css", "w+"){|f|
65
+ f.write <<eos
66
+ h2 { color: green; }
67
+ div { background: url('/l1/asdf.png')}
68
+ .something {background: url('l3/hello.png')}
69
+ eos
70
+ }
71
+
72
+ File.open("/src/l1/test.js", "w+"){|f|
73
+ f.write <<eos
74
+ slinky_require('test2.js')
75
+ slinky_require("l2/test3.js")
76
+ eos
77
+ }
78
+
79
+ File.open("/src/l1/test2.js", "w+"){|f|
80
+ f.write <<eos
81
+ slinky_require('test5.js')
82
+ eos
83
+ }
84
+
85
+ File.open("/src/l1/l2/test3.coffee", "w+"){|f|
86
+ f.write <<eos
87
+ slinky_require('test6.js')
88
+ test = {do: (x) -> console.log(x)}
89
+ test.do("Hello, world")
90
+ eos
91
+ }
92
+
93
+ File.open("/src/l1/test5.js", "w+").close()
94
+ File.open("/src/l1/l2/test6.js", "w+").close()
95
+
96
+ File.open("/src/l1/l2/test.txt", "w+"){|f| f.write("hello\n") }
97
+ File.open("/src/l1/l2/l3/test2.txt", "w+"){|f| f.write("goodbye\n") }
98
+
99
+ @files = ["test.haml", "l1/test.js", "l1/test.sass", "l1/l2/test2.css", "l1/l2/test.txt", "l1/l2/l3/test2.txt", "l1/test2.js", "l1/l2/test3.coffee", "l1/test5.js", "l1/l2/test6.js"]
100
+
101
+ end
102
+
103
+ config.after :all do
104
+ FakeFS.deactivate!
105
+ end
106
+ end
107
+
108
+ def run_for secs
109
+ EM.run do
110
+ yield
111
+ EM.add_timer(secs) {
112
+ EM.stop_event_loop
113
+ }
114
+ end
115
+ end
116
+