rake-pipeline 0.5.0 → 0.7.0

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 (55) hide show
  1. data/.travis.yml +12 -0
  2. data/Gemfile +1 -0
  3. data/README.markdown +1 -1
  4. data/README.yard +61 -32
  5. data/Rakefile +9 -0
  6. data/bin/rakep +1 -24
  7. data/lib/generators/rake/pipeline/install/install_generator.rb +70 -0
  8. data/lib/rake-pipeline.rb +117 -53
  9. data/lib/rake-pipeline/cli.rb +56 -0
  10. data/lib/rake-pipeline/dsl.rb +3 -140
  11. data/lib/rake-pipeline/dsl/pipeline_dsl.rb +168 -0
  12. data/lib/rake-pipeline/dsl/project_dsl.rb +108 -0
  13. data/lib/rake-pipeline/dynamic_file_task.rb +188 -0
  14. data/lib/rake-pipeline/file_wrapper.rb +1 -1
  15. data/lib/rake-pipeline/filter.rb +45 -15
  16. data/lib/rake-pipeline/filters.rb +3 -1
  17. data/lib/rake-pipeline/filters/{concat.rb → concat_filter.rb} +0 -0
  18. data/lib/rake-pipeline/filters/ordering_concat_filter.rb +38 -0
  19. data/lib/rake-pipeline/filters/pipeline_finalizing_filter.rb +19 -0
  20. data/lib/rake-pipeline/graph.rb +178 -0
  21. data/lib/rake-pipeline/manifest.rb +63 -0
  22. data/lib/rake-pipeline/manifest_entry.rb +34 -0
  23. data/lib/rake-pipeline/matcher.rb +65 -30
  24. data/lib/rake-pipeline/middleware.rb +15 -12
  25. data/lib/rake-pipeline/precompile.rake +8 -0
  26. data/lib/rake-pipeline/project.rb +280 -0
  27. data/lib/rake-pipeline/railtie.rb +16 -1
  28. data/lib/rake-pipeline/server.rb +15 -0
  29. data/lib/rake-pipeline/version.rb +2 -2
  30. data/rake-pipeline.gemspec +2 -0
  31. data/spec/cli_spec.rb +71 -0
  32. data/spec/concat_filter_spec.rb +1 -27
  33. data/spec/{dsl_spec.rb → dsl/pipeline_dsl_spec.rb} +32 -18
  34. data/spec/dsl/project_dsl_spec.rb +41 -0
  35. data/spec/dynamic_file_task_spec.rb +111 -0
  36. data/spec/encoding_spec.rb +6 -8
  37. data/spec/file_wrapper_spec.rb +19 -2
  38. data/spec/filter_spec.rb +120 -22
  39. data/spec/graph_spec.rb +56 -0
  40. data/spec/manifest_entry_spec.rb +51 -0
  41. data/spec/manifest_spec.rb +67 -0
  42. data/spec/matcher_spec.rb +35 -2
  43. data/spec/middleware_spec.rb +123 -75
  44. data/spec/ordering_concat_filter_spec.rb +39 -0
  45. data/spec/pipeline_spec.rb +95 -34
  46. data/spec/project_spec.rb +293 -0
  47. data/spec/rake_acceptance_spec.rb +307 -67
  48. data/spec/rake_tasks_spec.rb +21 -0
  49. data/spec/spec_helper.rb +11 -48
  50. data/spec/support/spec_helpers/file_utils.rb +35 -0
  51. data/spec/support/spec_helpers/filters.rb +16 -0
  52. data/spec/support/spec_helpers/input_helpers.rb +23 -0
  53. data/spec/support/spec_helpers/memory_file_wrapper.rb +31 -0
  54. data/tools/perfs +107 -0
  55. metadata +100 -12
@@ -0,0 +1,293 @@
1
+ describe "Rake::Pipeline::Project" do
2
+ include Rake::Pipeline::SpecHelpers::InputHelpers
3
+
4
+ ASSETFILE_SOURCE = <<-HERE.gsub(/^ {4}/, '')
5
+ require "#{tmp}/../support/spec_helpers/filters"
6
+ tmpdir "tmp"
7
+ output "public"
8
+
9
+ input "app/assets" do
10
+ match "*.js" do
11
+ concat "javascripts/application.js"
12
+ filter Rake::Pipeline::SpecHelpers::Filters::StripAssertsFilter
13
+ end
14
+ end
15
+ HERE
16
+
17
+ MODIFIED_ASSETFILE_SOURCE = <<-HERE.gsub(/^ {4}/, '')
18
+ require "#{tmp}/../support/spec_helpers/filters"
19
+ tmpdir "tmp"
20
+ output "public"
21
+
22
+ input "app/assets" do
23
+ match "*.js" do
24
+ concat "javascripts/app.js"
25
+ filter Rake::Pipeline::SpecHelpers::Filters::StripAssertsFilter
26
+ end
27
+ end
28
+ HERE
29
+
30
+ BAD_ASSETFILE_SOURCE = <<-HERE.gsub(/^ {4}/, '')
31
+ require "#{tmp}/../support/spec_helpers/filters"
32
+ tmpdir "tmp"
33
+ output "public"
34
+
35
+ input "app/assets" do
36
+ method_not_in_dsl_on_line_6
37
+ end
38
+ HERE
39
+
40
+ let(:assetfile_path) { File.join(tmp, "Assetfile") }
41
+
42
+ def assetfile_digest
43
+ (Digest::SHA1.new << File.read(assetfile_path)).to_s
44
+ end
45
+
46
+ let(:unmatched_file) { input_file("junk.txt") }
47
+
48
+ let(:input_files) do
49
+ [input_file("jquery.js"), input_file("ember.js"), unmatched_file]
50
+ end
51
+
52
+ let(:output_files) do
53
+ [output_file("javascripts/application.js")]
54
+ end
55
+
56
+ let(:old_tmpdir) do
57
+ File.join(tmp, "tmp", "rake-pipeline-ad7a83894789")
58
+ end
59
+
60
+ let(:digested_tmpdir) do
61
+ File.join(tmp, "tmp", "rake-pipeline-#{assetfile_digest}")
62
+ end
63
+
64
+ attr_reader :project
65
+
66
+ before do
67
+ File.open(assetfile_path, 'w') { |file| file.write(ASSETFILE_SOURCE) }
68
+ create_files(input_files)
69
+ @project = Rake::Pipeline::Project.new(assetfile_path)
70
+ mkdir_p(old_tmpdir)
71
+ end
72
+
73
+ it "has an assetfile_path" do
74
+ project.assetfile_path.should == assetfile_path
75
+ end
76
+
77
+ it "has an assetfile_digest" do
78
+ project.assetfile_digest.should == assetfile_digest
79
+ end
80
+
81
+ it "has a pipeline" do
82
+ project.should have(1).pipelines
83
+ end
84
+
85
+ describe "constructor" do
86
+ it "creates pipelines from an Assetfile given an Assetfile path" do
87
+ project = Rake::Pipeline::Project.new(assetfile_path)
88
+ project.maps.should == {}
89
+ pipeline = project.pipelines.last
90
+ pipeline.inputs.should == { "app/assets" => "**/*" }
91
+ pipeline.output_root.should == File.join(tmp, "public")
92
+ end
93
+
94
+ it "wraps an existing pipeline" do
95
+ pipeline = Rake::Pipeline::Project.class_eval("build do\n#{File.read(assetfile_path)}\nend", assetfile_path, 1)
96
+ project = Rake::Pipeline::Project.new(pipeline)
97
+ project.pipelines.last.should == pipeline
98
+ end
99
+ end
100
+
101
+ describe "#invoke" do
102
+ it "creates output files" do
103
+ output_files.each { |file| file.should_not exist }
104
+ project.invoke
105
+ output_files.each { |file| file.should exist }
106
+ end
107
+
108
+ it "writes temp files to a subdirectory of the tmp dir named after the assetfile digest" do
109
+ project.invoke
110
+ File.exist?(digested_tmpdir).should be_true
111
+ end
112
+ end
113
+
114
+ describe "invalid Assetfile" do
115
+ before do
116
+ File.open(assetfile_path, 'w') { |file| file.write(BAD_ASSETFILE_SOURCE) }
117
+ end
118
+
119
+ it "should raise error with assetfile path on correct line number" do
120
+ lambda {
121
+ Rake::Pipeline::Project.new(assetfile_path)
122
+ }.should raise_error {|error| error.backtrace[0].should match(/Assetfile:6/) }
123
+ end
124
+ end
125
+
126
+ describe "#invoke_clean" do
127
+ context "if the Assetfile contents have changed" do
128
+ def modify_assetfile
129
+ File.open(assetfile_path, 'w') do |file|
130
+ file.write(MODIFIED_ASSETFILE_SOURCE)
131
+ end
132
+ end
133
+
134
+ it "rebuilds its pipeline" do
135
+ project.invoke_clean
136
+ original_pipeline = project.pipelines.last
137
+ original_assetfile_digest = assetfile_digest
138
+
139
+ modify_assetfile
140
+ project.invoke_clean
141
+ assetfile_digest.should_not == original_assetfile_digest
142
+ project.pipelines.last.should_not == original_pipeline
143
+ end
144
+ end
145
+ end
146
+
147
+ describe "#cleanup_tmpdir" do
148
+ it "cleans old rake-pipeline-* dirs out of the pipeline's tmp dir" do
149
+ File.exist?(old_tmpdir).should be_true
150
+ project.cleanup_tmpdir
151
+ File.exist?(old_tmpdir).should be_false
152
+ end
153
+
154
+ it "leaves the current assetfile-digest tmp dir alone" do
155
+ project.invoke
156
+ File.exist?(digested_tmpdir).should be_true
157
+ project.cleanup_tmpdir
158
+ File.exist?(digested_tmpdir).should be_true
159
+ end
160
+ end
161
+
162
+ describe "#clean" do
163
+ def rakep_tmpdirs
164
+ Dir["#{tmp}/tmp/rake-pipeline-*"]
165
+ end
166
+
167
+ it "cleans all rake-pipeline-* dirs out of the pipeline's tmp dir" do
168
+ project.invoke
169
+ rakep_tmpdirs.should_not be_empty
170
+ project.clean
171
+ rakep_tmpdirs.should be_empty
172
+ end
173
+
174
+ it "removes the pipeline's output files" do
175
+ project.invoke
176
+ output_files.each { |f| f.should exist }
177
+ project.clean
178
+ output_files.each { |f| f.should_not exist }
179
+ end
180
+
181
+ it "leaves the pipeline's unmatched input files alone" do
182
+ project.invoke
183
+ project.clean
184
+ unmatched_file.should exist
185
+ end
186
+ end
187
+
188
+ describe ".add_to_digest" do
189
+ after do
190
+ Rake::Pipeline::Project.digest_additions = []
191
+ end
192
+
193
+ it "appends a string to the generated tmp dir name" do
194
+ Rake::Pipeline::Project.add_to_digest("octopus")
195
+
196
+ File.basename(project.digested_tmpdir).should ==
197
+ "rake-pipeline-#{assetfile_digest}-octopus"
198
+ end
199
+
200
+ it "can be called multiple times" do
201
+ Rake::Pipeline::Project.add_to_digest("a")
202
+ Rake::Pipeline::Project.add_to_digest("b")
203
+
204
+ File.basename(project.digested_tmpdir).should ==
205
+ "rake-pipeline-#{assetfile_digest}-a-b"
206
+ end
207
+ end
208
+
209
+ describe "#build_pipeline" do
210
+ let(:inputs) { {"foo" => "**/*"} }
211
+
212
+ it "returns a pipeline" do
213
+ pipeline = project.build_pipeline(inputs) {}
214
+ pipeline.should be_kind_of(Rake::Pipeline)
215
+ end
216
+
217
+ it "adds the pipeline to the list of pipelines" do
218
+ pipeline = project.build_pipeline(inputs) {}
219
+ project.pipelines.last.should == pipeline
220
+ end
221
+
222
+ it "configures the pipeline with the pipeline DSL" do
223
+ pipeline = project.build_pipeline(inputs) do
224
+ output "bar"
225
+ end
226
+
227
+ pipeline.output_root.should == File.expand_path("bar")
228
+ end
229
+
230
+ it "sets the pipeline's tmpdir to a digest tmpdir" do
231
+ pipeline = project.build_pipeline(inputs) {}
232
+ pipeline.tmpdir.should == project.digested_tmpdir
233
+ end
234
+
235
+ it "sets the pipeline's output_root to the default_output_root" do
236
+ pipeline = project.build_pipeline(inputs) {}
237
+ pipeline.output_root.should == project.default_output_root
238
+ end
239
+
240
+ it "sets the pipeline's project to itself" do
241
+ pipeline = project.build_pipeline(inputs) {}
242
+ pipeline.project.should == project
243
+ end
244
+
245
+ it "creates a pipeline with a given set of inputs" do
246
+ pipeline = project.build_pipeline(inputs) {}
247
+ pipeline.inputs.should == inputs
248
+ end
249
+
250
+ it "can be called with a single path input" do
251
+ pipeline = project.build_pipeline("/path") {}
252
+ pipeline.inputs.should == {"/path" => "**/*"}
253
+ end
254
+
255
+ it "can be called with a path and a glob" do
256
+ pipeline = project.build_pipeline("/path", "*.js") {}
257
+ pipeline.inputs.should == {"/path" => "*.js"}
258
+ end
259
+
260
+ it "can be called with an array of paths" do
261
+ pipeline = project.build_pipeline(["path1", "path2"]) {}
262
+ pipeline.inputs.should have_key("path1")
263
+ pipeline.inputs.should have_key("path2")
264
+ end
265
+
266
+ it "can be called with a hash of path => glob pairs" do
267
+ pipeline = project.build_pipeline({"/path" => "*.css"}) {}
268
+ pipeline.inputs.should == {"/path" => "*.css"}
269
+ end
270
+ end
271
+
272
+ describe "#obsolete_tmpdirs" do
273
+ it "includes tmp directories that don't match the current digest" do
274
+ project.obsolete_tmpdirs.should include(old_tmpdir)
275
+ end
276
+ end
277
+
278
+ describe "#files_to_clean" do
279
+ it "includes a project's output files" do
280
+ output_files.each do |file|
281
+ project.files_to_clean.should include(file.fullpath)
282
+ end
283
+ end
284
+
285
+ it "includes a project's temporary directory" do
286
+ project.files_to_clean.should include(digested_tmpdir)
287
+ end
288
+
289
+ it "includes any old digest tmp dirs" do
290
+ project.files_to_clean.should include(old_tmpdir)
291
+ end
292
+ end
293
+ end
@@ -1,6 +1,6 @@
1
1
  require "rake-pipeline/filters"
2
2
 
3
- describe "A realistic pipeline" do
3
+ describe "A realistic project" do
4
4
 
5
5
  INPUTS = {
6
6
 
@@ -26,10 +26,14 @@ HERE
26
26
  }
27
27
  HERE
28
28
 
29
- "app/index.html" => <<-HERE
29
+ "app/index.html" => <<-HERE,
30
30
  <html></html>
31
31
  HERE
32
32
 
33
+ "app/junk.txt" => <<-HERE
34
+ junk
35
+ HERE
36
+
33
37
  }
34
38
 
35
39
  EXPECTED_JS_OUTPUT = <<-HERE
@@ -52,15 +56,6 @@ EXPECTED_HTML_OUTPUT = <<-HERE
52
56
  <html></html>
53
57
  HERE
54
58
 
55
- before do
56
- Rake.application = Rake::Application.new
57
-
58
- INPUTS.each do |name, string|
59
- mkdir_p File.dirname(File.join(tmp, name))
60
- File.open(File.join(tmp, name), "w") { |file| file.write(string) }
61
- end
62
- end
63
-
64
59
  def input_wrapper(path)
65
60
  Rake::Pipeline::FileWrapper.new(tmp, path)
66
61
  end
@@ -78,65 +73,112 @@ HERE
78
73
  concat_filter = Rake::Pipeline::ConcatFilter
79
74
  strip_asserts_filter = Rake::Pipeline::SpecHelpers::Filters::StripAssertsFilter
80
75
 
81
- it "can successfully apply filters" do
82
- concat = concat_filter.new
83
- concat.input_files = INPUTS.keys.select { |key| key =~ /javascript/ }.map { |file| input_wrapper(file) }
84
- concat.output_root = File.join(tmp, "temporary", "concat_filter")
85
- concat.output_name_generator = proc { |input| "javascripts/application.js" }
76
+ def copy_files
77
+ INPUTS.each do |name, string|
78
+ mkdir_p File.dirname(File.join(tmp, name))
79
+ File.open(File.join(tmp, name), "w") { |file| file.write(string) }
80
+ end
81
+ end
86
82
 
87
- strip_asserts = strip_asserts_filter.new
88
- strip_asserts.input_files = concat.output_files
89
- strip_asserts.output_root = File.join(tmp, "public")
90
- strip_asserts.output_name_generator = proc { |input| input }
83
+ before do
84
+ Rake.application = Rake::Application.new
85
+ copy_files
86
+ end
91
87
 
92
- concat.generate_rake_tasks
93
- Rake::Task.define_task(:default => strip_asserts.generate_rake_tasks)
94
- Rake.application[:default].invoke
88
+ describe "a pipeline" do
89
+ it "can successfully apply filters" do
90
+ concat = concat_filter.new
91
+ concat.input_files = INPUTS.keys.select { |key| key =~ /javascript/ }.map { |file| input_wrapper(file) }
92
+ concat.output_root = File.join(tmp, "temporary", "concat_filter")
93
+ concat.output_name_generator = proc { |input| "javascripts/application.js" }
95
94
 
96
- output_should_exist
97
- end
95
+ strip_asserts = strip_asserts_filter.new
96
+ strip_asserts.input_files = concat.output_files
97
+ strip_asserts.output_root = File.join(tmp, "public")
98
+ strip_asserts.output_name_generator = proc { |input| input }
98
99
 
99
- it "can be configured using the pipeline" do
100
- pipeline = Rake::Pipeline.new
101
- pipeline.input_root = File.expand_path(tmp)
102
- pipeline.output_root = File.expand_path("public")
103
- pipeline.input_glob = "app/javascripts/*.js"
104
- pipeline.tmpdir = "temporary"
100
+ concat.generate_rake_tasks
101
+ Rake::Task.define_task(:default => strip_asserts.generate_rake_tasks)
102
+ Rake.application[:default].invoke
105
103
 
106
- concat = concat_filter.new
107
- concat.output_name_generator = proc { |input| "javascripts/application.js" }
104
+ output_should_exist
105
+ end
108
106
 
109
- strip_asserts = strip_asserts_filter.new
110
- strip_asserts.output_name_generator = proc { |input| input }
107
+ it "supports filters with multiple outputs per input" do
108
+ concat = concat_filter.new
109
+ concat.input_files = INPUTS.keys.select { |key| key =~ /javascript/ }.map { |file| input_wrapper(file) }
110
+ concat.output_root = File.join(tmp, "temporary", "concat_filter")
111
+ concat.output_name_generator = proc { |input| [ "javascripts/application.js", input.sub(/^app\//, '') ] }
111
112
 
112
- pipeline.add_filters(concat, strip_asserts)
113
- pipeline.invoke
113
+ strip_asserts = strip_asserts_filter.new
114
+ strip_asserts.input_files = concat.output_files
115
+ strip_asserts.output_root = File.join(tmp, "public")
116
+ strip_asserts.output_name_generator = proc { |input| input }
114
117
 
115
- output_should_exist
118
+ concat.generate_rake_tasks
119
+ Rake::Task.define_task(:default => strip_asserts.generate_rake_tasks)
120
+ Rake.application[:default].invoke
121
+
122
+ output_should_exist
123
+
124
+ expected_files = {
125
+ "javascripts/jquery.js" => "var jQuery = {};\n",
126
+ "javascripts/sproutcore.js" => "var SC = {};\n\nSC.hi = function() { console.log(\"hi\"); };\n"
127
+ }
128
+
129
+ expected_files.each do |file, expected|
130
+ output_file = File.join(tmp, "public", file)
131
+ output = nil
132
+
133
+ lambda { output = File.read(output_file) }.should_not raise_error
134
+ output.should == expected
135
+ end
136
+ end
137
+
138
+ it "can be configured using the pipeline" do
139
+ pipeline = Rake::Pipeline.new
140
+ pipeline.add_input tmp, 'app/javascripts/*.js'
141
+ pipeline.output_root = File.expand_path("public")
142
+ pipeline.tmpdir = "temporary"
143
+
144
+ concat = concat_filter.new
145
+ concat.output_name_generator = proc { |input| "javascripts/application.js" }
146
+
147
+ strip_asserts = strip_asserts_filter.new
148
+ strip_asserts.output_name_generator = proc { |input| input }
149
+
150
+ pipeline.add_filters(concat, strip_asserts)
151
+ pipeline.invoke
152
+
153
+ output_should_exist
154
+ end
116
155
  end
117
156
 
118
157
  describe "using the pipeline DSL" do
119
-
120
- attr_reader :pipeline
158
+ attr_reader :project
121
159
 
122
160
  shared_examples_for "the pipeline DSL" do
123
161
  it "can be configured using the pipeline DSL" do
124
- pipeline.invoke
162
+ project.invoke
125
163
  output_should_exist
126
164
  end
127
165
 
128
166
  it "can be configured using the pipeline DSL with an alternate Rake application" do
129
- pipeline.rake_application = Rake::Application.new
130
- pipeline.invoke
167
+ project.pipelines.first.rake_application = Rake::Application.new
168
+ project.invoke
131
169
  output_should_exist
132
170
  end
133
171
 
134
172
  it "can be invoked repeatedly to reflected updated changes" do
135
- pipeline.invoke
173
+ project.invoke
136
174
  age_existing_files
137
175
 
138
- File.open(File.join(tmp, "app/javascripts/jquery.js"), "w") do |file|
139
- file.write "var jQuery = {};\njQuery.trim = function() {};\n"
176
+ if respond_to?(:update_jquery)
177
+ update_jquery
178
+ else
179
+ File.open(File.join(tmp, "app/javascripts/jquery.js"), "w") do |file|
180
+ file.write "var jQuery = {};\njQuery.trim = function() {};\n"
181
+ end
140
182
  end
141
183
 
142
184
  expected = <<-HERE.gsub(/^ {10}/, '')
@@ -147,20 +189,24 @@ HERE
147
189
  SC.hi = function() { console.log("hi"); };
148
190
  HERE
149
191
 
150
- pipeline.invoke
192
+ project.invoke
151
193
 
152
194
  output_should_exist(expected)
153
195
  end
154
196
 
155
197
  it "can be restarted to reflect new files" do
156
- pipeline.invoke
198
+ project.invoke
157
199
  age_existing_files
158
200
 
159
- File.open(File.join(tmp, "app/javascripts/history.js"), "w") do |file|
160
- file.write "var History = {};\n"
201
+ if respond_to?(:update_history)
202
+ update_history
203
+ else
204
+ File.open(File.join(tmp, "app/javascripts/history.js"), "w") do |file|
205
+ file.write "var History = {};\n"
206
+ end
161
207
  end
162
208
 
163
- pipeline.invoke_clean
209
+ project.invoke_clean
164
210
 
165
211
  expected = <<-HERE.gsub(/^ {10}/, '')
166
212
  var History = {};
@@ -174,36 +220,98 @@ HERE
174
220
  end
175
221
  end
176
222
 
177
- describe "the raw pipeline DSL" do
223
+ describe "the raw pipeline DSL (with block strip_asserts_filter)" do
178
224
  it_behaves_like "the pipeline DSL"
179
225
 
180
226
  before do
181
- @pipeline = Rake::Pipeline.build do
227
+ @project = Rake::Pipeline::Project.build do
182
228
  tmpdir "temporary"
183
- input tmp, "app/javascripts/*.js"
184
- filter(concat_filter) { "javascripts/application.js" }
185
- filter(strip_asserts_filter) { |input| input }
186
229
  output "public"
230
+
231
+ input tmp, "app/javascripts/*.js" do
232
+ concat "javascripts/application.js"
233
+ filter(strip_asserts_filter) { |input| input }
234
+ end
187
235
  end
188
236
  end
189
237
  end
190
238
 
191
- describe "the raw pipeline DSL" do
239
+ describe "the raw pipeline DSL (with before_filter)" do
192
240
  it_behaves_like "the pipeline DSL"
193
241
 
194
242
  before do
195
- @pipeline = Rake::Pipeline.build do
243
+ @project = Rake::Pipeline::Project.build do
196
244
  tmpdir "temporary"
197
- input tmp, "app/javascripts/*.js"
198
- filter concat_filter, "javascripts/application.js"
199
- filter strip_asserts_filter
200
245
  output "public"
246
+
247
+ before_filter Rake::Pipeline::ConcatFilter, "javascripts/application.js"
248
+
249
+ input tmp, "app/javascripts/*.js" do
250
+ filter strip_asserts_filter
251
+ end
252
+ end
253
+ end
254
+ end
255
+
256
+ describe "the raw pipeline DSL (with simple strip_asserts_filter)" do
257
+ it_behaves_like "the pipeline DSL"
258
+
259
+ before do
260
+ @project = Rake::Pipeline::Project.build do
261
+ tmpdir "temporary"
262
+ output "public"
263
+
264
+ input tmp, "app/javascripts/*.js" do
265
+ concat "javascripts/application.js"
266
+ filter strip_asserts_filter
267
+ end
201
268
  end
202
269
  end
203
270
  end
204
271
 
205
272
  describe "using the matcher spec" do
273
+ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
274
+ super
275
+
276
+ css = File.join(tmp, "public/stylesheets/application.css")
277
+
278
+ File.exists?(css).should be_true
279
+ File.read(css).should == EXPECTED_CSS_OUTPUT
280
+
281
+ html = File.join(tmp, "public/index.html")
282
+ File.exists?(html).should be_true
283
+ File.read(html).should == EXPECTED_HTML_OUTPUT
284
+
285
+ junk = File.join(tmp, "public/junk.txt")
286
+ File.exists?(junk).should be_false
287
+ end
288
+
289
+ it_behaves_like "the pipeline DSL"
290
+
291
+ before do
292
+ @project = Rake::Pipeline::Project.build do
293
+ tmpdir "temporary"
294
+ output "public"
295
+
296
+ input File.join(tmp, "app") do
297
+ match "**/*.js" do
298
+ filter strip_asserts_filter
299
+ concat "javascripts/application.js"
300
+ end
301
+
302
+ match "**/*.css" do
303
+ concat "stylesheets/application.css"
304
+ end
305
+
306
+ match "**/*.html" do
307
+ concat
308
+ end
309
+ end
310
+ end
311
+ end
312
+ end
206
313
 
314
+ describe "using multiple pipelines (with after_filters)" do
207
315
  def output_should_exist(expected=EXPECTED_JS_OUTPUT)
208
316
  super
209
317
 
@@ -215,23 +323,155 @@ HERE
215
323
  html = File.join(tmp, "public/index.html")
216
324
  File.exists?(html).should be_true
217
325
  File.read(html).should == EXPECTED_HTML_OUTPUT
326
+
327
+ junk = File.join(tmp, "public/junk.txt")
328
+ File.exists?(junk).should be_false
218
329
  end
219
330
 
220
331
  it_behaves_like "the pipeline DSL"
221
332
 
222
333
  before do
223
- @pipeline = Rake::Pipeline.build do
334
+ @project = Rake::Pipeline::Project.build do
224
335
  tmpdir "temporary"
225
- input File.join(tmp, "app"), "**/*.{js,css,html}"
226
336
  output "public"
227
337
 
228
- match "**/*.js" do
338
+ app_dir = File.join(tmp, "app")
339
+
340
+ after_filter Rake::Pipeline::ConcatFilter do |input|
341
+ ext = File.extname(input)
342
+
343
+ case ext
344
+ when ".js"
345
+ "javascripts/application.js"
346
+ when ".css"
347
+ "stylesheets/application.css"
348
+ when ".html"
349
+ input
350
+ end
351
+ end
352
+
353
+ input app_dir, "**/*.js" do
229
354
  filter strip_asserts_filter
230
- filter concat_filter, "javascripts/application.js"
231
355
  end
232
356
 
233
- match "**/*.css" do
234
- filter concat_filter, "stylesheets/application.css"
357
+ input app_dir, "**/*.css"
358
+
359
+ input app_dir, "**/*.html"
360
+ end
361
+ end
362
+ end
363
+
364
+ describe "using multiple pipelines" do
365
+ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
366
+ super
367
+
368
+ css = File.join(tmp, "public/stylesheets/application.css")
369
+
370
+ File.exists?(css).should be_true
371
+ File.read(css).should == EXPECTED_CSS_OUTPUT
372
+
373
+ html = File.join(tmp, "public/index.html")
374
+ File.exists?(html).should be_true
375
+ File.read(html).should == EXPECTED_HTML_OUTPUT
376
+
377
+ junk = File.join(tmp, "public/junk.txt")
378
+ File.exists?(junk).should be_false
379
+ end
380
+
381
+ it_behaves_like "the pipeline DSL"
382
+
383
+ before do
384
+ @project = Rake::Pipeline::Project.build do
385
+ tmpdir "temporary"
386
+ output "public"
387
+
388
+ app_dir = File.join(tmp, "app")
389
+
390
+ input app_dir, "**/*.js" do
391
+ filter strip_asserts_filter
392
+ concat "javascripts/application.js"
393
+ end
394
+
395
+ input app_dir, "**/*.css" do
396
+ concat "stylesheets/application.css"
397
+ end
398
+
399
+ input app_dir, "**/*.html" do
400
+ concat
401
+ end
402
+ end
403
+ end
404
+ end
405
+
406
+ describe "using the matcher spec (with multiple inputs to a single pipeline)" do
407
+ it_behaves_like "the pipeline DSL"
408
+
409
+ def tmp1
410
+ File.join(tmp, 'tmp1')
411
+ end
412
+
413
+ def tmp2
414
+ File.join(tmp, 'tmp2')
415
+ end
416
+
417
+ def update_jquery
418
+ File.open(File.join(tmp1, "app/javascripts/jquery.js"), "w") do |file|
419
+ file.write "var jQuery = {};\njQuery.trim = function() {};\n"
420
+ end
421
+ end
422
+
423
+ def update_history
424
+ File.open(File.join(tmp1, "app/javascripts/history.js"), "w") do |file|
425
+ file.write "var History = {};\n"
426
+ end
427
+ end
428
+
429
+ def copy_files
430
+ INPUTS.each do |name, string|
431
+ file = name =~ /\.js$/ ? File.join(tmp1, name) : File.join(tmp2, name)
432
+
433
+ mkdir_p File.dirname(file)
434
+ File.open(file, "w") { |f| f.write(string) }
435
+ end
436
+ end
437
+
438
+ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
439
+ super
440
+
441
+ css = File.join(tmp, "public/stylesheets/application.css")
442
+
443
+ File.exists?(css).should be_true
444
+ File.read(css).should == EXPECTED_CSS_OUTPUT
445
+
446
+ html = File.join(tmp, "public/index.html")
447
+ File.exists?(html).should be_true
448
+ File.read(html).should == EXPECTED_HTML_OUTPUT
449
+
450
+ junk = File.join(tmp, "public/junk.txt")
451
+ File.exists?(junk).should be_false
452
+ end
453
+
454
+ before do
455
+ tmp1 = self.tmp1
456
+ tmp2 = self.tmp2
457
+
458
+ @project = Rake::Pipeline::Project.build do
459
+ tmpdir "temporary"
460
+ output "public"
461
+
462
+ inputs [File.join(tmp1, "app"), File.join(tmp2, "app")] do
463
+ match "**/*.js" do
464
+ filter strip_asserts_filter
465
+ concat "javascripts/application.js"
466
+ end
467
+
468
+ match "**/*.css" do
469
+ concat "stylesheets/application.css"
470
+ end
471
+
472
+ match "**/*.html" do
473
+ concat
474
+ end
235
475
  end
236
476
  end
237
477
  end