bpm 1.0.0.beta.8 → 1.0.0.beta.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +9 -0
  3. data/bpm.gemspec +2 -7
  4. data/lib/bpm/pipeline/generated_asset.rb +19 -21
  5. data/lib/bpm/pipeline/plugin_context.rb +7 -7
  6. data/lib/bpm/pipeline/plugin_processor.rb +11 -20
  7. data/lib/bpm/pipeline/transport_processor.rb +8 -13
  8. data/lib/bpm/pipeline.rb +47 -42
  9. data/lib/bpm/project_generator.rb +2 -2
  10. data/lib/bpm/version.rb +1 -1
  11. data/lib/bpm.rb +0 -3
  12. data/spec/cli/init_spec.rb +48 -48
  13. data/spec/cli/rebuild_spec.rb +30 -30
  14. data/spec/fixtures/projects/init_app/assets/bpm_libs.js +1 -1
  15. data/spec/fixtures/projects/init_app/assets/bpm_styles.css +1 -1
  16. data/spec/fixtures/projects/init_default/assets/bpm_libs.js +1 -1
  17. data/spec/fixtures/projects/init_default/assets/bpm_styles.css +1 -1
  18. data/spec/plugins/minifier_spec.rb +8 -8
  19. data/templates/project/index.html +0 -2
  20. data/templates/project/{app → lib}/main.js +0 -0
  21. metadata +24 -209
  22. data/.gitmodules +0 -3
  23. data/vendor/sprockets/.gitignore +0 -7
  24. data/vendor/sprockets/.travis.yml +0 -7
  25. data/vendor/sprockets/Gemfile +0 -2
  26. data/vendor/sprockets/LICENSE +0 -20
  27. data/vendor/sprockets/README.md +0 -22
  28. data/vendor/sprockets/Rakefile +0 -8
  29. data/vendor/sprockets/lib/sprockets/asset.rb +0 -198
  30. data/vendor/sprockets/lib/sprockets/asset_attributes.rb +0 -178
  31. data/vendor/sprockets/lib/sprockets/base.rb +0 -134
  32. data/vendor/sprockets/lib/sprockets/bundled_asset.rb +0 -249
  33. data/vendor/sprockets/lib/sprockets/cache/file_store.rb +0 -41
  34. data/vendor/sprockets/lib/sprockets/caching.rb +0 -126
  35. data/vendor/sprockets/lib/sprockets/charset_normalizer.rb +0 -41
  36. data/vendor/sprockets/lib/sprockets/context.rb +0 -221
  37. data/vendor/sprockets/lib/sprockets/digest.rb +0 -73
  38. data/vendor/sprockets/lib/sprockets/directive_processor.rb +0 -397
  39. data/vendor/sprockets/lib/sprockets/eco_template.rb +0 -38
  40. data/vendor/sprockets/lib/sprockets/ejs_template.rb +0 -37
  41. data/vendor/sprockets/lib/sprockets/engines.rb +0 -117
  42. data/vendor/sprockets/lib/sprockets/environment.rb +0 -94
  43. data/vendor/sprockets/lib/sprockets/errors.rb +0 -17
  44. data/vendor/sprockets/lib/sprockets/index.rb +0 -81
  45. data/vendor/sprockets/lib/sprockets/jst_processor.rb +0 -26
  46. data/vendor/sprockets/lib/sprockets/mime.rb +0 -38
  47. data/vendor/sprockets/lib/sprockets/processing.rb +0 -269
  48. data/vendor/sprockets/lib/sprockets/processor.rb +0 -32
  49. data/vendor/sprockets/lib/sprockets/safety_colons.rb +0 -28
  50. data/vendor/sprockets/lib/sprockets/server.rb +0 -270
  51. data/vendor/sprockets/lib/sprockets/static_asset.rb +0 -86
  52. data/vendor/sprockets/lib/sprockets/static_compilation.rb +0 -74
  53. data/vendor/sprockets/lib/sprockets/trail.rb +0 -123
  54. data/vendor/sprockets/lib/sprockets/utils.rb +0 -67
  55. data/vendor/sprockets/lib/sprockets/version.rb +0 -3
  56. data/vendor/sprockets/lib/sprockets.rb +0 -31
  57. data/vendor/sprockets/sprockets.gemspec +0 -30
  58. data/vendor/sprockets/test/fixtures/asset/POW.png +0 -0
  59. data/vendor/sprockets/test/fixtures/asset/application.js +0 -6
  60. data/vendor/sprockets/test/fixtures/asset/bar-utf8.css +0 -2
  61. data/vendor/sprockets/test/fixtures/asset/charset.css +0 -2
  62. data/vendor/sprockets/test/fixtures/asset/circle/a.js +0 -2
  63. data/vendor/sprockets/test/fixtures/asset/circle/b.js +0 -2
  64. data/vendor/sprockets/test/fixtures/asset/circle/c.js +0 -2
  65. data/vendor/sprockets/test/fixtures/asset/compat.js +0 -4
  66. data/vendor/sprockets/test/fixtures/asset/constants.js +0 -2
  67. data/vendor/sprockets/test/fixtures/asset/constants.yml +0 -1
  68. data/vendor/sprockets/test/fixtures/asset/default_mime_type.js +0 -1
  69. data/vendor/sprockets/test/fixtures/asset/filename.js.erb +0 -1
  70. data/vendor/sprockets/test/fixtures/asset/foo-utf8.css +0 -2
  71. data/vendor/sprockets/test/fixtures/asset/included_header.js +0 -4
  72. data/vendor/sprockets/test/fixtures/asset/jquery.tmpl.min.js +0 -1
  73. data/vendor/sprockets/test/fixtures/asset/mismatch.js +0 -1
  74. data/vendor/sprockets/test/fixtures/asset/multiple.js +0 -2
  75. data/vendor/sprockets/test/fixtures/asset/multipleengine.js +0 -1
  76. data/vendor/sprockets/test/fixtures/asset/noengine.js +0 -1
  77. data/vendor/sprockets/test/fixtures/asset/noformat.coffee +0 -1
  78. data/vendor/sprockets/test/fixtures/asset/one.css +0 -1
  79. data/vendor/sprockets/test/fixtures/asset/oneengine.js +0 -1
  80. data/vendor/sprockets/test/fixtures/asset/project.css +0 -1
  81. data/vendor/sprockets/test/fixtures/asset/project.js.erb +0 -4
  82. data/vendor/sprockets/test/fixtures/asset/relative/include.js +0 -4
  83. data/vendor/sprockets/test/fixtures/asset/relative/require.js +0 -1
  84. data/vendor/sprockets/test/fixtures/asset/relative/require_outside_path.js +0 -1
  85. data/vendor/sprockets/test/fixtures/asset/require_self.css +0 -9
  86. data/vendor/sprockets/test/fixtures/asset/require_self_twice.css +0 -8
  87. data/vendor/sprockets/test/fixtures/asset/semicolons/bar.js +0 -1
  88. data/vendor/sprockets/test/fixtures/asset/semicolons/index.js +0 -5
  89. data/vendor/sprockets/test/fixtures/asset/sprite.css.erb +0 -12
  90. data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/d.js +0 -2
  91. data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/e.js +0 -1
  92. data/vendor/sprockets/test/fixtures/asset/tree/all/b/c.js +0 -1
  93. data/vendor/sprockets/test/fixtures/asset/tree/all/b.css +0 -2
  94. data/vendor/sprockets/test/fixtures/asset/tree/all/b.js.erb +0 -1
  95. data/vendor/sprockets/test/fixtures/asset/tree/all/d/c.js.coffee +0 -1
  96. data/vendor/sprockets/test/fixtures/asset/tree/all/d/e.js +0 -1
  97. data/vendor/sprockets/test/fixtures/asset/tree/all_with_require.js +0 -7
  98. data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_directory.js +0 -1
  99. data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_tree.js +0 -2
  100. data/vendor/sprockets/test/fixtures/asset/tree/directory/application.js +0 -2
  101. data/vendor/sprockets/test/fixtures/asset/tree/directory/bar.js +0 -1
  102. data/vendor/sprockets/test/fixtures/asset/tree/directory/foo.js +0 -1
  103. data/vendor/sprockets/test/fixtures/asset/tree/tree/application.js +0 -2
  104. data/vendor/sprockets/test/fixtures/asset/tree/tree/bar.js +0 -1
  105. data/vendor/sprockets/test/fixtures/asset/tree/tree/foo.js +0 -1
  106. data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/a/a.js +0 -1
  107. data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/require_tree_with_logical_path.js +0 -1
  108. data/vendor/sprockets/test/fixtures/asset/tree/without_argument/a.js +0 -1
  109. data/vendor/sprockets/test/fixtures/asset/tree/without_argument/b.js +0 -1
  110. data/vendor/sprockets/test/fixtures/asset/tree/without_argument/require_tree_without_argument.js +0 -1
  111. data/vendor/sprockets/test/fixtures/asset/two.css +0 -1
  112. data/vendor/sprockets/test/fixtures/asset/unicode.js +0 -2
  113. data/vendor/sprockets/test/fixtures/asset/unknownexts.min.js +0 -2
  114. data/vendor/sprockets/test/fixtures/asset/users.js.erb.str +0 -4
  115. data/vendor/sprockets/test/fixtures/context/POW.png +0 -0
  116. data/vendor/sprockets/test/fixtures/context/application.js.yml +0 -3
  117. data/vendor/sprockets/test/fixtures/context/bar.js +0 -1
  118. data/vendor/sprockets/test/fixtures/context/foo.js +0 -2
  119. data/vendor/sprockets/test/fixtures/context/helpers.css.erb +0 -3
  120. data/vendor/sprockets/test/fixtures/context/properties.js.erb +0 -7
  121. data/vendor/sprockets/test/fixtures/context/require_glob.js +0 -1
  122. data/vendor/sprockets/test/fixtures/context/resolve_content_type.js.erb +0 -4
  123. data/vendor/sprockets/test/fixtures/context/sprite.css.embed +0 -3
  124. data/vendor/sprockets/test/fixtures/default/application.js.coffee +0 -4
  125. data/vendor/sprockets/test/fixtures/default/blank.gif +0 -0
  126. data/vendor/sprockets/test/fixtures/default/coffee/foo.coffee +0 -1
  127. data/vendor/sprockets/test/fixtures/default/coffee/index.js +0 -3
  128. data/vendor/sprockets/test/fixtures/default/empty +0 -0
  129. data/vendor/sprockets/test/fixtures/default/gallery.css.erb +0 -3
  130. data/vendor/sprockets/test/fixtures/default/gallery.js +0 -1
  131. data/vendor/sprockets/test/fixtures/default/goodbye.jst.eco +0 -1
  132. data/vendor/sprockets/test/fixtures/default/hello.jst.ejs +0 -1
  133. data/vendor/sprockets/test/fixtures/default/hello.txt +0 -1
  134. data/vendor/sprockets/test/fixtures/default/interpolation.js +0 -1
  135. data/vendor/sprockets/test/fixtures/default/missing_require.js +0 -1
  136. data/vendor/sprockets/test/fixtures/default/mobile/a.js +0 -1
  137. data/vendor/sprockets/test/fixtures/default/mobile/b.js +0 -1
  138. data/vendor/sprockets/test/fixtures/default/mobile/c.css +0 -1
  139. data/vendor/sprockets/test/fixtures/default/mobile/d.css +0 -1
  140. data/vendor/sprockets/test/fixtures/default/mobile/index.css +0 -3
  141. data/vendor/sprockets/test/fixtures/default/mobile/index.js +0 -1
  142. data/vendor/sprockets/test/fixtures/default/noreturn.js +0 -1
  143. data/vendor/sprockets/test/fixtures/default/project.js.coffee.erb +0 -2
  144. data/vendor/sprockets/test/fixtures/default/with_data_uri.css.erb +0 -3
  145. data/vendor/sprockets/test/fixtures/directives/code_before_comment +0 -3
  146. data/vendor/sprockets/test/fixtures/directives/comment_without_directives +0 -6
  147. data/vendor/sprockets/test/fixtures/directives/directive_word_splitting +0 -6
  148. data/vendor/sprockets/test/fixtures/directives/directives_after_header +0 -16
  149. data/vendor/sprockets/test/fixtures/directives/double_slash +0 -9
  150. data/vendor/sprockets/test/fixtures/directives/hash +0 -8
  151. data/vendor/sprockets/test/fixtures/directives/no_header +0 -2
  152. data/vendor/sprockets/test/fixtures/directives/slash_star +0 -10
  153. data/vendor/sprockets/test/fixtures/directives/slash_star_single +0 -4
  154. data/vendor/sprockets/test/fixtures/directives/space_between_directive_word +0 -2
  155. data/vendor/sprockets/test/fixtures/directives/triple_hash +0 -10
  156. data/vendor/sprockets/test/fixtures/encoding/ascii.js +0 -1
  157. data/vendor/sprockets/test/fixtures/encoding/ascii_utf8.js +0 -2
  158. data/vendor/sprockets/test/fixtures/encoding/utf16.js +0 -0
  159. data/vendor/sprockets/test/fixtures/encoding/utf8.js +0 -1
  160. data/vendor/sprockets/test/fixtures/encoding/utf8_bom.js +0 -1
  161. data/vendor/sprockets/test/fixtures/engines/hello.alert +0 -1
  162. data/vendor/sprockets/test/fixtures/engines/moo.js.str +0 -1
  163. data/vendor/sprockets/test/fixtures/public/compiled-digest-0aa2105d29558f3eb790d411d7d8fb66.js +0 -3
  164. data/vendor/sprockets/test/fixtures/public/compiled-digest-1c41eb0cf934a0c76babe875f982f9d1.js +0 -1
  165. data/vendor/sprockets/test/fixtures/server/app/javascripts/application.js +0 -5
  166. data/vendor/sprockets/test/fixtures/server/app/javascripts/bar.js +0 -1
  167. data/vendor/sprockets/test/fixtures/server/app/javascripts/foo.js +0 -1
  168. data/vendor/sprockets/test/fixtures/server/app/javascripts/hello.txt +0 -2
  169. data/vendor/sprockets/test/fixtures/server/app/javascripts/tree.js +0 -1
  170. data/vendor/sprockets/test/fixtures/server/vendor/javascripts/missing_require.js +0 -1
  171. data/vendor/sprockets/test/fixtures/server/vendor/stylesheets/missing_require.css +0 -1
  172. data/vendor/sprockets/test/sprockets_test.rb +0 -56
  173. data/vendor/sprockets/test/test_asset.rb +0 -699
  174. data/vendor/sprockets/test/test_asset_attributes.rb +0 -150
  175. data/vendor/sprockets/test/test_caching.rb +0 -62
  176. data/vendor/sprockets/test/test_context.rb +0 -115
  177. data/vendor/sprockets/test/test_directive_processor.rb +0 -124
  178. data/vendor/sprockets/test/test_encoding.rb +0 -65
  179. data/vendor/sprockets/test/test_engines.rb +0 -73
  180. data/vendor/sprockets/test/test_environment.rb +0 -587
  181. data/vendor/sprockets/test/test_server.rb +0 -227
@@ -1,699 +0,0 @@
1
- require "sprockets_test"
2
-
3
- module AssetTests
4
- def self.test(name, &block)
5
- define_method("test #{name.inspect}", &block)
6
- end
7
-
8
- test "pathname is a Pathname that exists" do
9
- assert_kind_of Pathname, @asset.pathname
10
- assert @asset.pathname.exist?
11
- end
12
-
13
- test "logical path can find itself" do
14
- assert_equal @asset, @env[@asset.logical_path]
15
- end
16
-
17
- test "mtime" do
18
- assert @asset.mtime
19
- end
20
-
21
- test "digest" do
22
- assert @asset.digest
23
- end
24
-
25
- test "stale?" do
26
- assert !@asset.stale?
27
- end
28
-
29
- test "fresh?" do
30
- assert @asset.fresh?
31
- end
32
-
33
- test "dependencies are an Array" do
34
- assert_kind_of Array, @asset.dependencies
35
- end
36
-
37
- test "splat asset" do
38
- assert_kind_of Array, @asset.to_a
39
- end
40
-
41
- test "body is a String" do
42
- assert_kind_of String, @asset.body
43
- end
44
-
45
- test "write to file" do
46
- target = fixture_path('asset/tmp.js')
47
- begin
48
- @asset.write_to(target)
49
- assert File.exist?(target)
50
- assert_equal @asset.mtime, File.mtime(target)
51
- ensure
52
- FileUtils.rm(target) if File.exist?(target)
53
- assert !File.exist?(target)
54
- end
55
- end
56
-
57
- test "write to gzipped file" do
58
- target = fixture_path('asset/tmp.js.gz')
59
- begin
60
- @asset.write_to(target)
61
- assert File.exist?(target)
62
- assert_equal @asset.mtime, File.mtime(target)
63
- ensure
64
- FileUtils.rm(target) if File.exist?(target)
65
- assert !File.exist?(target)
66
- end
67
- end
68
- end
69
-
70
- class StaticAssetTest < Sprockets::TestCase
71
- def setup
72
- @env = Sprockets::Environment.new
73
- @env.append_path(fixture_path('asset'))
74
- @env.cache = {}
75
-
76
- @asset = @env['POW.png']
77
- end
78
-
79
- include AssetTests
80
-
81
- test "class" do
82
- assert_kind_of Sprockets::StaticAsset, @asset
83
- end
84
-
85
- test "content type" do
86
- assert_equal "image/png", @asset.content_type
87
- end
88
-
89
- test "length" do
90
- assert_equal 42917, @asset.length
91
- end
92
-
93
- test "splat" do
94
- assert_equal [@asset], @asset.to_a
95
- end
96
-
97
- test "dependencies" do
98
- assert_equal [], @asset.dependencies
99
- end
100
-
101
- test "to path" do
102
- assert_equal fixture_path('asset/POW.png'), @asset.to_path
103
- end
104
-
105
- test "body is entire contents" do
106
- assert_equal @asset.to_s, @asset.body
107
- end
108
-
109
- test "asset is fresh if its mtime and contents are the same" do
110
- assert @asset.fresh?
111
- end
112
-
113
- test "asset is fresh if its mtime is changed but its contents is the same" do
114
- filename = fixture_path('asset/test-POW.png')
115
-
116
- sandbox filename do
117
- File.open(filename, 'w') { |f| f.write "a" }
118
- asset = @env['test-POW.png']
119
-
120
- assert asset.fresh?
121
-
122
- File.open(filename, 'w') { |f| f.write "a" }
123
- mtime = Time.now + 1
124
- File.utime(mtime, mtime, filename)
125
-
126
- assert asset.fresh?
127
- end
128
- end
129
-
130
- test "asset is stale when its contents has changed" do
131
- filename = fixture_path('asset/POW.png')
132
-
133
- sandbox filename do
134
- File.open(filename, 'w') { |f| f.write "a" }
135
- asset = @env['POW.png']
136
-
137
- assert asset.fresh?
138
-
139
- File.open(filename, 'w') { |f| f.write "b" }
140
- mtime = Time.now + 1
141
- File.utime(mtime, mtime, filename)
142
-
143
- assert asset.stale?
144
- end
145
- end
146
-
147
- test "asset is stale if the file is removed" do
148
- filename = fixture_path('asset/POW.png')
149
-
150
- sandbox filename do
151
- File.open(filename, 'w') { |f| f.write "a" }
152
- asset = @env['POW.png']
153
-
154
- assert asset.fresh?
155
-
156
- File.unlink(filename)
157
-
158
- assert asset.stale?
159
- end
160
- end
161
-
162
- test "serializing asset to and from hash" do
163
- expected = @asset
164
- hash = {}
165
- @asset.encode_with(hash)
166
- actual = @env.asset_from_hash(hash)
167
-
168
- assert_kind_of Sprockets::StaticAsset, actual
169
- assert_equal expected.logical_path, actual.logical_path
170
- assert_equal expected.pathname, actual.pathname
171
- assert_equal expected.content_type, actual.content_type
172
- assert_equal expected.length, actual.length
173
- assert_equal expected.digest, actual.digest
174
-
175
- assert_equal expected.dependencies, actual.dependencies
176
- assert_equal expected.to_a, actual.to_a
177
- assert_equal expected.body, actual.body
178
- assert_equal expected.to_s, actual.to_s
179
-
180
- assert actual.eql?(expected)
181
- assert expected.eql?(actual)
182
- end
183
- end
184
-
185
- class BundledAssetTest < Sprockets::TestCase
186
- def setup
187
- @env = Sprockets::Environment.new
188
- @env.append_path(fixture_path('asset'))
189
- @env.cache = {}
190
-
191
- @asset = @env['application.js']
192
- end
193
-
194
- include AssetTests
195
-
196
- test "class" do
197
- assert_kind_of Sprockets::BundledAsset, @asset
198
- end
199
-
200
- test "content type" do
201
- assert_equal "application/javascript", @asset.content_type
202
- end
203
-
204
- test "length" do
205
- assert_equal 157, @asset.length
206
- end
207
-
208
- test "to_s" do
209
- assert_equal "var Project = {\n find: function(id) {\n }\n};\nvar Users = {\n find: function(id) {\n }\n};\n\ndocument.on('dom:loaded', function() {\n $('search').focus();\n});\n", @asset.to_s
210
- end
211
-
212
- test "each" do
213
- body = ""
214
- @asset.each { |part| body << part }
215
- assert_equal "var Project = {\n find: function(id) {\n }\n};\nvar Users = {\n find: function(id) {\n }\n};\n\ndocument.on('dom:loaded', function() {\n $('search').focus();\n});\n", body
216
- end
217
-
218
- test "requiring the same file multiple times has no effect" do
219
- assert_equal read("project.js")+"\n", asset("multiple.js").to_s
220
- end
221
-
222
- test "requiring a file of a different format raises an exception" do
223
- assert_raise Sprockets::ContentTypeMismatch do
224
- asset("mismatch.js")
225
- end
226
- end
227
-
228
- test "splatted asset includes itself" do
229
- assert_equal [resolve("project.js")], asset("project.js").to_a.map(&:pathname)
230
- end
231
-
232
- test "asset includes self as dependency" do
233
- assert_equal [], asset("project.js").dependencies.map(&:pathname)
234
- end
235
-
236
- test "asset with child dependencies" do
237
- assert_equal [resolve("project.js"), resolve("users.js")],
238
- asset("application.js").dependencies.map(&:pathname)
239
- end
240
-
241
- test "splatted asset with child dependencies" do
242
- assert_equal [resolve("project.js"), resolve("users.js"), resolve("application.js")],
243
- asset("application.js").to_a.map(&:pathname)
244
- end
245
-
246
- test "bundled asset body is just its own contents" do
247
- assert_equal "\ndocument.on('dom:loaded', function() {\n $('search').focus();\n});\n",
248
- asset("application.js").body
249
- end
250
-
251
- test "bundling joins files with blank line" do
252
- assert_equal "var Project = {\n find: function(id) {\n }\n};\nvar Users = {\n find: function(id) {\n }\n};\n\ndocument.on('dom:loaded', function() {\n $('search').focus();\n});\n",
253
- asset("application.js").to_s
254
- end
255
-
256
- test "dependencies appear in the source before files that required them" do
257
- assert_match(/Project.+Users.+focus/m, asset("application.js").to_s)
258
- end
259
-
260
- test "processing a source file with no engine extensions" do
261
- assert_equal read("users.js"), asset("noengine.js").to_s
262
- end
263
-
264
- test "processing a source file with one engine extension" do
265
- assert_equal read("users.js"), asset("oneengine.js").to_s
266
- end
267
-
268
- test "processing a source file with multiple engine extensions" do
269
- assert_equal read("users.js"), asset("multipleengine.js").to_s
270
- end
271
-
272
- test "processing a source file with unknown extensions" do
273
- assert_equal read("users.js") + "var jQuery;\n", asset("unknownexts.min.js").to_s
274
- end
275
-
276
- test "processing a source file in compat mode" do
277
- assert_equal read("project.js") + "\n" + read("users.js"),
278
- asset("compat.js").to_s
279
- end
280
-
281
- test "included dependencies are inserted after the header of the dependent file" do
282
- assert_equal "# My Application\n" + read("project.js") + "\n\nhello();\n",
283
- asset("included_header.js").to_s
284
- end
285
-
286
- test "requiring a file with a relative path" do
287
- assert_equal read("project.js") + "\n",
288
- asset("relative/require.js").to_s
289
- end
290
-
291
- test "including a file with a relative path" do
292
- assert_equal "// Included relatively\n" + read("project.js") + "\n\nhello();\n", asset("relative/include.js").to_s
293
- end
294
-
295
- test "can't require files outside the load path" do
296
- assert_raise Sprockets::FileNotFound do
297
- asset("relative/require_outside_path.js")
298
- end
299
- end
300
-
301
- test "require_directory requires all child files in alphabetical order" do
302
- assert_equal(
303
- "ok(\"b.js.erb\");\n",
304
- asset("tree/all_with_require_directory.js").to_s
305
- )
306
- end
307
-
308
- test "require_directory current directory includes self last" do
309
- assert_equal(
310
- "var Bar;\nvar Foo;\nvar App;\n",
311
- asset("tree/directory/application.js").to_s
312
- )
313
- end
314
-
315
- test "require_tree requires all descendant files in alphabetical order" do
316
- assert_equal(
317
- asset("tree/all_with_require.js").to_s,
318
- asset("tree/all_with_require_tree.js").to_s
319
- )
320
- end
321
-
322
- test "require_tree without an argument defaults to the current directory" do
323
- assert_equal(
324
- "a();\nb();\n",
325
- asset("tree/without_argument/require_tree_without_argument.js").to_s
326
- )
327
- end
328
-
329
- test "require_tree with current directory includes self last" do
330
- assert_equal(
331
- "var Bar;\nvar Foo;\nvar App;\n",
332
- asset("tree/tree/application.js").to_s
333
- )
334
- end
335
-
336
- test "require_tree with a logical path argument raises an exception" do
337
- assert_raise(Sprockets::ArgumentError) do
338
- asset("tree/with_logical_path/require_tree_with_logical_path.js").to_s
339
- end
340
- end
341
-
342
- test "require_self inserts the current file's body at the specified point" do
343
- assert_equal "/* b.css */\n\nb { display: none }\n/*\n */\n.one {}\n\n\nbody {}\n.two {}\n.project {}\n", asset("require_self.css").to_s
344
- end
345
-
346
- test "multiple require_self directives raises and error" do
347
- assert_raise(Sprockets::ArgumentError) do
348
- asset("require_self_twice.css")
349
- end
350
- end
351
-
352
- test "circular require raises an error" do
353
- assert_raise(Sprockets::CircularDependencyError) do
354
- asset("circle/a.js")
355
- end
356
- assert_raise(Sprockets::CircularDependencyError) do
357
- asset("circle/b.js")
358
- end
359
- assert_raise(Sprockets::CircularDependencyError) do
360
- asset("circle/c.js")
361
- end
362
- end
363
-
364
- test "__FILE__ is properly set in templates" do
365
- assert_equal %(var filename = "#{resolve("filename.js")}";\n),
366
- asset("filename.js").to_s
367
- end
368
-
369
- test "asset inherits the format extension and content type of the original file" do
370
- asset = asset("project.js")
371
- assert_equal "application/javascript", asset.content_type
372
- end
373
-
374
- if Tilt::CoffeeScriptTemplate.respond_to?(:default_mime_type)
375
- test "asset falls back to engines default mime type" do
376
- asset = asset("default_mime_type.js")
377
- assert_equal "application/javascript", asset.content_type
378
- end
379
- end
380
-
381
- test "asset is a rack response body" do
382
- body = ""
383
- asset("project.js").each { |part| body += part }
384
- assert_equal asset("project.js").to_s, body
385
- end
386
-
387
- test "asset length is source length" do
388
- assert_equal 46, asset("project.js").length
389
- end
390
-
391
- test "asset length is source length with unicode characters" do
392
- assert_equal 8, asset("unicode.js").length
393
- end
394
-
395
- test "asset digest" do
396
- assert asset("project.js").digest
397
- end
398
-
399
- test "asset is fresh if its mtime and contents are the same" do
400
- assert asset("application.js").fresh?
401
- end
402
-
403
- test "asset is stale when its contents has changed" do
404
- filename = fixture_path('asset/test.js')
405
-
406
- sandbox filename do
407
- File.open(filename, 'w') { |f| f.write "a;" }
408
- asset = @env['test.js']
409
-
410
- assert asset.fresh?
411
-
412
- File.open(filename, 'w') { |f| f.write "b;" }
413
- mtime = Time.now + 1
414
- File.utime(mtime, mtime, filename)
415
-
416
- assert asset.stale?
417
- end
418
- end
419
-
420
- test "asset is stale if the file is removed" do
421
- filename = fixture_path('asset/test.js')
422
-
423
- sandbox filename do
424
- File.open(filename, 'w') { |f| f.write "a;" }
425
- asset = @env['test.js']
426
-
427
- assert asset.fresh?
428
-
429
- File.unlink(filename)
430
-
431
- assert asset.stale?
432
- end
433
- end
434
-
435
- test "asset is stale when one of its source files is modified" do
436
- main = fixture_path('asset/test-main.js')
437
- dep = fixture_path('asset/test-dep.js')
438
-
439
- sandbox main, dep do
440
- File.open(main, 'w') { |f| f.write "//= require test-dep\n" }
441
- File.open(dep, 'w') { |f| f.write "a;" }
442
- asset = @env['test-main.js']
443
-
444
- assert asset.fresh?
445
-
446
- File.open(dep, 'w') { |f| f.write "b;" }
447
- mtime = Time.now + 1
448
- File.utime(mtime, mtime, dep)
449
-
450
- assert asset.stale?
451
- end
452
- end
453
-
454
- test "asset is stale when one of its dependencies is modified" do
455
- main = fixture_path('asset/test-main.js')
456
- dep = fixture_path('asset/test-dep.js')
457
-
458
- sandbox main, dep do
459
- File.open(main, 'w') { |f| f.write "//= depend_on test-dep\n" }
460
- File.open(dep, 'w') { |f| f.write "a;" }
461
- asset = @env['test-main.js']
462
-
463
- assert asset.fresh?
464
-
465
- File.open(dep, 'w') { |f| f.write "b;" }
466
- mtime = Time.now + 1
467
- File.utime(mtime, mtime, dep)
468
-
469
- assert asset.stale?
470
- end
471
- end
472
-
473
- test "asset is stale when one of its asset dependencies is modified" do
474
- main = fixture_path('asset/test-main.js')
475
- dep = fixture_path('asset/test-dep.js')
476
-
477
- sandbox main, dep do
478
- File.open(main, 'w') { |f| f.write "//= depend_on_asset test-dep\n" }
479
- File.open(dep, 'w') { |f| f.write "a;" }
480
- asset = @env['test-main.js']
481
-
482
- assert asset.fresh?
483
-
484
- File.open(dep, 'w') { |f| f.write "b;" }
485
- mtime = Time.now + 1
486
- File.utime(mtime, mtime, dep)
487
-
488
- assert asset.stale?
489
- end
490
- end
491
-
492
- test "asset is stale when one of its source files dependencies is modified" do
493
- a = fixture_path('asset/test-a.js')
494
- b = fixture_path('asset/test-b.js')
495
- c = fixture_path('asset/test-c.js')
496
-
497
- sandbox a, b, c do
498
- File.open(a, 'w') { |f| f.write "//= require test-b\n" }
499
- File.open(b, 'w') { |f| f.write "//= require test-c\n" }
500
- File.open(c, 'w') { |f| f.write "c;" }
501
- asset_a = @env['test-a.js']
502
- asset_b = @env['test-b.js']
503
- asset_c = @env['test-c.js']
504
-
505
- assert asset_a.fresh?
506
- assert asset_b.fresh?
507
- assert asset_c.fresh?
508
-
509
- File.open(c, 'w') { |f| f.write "x;" }
510
- mtime = Time.now + 1
511
- File.utime(mtime, mtime, c)
512
-
513
- assert asset_a.stale?
514
- assert asset_b.stale?
515
- assert asset_c.stale?
516
- end
517
- end
518
-
519
- test "asset is stale when one of its dependency dependencies is modified" do
520
- a = fixture_path('asset/test-a.js')
521
- b = fixture_path('asset/test-b.js')
522
- c = fixture_path('asset/test-c.js')
523
-
524
- sandbox a, b, c do
525
- File.open(a, 'w') { |f| f.write "//= require test-b\n" }
526
- File.open(b, 'w') { |f| f.write "//= depend_on test-c\n" }
527
- File.open(c, 'w') { |f| f.write "c;" }
528
- asset_a = @env['test-a.js']
529
- asset_b = @env['test-b.js']
530
- asset_c = @env['test-c.js']
531
-
532
- assert asset_a.fresh?
533
- assert asset_b.fresh?
534
- assert asset_c.fresh?
535
-
536
- File.open(c, 'w') { |f| f.write "x;" }
537
- mtime = Time.now + 1
538
- File.utime(mtime, mtime, c)
539
-
540
- assert asset_a.stale?
541
- assert asset_b.stale?
542
- assert asset_c.stale?
543
- end
544
- end
545
-
546
- test "asset is stale when one of its asset dependency dependencies is modified" do
547
- a = fixture_path('asset/test-a.js')
548
- b = fixture_path('asset/test-b.js')
549
- c = fixture_path('asset/test-c.js')
550
-
551
- sandbox a, b, c do
552
- File.open(a, 'w') { |f| f.write "//= depend_on_asset test-b\n" }
553
- File.open(b, 'w') { |f| f.write "//= depend_on_asset test-c\n" }
554
- File.open(c, 'w') { |f| f.write "c;" }
555
- asset_a = @env['test-a.js']
556
- asset_b = @env['test-b.js']
557
- asset_c = @env['test-c.js']
558
-
559
- assert asset_a.fresh?
560
- assert asset_b.fresh?
561
- assert asset_c.fresh?
562
-
563
- File.open(c, 'w') { |f| f.write "x;" }
564
- mtime = Time.now + 1
565
- File.utime(mtime, mtime, c)
566
-
567
- assert asset_a.stale?
568
- assert asset_b.stale?
569
- assert asset_c.stale?
570
- end
571
- end
572
-
573
- test "asset if stale if once of its source files is removed" do
574
- main = fixture_path('asset/test-main.js')
575
- dep = fixture_path('asset/test-dep.js')
576
-
577
- sandbox main, dep do
578
- File.open(main, 'w') { |f| f.write "//= require test-dep\n" }
579
- File.open(dep, 'w') { |f| f.write "a;" }
580
- asset = @env['test-main.js']
581
-
582
- assert asset.fresh?
583
-
584
- File.unlink(dep)
585
-
586
- assert asset.stale?
587
- end
588
- end
589
-
590
- test "asset is stale if a file is added to its require directory" do
591
- asset = asset("tree/all_with_require_directory.js")
592
- assert asset.fresh?
593
-
594
- dirname = File.join(fixture_path("asset"), "tree/all")
595
- filename = File.join(dirname, "z.js")
596
-
597
- sandbox filename do
598
- File.open(filename, 'w') { |f| f.write "z" }
599
- mtime = Time.now + 1
600
- File.utime(mtime, mtime, dirname)
601
-
602
- assert asset.stale?
603
- end
604
- end
605
-
606
- test "asset is stale if a file is added to its require tree" do
607
- asset = asset("tree/all_with_require_tree.js")
608
- assert asset.fresh?
609
-
610
- dirname = File.join(fixture_path("asset"), "tree/all/b/c")
611
- filename = File.join(dirname, "z.js")
612
-
613
- sandbox filename do
614
- File.open(filename, 'w') { |f| f.write "z" }
615
- mtime = Time.now + 1
616
- File.utime(mtime, mtime, dirname)
617
-
618
- assert asset.stale?
619
- end
620
- end
621
-
622
- test "asset is stale if its declared dependency changes" do
623
- sprite = fixture_path('asset/sprite.css.erb')
624
- image = fixture_path('asset/POW.png')
625
-
626
- sandbox sprite, image do
627
- asset = @env['sprite.css']
628
-
629
- assert asset.fresh?
630
-
631
- File.open(image, 'w') { |f| f.write "(change)" }
632
- mtime = Time.now + 1
633
- File.utime(mtime, mtime, image)
634
-
635
- assert asset.stale?
636
- end
637
- end
638
-
639
- test "legacy constants.yml" do
640
- assert_equal "var Prototype = { version: '2.0' };\n",
641
- asset("constants.js").to_s
642
- end
643
-
644
- test "multiple charset defintions are stripped from css bundle" do
645
- assert_equal "@charset \"UTF-8\";\n.foo {}\n\n.bar {}\n", asset("charset.css").to_s
646
- end
647
-
648
- test "appends missing semicolons" do
649
- assert_equal "var Bar\n;\n\n(function() {\n var Foo\n})\n;\n",
650
- asset("semicolons.js").to_s
651
- end
652
-
653
- test "serializing asset to and from hash" do
654
- expected = @asset
655
- hash = {}
656
- @asset.encode_with(hash)
657
- actual = @env.asset_from_hash(hash)
658
-
659
- assert_kind_of Sprockets::BundledAsset, actual
660
- assert_equal expected.logical_path, actual.logical_path
661
- assert_equal expected.pathname, actual.pathname
662
- assert_equal expected.body, actual.body
663
- assert_equal expected.to_s, actual.to_s
664
- assert_equal expected.content_type, actual.content_type
665
- assert_equal expected.length, actual.length
666
- assert_equal expected.digest, actual.digest
667
- assert_equal expected.dependencies, actual.dependencies
668
- assert_equal expected.to_a, actual.to_a
669
- assert_equal expected.to_s, actual.to_s
670
-
671
- assert actual.eql?(expected)
672
- assert expected.eql?(actual)
673
- end
674
-
675
- test "should not fail if home is not set in environment" do
676
- begin
677
- home, ENV["HOME"] = ENV["HOME"], nil
678
- assert_nothing_raised do
679
- env = Sprockets::Environment.new
680
- env.append_path(fixture_path('asset'))
681
- env['application.js']
682
- end
683
- ensure
684
- ENV["HOME"] = home
685
- end
686
- end
687
-
688
- def asset(logical_path)
689
- @env[logical_path]
690
- end
691
-
692
- def resolve(logical_path)
693
- @env.resolve(logical_path)
694
- end
695
-
696
- def read(logical_path)
697
- File.read(resolve(logical_path))
698
- end
699
- end