Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add .travis.yml

organize spec_helper like rake-pipeline project
use MemoryManifest in filter specs
  • Loading branch information...
commit 7775b0b0a13267a04241db10ce0e906d49e4da11 1 parent 2cfe4e7
@krisselden krisselden authored
View
11 .travis.yml
@@ -0,0 +1,11 @@
+rvm:
+ - 1.9.2
+ - 1.9.3
+ - ruby-head
+ - jruby-head
+
+bundler_args: --without docs
+
+notifications:
+ email:
+ - wycats@gmail.com
View
9 Gemfile
@@ -1,7 +1,8 @@
-source "http://rubygems.org"
-
-# Specify your gem's dependencies in rake-pipeline-web-filters.gemspec
-gemspec
+source :rubygems
gem "rake-pipeline", :git => "git://github.com/livingsocial/rake-pipeline.git"
gem "pry"
+gem "pry-debugger"
+
+# Specify your gem's dependencies in rake-pipeline-web-filters.gemspec
+gemspec
View
3  spec/cache_buster_filter_spec.rb
@@ -1,5 +1,6 @@
describe "CacheBusterFilter" do
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
CacheBusterFilter ||= Rake::Pipeline::Web::Filters::CacheBusterFilter
let(:content) { "it doesn't matter" }
@@ -14,6 +15,8 @@
def setup_filter(filter)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [ input_file ]
filter.output_root = output_root
filter.rake_application = Rake::Application.new
View
3  spec/chained_filter_spec.rb
@@ -1,5 +1,6 @@
describe "ChainedFilter" do
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
ChainedFilter ||= Rake::Pipeline::Web::Filters::ChainedFilter
input_file1 = MemoryFileWrapper.new("/path", "input.js.strip_asserts.erb", "UTF-8", <<-CONTENT)
@@ -58,6 +59,8 @@ def generate_output(inputs, output)
)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [ file_wrapper ]
filter.output_root = "/output"
filter.rake_application = Rake::Application.new
View
3  spec/coffee_script_filter_spec.rb
@@ -1,6 +1,7 @@
describe "CoffeeScriptFilter" do
CoffeeScriptFilter ||= Rake::Pipeline::Web::Filters::CoffeeScriptFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:coffee_input) { <<-COFFEE }
x = 1;
@@ -46,6 +47,8 @@ def should_match(expected, output)
def setup_filter(filter)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file("input.coffee", coffee_input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
3  spec/gzip_filter_spec.rb
@@ -5,6 +5,7 @@
describe "GzipFilter" do
GzipFilter ||= Rake::Pipeline::Web::Filters::GzipFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:input) { "(function(){console.log('gzip me')})();" }
@@ -18,6 +19,8 @@ def output_file(name)
def setup_filter(filter)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file("test.js", input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
3  spec/handlebars_filter_spec.rb
@@ -1,6 +1,7 @@
describe "HandlebarsFilter" do
HandlebarsFilter ||= Rake::Pipeline::Web::Filters::HandlebarsFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:handlebars_input) {
'<h1 class="title">{{title}}</h1>'
@@ -20,6 +21,8 @@ def output_file(name)
def setup_filter(filter, input_filename = "test.handlebars")
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file(input_filename, handlebars_input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
9 spec/helpers_spec.rb
@@ -119,13 +119,8 @@ def filter
end
describe "ProjectHelpers" do
- def project
- @project ||= Rake::Pipeline::Project.new
- end
-
- def dsl
- @dsl ||= Rake::Pipeline::DSL::ProjectDSL.new(project)
- end
+ let(:project) { Rake::Pipeline::Project.new }
+ let(:dsl) { Rake::Pipeline::DSL::ProjectDSL.new(project) }
describe "register" do
it "registers filters per file name" do
View
3  spec/iife_filter_spec.rb
@@ -1,6 +1,7 @@
describe "IifeFilter" do
IifeFilter ||= Rake::Pipeline::Web::Filters::IifeFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:js_input) { <<-HERE }
var name = "Truckasaurus Gates";
@@ -22,6 +23,8 @@ def output_file(name)
def setup_filter(filter)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file("name.js", js_input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
59 spec/jade_filter_spec.rb
@@ -1,8 +1,9 @@
describe "JadeFilter" do
JadeFilter ||= Rake::Pipeline::Web::Filters::JadeFilter
- MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
- let(:jade_input) {"""
+ let(:jade_input) {
+ """
!!! 5
html
head
@@ -10,12 +11,14 @@
body
h1 Hello
"""
-}
+ }
- let(:expected_html_output) {"""<!DOCTYPE html><html><head><title>Hello</title></head><body><h1>Hello</h1></body></html>"""
-}
+ let(:expected_html_output) {
+ """<!DOCTYPE html><html><head><title>Hello</title></head><body><h1>Hello</h1></body></html>"""
+ }
-let(:expected_prettified_html_output) {"""\
+ let(:expected_prettified_html_output) {
+ """\
<!DOCTYPE html>
<html>
<head>
@@ -25,48 +28,54 @@
<h1>Hello</h1>
</body>
</html>"""
-}
+ }
- def input_file(name, content)
- MemoryFileWrapper.new("/path/to/input", name, "UTF-8", content)
- end
+ let(:input_root) { File.expand_path('./input') }
+ let(:input_path) { 'index.jade' }
- def output_file(name)
- MemoryFileWrapper.new("/path/to/output", name, "UTF-8")
- end
+ let(:input_file) {
+ mkdir_p input_root
+ File.open(File.join(input_root, input_path), 'w+:UTF-8') {|file| file << jade_input }
+ Rake::Pipeline::FileWrapper.new(input_root, input_path, "UTF-8")
+ }
+
+ let(:output_root) { File.expand_path('./output') }
+ let(:output_path) { 'index.html' }
+
+ let(:output_file) {
+ Rake::Pipeline::FileWrapper.new(output_root, output_path, "UTF-8")
+ }
def setup_filter(filter, input=jade_input)
- filter.file_wrapper_class = MemoryFileWrapper
- filter.input_files = [input_file("index.jade", input)]
- filter.output_root = "/path/to/output"
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
+ filter.input_files = [input_file]
+ filter.output_root = output_root
filter.rake_application = Rake::Application.new
filter
end
it "generates output" do
filter = setup_filter JadeFilter.new
-
- filter.output_files.should == [output_file("index.html")]
+ filter.output_files.should == [output_file]
tasks = filter.generate_rake_tasks
tasks.each(&:invoke)
- file = MemoryFileWrapper.files["/path/to/output/index.html"]
- file.body.should == expected_html_output
- file.encoding.should == "UTF-8"
+ output_file.read.should == expected_html_output
+ output_file.encoding.should == "UTF-8"
end
it "prettifies output" do
filter = setup_filter JadeFilter.new :pretty => true
- filter.output_files.should == [output_file("index.html")]
+ filter.output_files.should == [output_file]
tasks = filter.generate_rake_tasks
tasks.each(&:invoke)
- file = MemoryFileWrapper.files["/path/to/output/index.html"]
- file.body.should == expected_prettified_html_output
- file.encoding.should == "UTF-8"
+ output_file.read.should == expected_prettified_html_output
+ output_file.encoding.should == "UTF-8"
end
describe "naming output files" do
View
3  spec/less_filter_spec.rb
@@ -1,6 +1,7 @@
describe "LessFilter" do
LessFilter ||= Rake::Pipeline::Web::Filters::LessFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:less_input) { <<-SCSS }
@blue: #3bbfce;
@@ -26,6 +27,8 @@ def output_file(name)
def setup_filter(filter)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file("border.less", less_input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
3  spec/markdown_filter_spec.rb
@@ -1,6 +1,7 @@
describe "MarkdownFilter" do
MarkdownFilter ||= Rake::Pipeline::Web::Filters::MarkdownFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:markdown_input) { <<-MARKDOWN }
## This is an H2
@@ -33,6 +34,8 @@ def output_file(name)
def setup_filter(filter)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file("page.md", markdown_input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
3  spec/minispade_filter_spec.rb
@@ -2,6 +2,7 @@
describe "MinispadeFilter" do
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
def input_file(contents="var foo = 'bar'; // last-line comment", path="/path/to/input", name="foo.js")
MemoryFileWrapper.new(path, name, "UTF-8", contents)
@@ -20,6 +21,8 @@ def input_file(contents="var foo = 'bar'; // last-line comment", path="/path/to/
def make_filter(input_file, *args)
filter = Rake::Pipeline::Web::Filters::MinispadeFilter.new(*args)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
3  spec/neuter_filter_spec.rb
@@ -2,6 +2,7 @@
describe "NeuterFilter" do
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
def make_input(name, data)
make_data(name, data)
@@ -19,6 +20,8 @@ def make_filter(input_files, *args)
filter = Rake::Pipeline::Web::Filters::NeuterFilter.new(*args)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = input_files
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
3  spec/sass_filter_spec.rb
@@ -1,6 +1,7 @@
describe "SassFilter" do
SassFilter ||= Rake::Pipeline::Web::Filters::SassFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:scss_input) { <<-SCSS }
$blue: #3bbfce;
@@ -36,6 +37,8 @@ def output_file(name)
def setup_filter(filter, input_files=nil)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = input_files || [input_file("border.scss", scss_input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
85 spec/spec_helper.rb
@@ -2,86 +2,11 @@
require "rake-pipeline"
require "rake-pipeline-web-filters"
-class Rake::Pipeline
- module SpecHelpers
-
- class MemoryFileWrapper < Struct.new(:root, :path, :encoding, :body)
- @@files = {}
- @@data = {}
-
- def self.files
- @@files
- end
-
- def self.data
- @@data
- end
-
- def with_encoding(new_encoding)
- self.class.new(root, path, new_encoding, body)
- end
-
- def fullpath
- File.join(root, path)
- end
-
- def create
- @@files[fullpath] = self
- self.body = ""
- yield
- end
-
- def read
- body || @@data[fullpath] || ""
- end
-
- def write(contents)
- self.body << contents
- end
- end
-
- # TODO: OS agnostic modules
- module FileUtils
- def mkdir_p(dir)
- system "mkdir", "-p", dir
- end
-
- def touch(file)
- system "touch", file
- end
-
- def rm_rf(dir)
- system "rm", "-rf", dir
- end
-
- def touch_p(file)
- dir = File.dirname(file)
- mkdir_p dir
- touch file
- end
-
- def age_existing_files
- old_time = Time.now - 10
- Dir[File.join(tmp, "**/*.js")].each do |file|
- File.utime(old_time, old_time, file)
- end
- end
- end
-
- module Filters
- ConcatFilter = Rake::Pipeline::ConcatFilter
- MemoryFileWrapper = Rake::Pipeline::SpecHelpers::MemoryFileWrapper
-
- class StripAssertsFilter < Rake::Pipeline::Filter
- def generate_output(inputs, output)
- inputs.each do |input|
- output.write input.read.gsub(%r{^\s*assert\(.*\)\s*;?\s*$}m, '')
- end
- end
- end
- end
- end
-end
+require "support/spec_helpers/file_utils"
+require "support/spec_helpers/filters"
+require "support/spec_helpers/input_helpers"
+require "support/spec_helpers/memory_file_wrapper"
+require "support/spec_helpers/memory_manifest"
RSpec.configure do |config|
original = Dir.pwd
View
3  spec/stylus_filter_spec.rb
@@ -1,6 +1,7 @@
describe "StylusFilter" do
StylusFilter ||= Rake::Pipeline::Web::Filters::StylusFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:styl_input) { <<-STYLUS }
border-radius()
@@ -36,6 +37,8 @@ def output_file(name)
def setup_filter(filter, input=styl_input)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file("border.styl", input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
33 spec/support/spec_helpers/file_utils.rb
@@ -0,0 +1,33 @@
+class Rake::Pipeline
+ module SpecHelpers
+
+ # TODO: OS agnostic modules
+ module FileUtils
+ def mkdir_p(dir)
+ system "mkdir", "-p", dir
+ end
+
+ def touch(file)
+ system "touch", file
+ end
+
+ def rm_rf(dir)
+ system "rm", "-rf", dir
+ end
+
+ def touch_p(file)
+ dir = File.dirname(file)
+ mkdir_p dir
+ touch file
+ end
+
+ def age_existing_files
+ old_time = Time.now - 10
+ Dir[File.join(tmp, "**/*.js")].each do |file|
+ File.utime(old_time, old_time, file)
+ end
+ end
+ end
+
+ end
+end
View
37 spec/support/spec_helpers/filters.rb
@@ -0,0 +1,37 @@
+class Rake::Pipeline
+ module SpecHelpers
+
+ module Filters
+ ConcatFilter = Rake::Pipeline::ConcatFilter
+
+ class StripAssertsFilter < Rake::Pipeline::Filter
+ def generate_output(inputs, output)
+ inputs.each do |input|
+ output.write input.read.gsub(%r{^\s*assert\(.*\)\s*;?\s*$}m, '')
+ end
+ end
+ end
+
+ class DynamicImportFilter < Rake::Pipeline::Filter
+ def additional_dependencies(input)
+ includes(input)
+ end
+
+ def includes(input)
+ input.read.scan(/^@import\(\"(.*)\"\)$/).map(&:first).map do |inc|
+ File.join(input.root, "#{inc}.import")
+ end
+ end
+
+ def generate_output(inputs, output)
+ inputs.each do |input|
+ output.write input.read
+ includes(input).each do |inc|
+ output.write File.read(inc)
+ end
+ end
+ end
+ end
+ end
+ end
+end
View
23 spec/support/spec_helpers/input_helpers.rb
@@ -0,0 +1,23 @@
+class Rake::Pipeline
+ module SpecHelpers
+ module InputHelpers
+ def input_file(path, root=File.join(tmp, "app/assets"))
+ Rake::Pipeline::FileWrapper.new root, path
+ end
+
+ def output_file(path, root=File.join(tmp, "public"))
+ input_file(path, root)
+ end
+
+ def create_files(files)
+ Array(files).each do |file|
+ mkdir_p File.dirname(file.fullpath)
+
+ File.open(file.fullpath, "w") do |file|
+ file.write "// This is #{file.path}\n"
+ end
+ end
+ end
+ end
+ end
+end
View
38 spec/support/spec_helpers/memory_file_wrapper.rb
@@ -0,0 +1,38 @@
+class Rake::Pipeline
+ module SpecHelpers
+ class MemoryFileWrapper < Struct.new(:root, :path, :encoding, :body)
+ @@files = {}
+ @@data = {}
+
+ def self.files
+ @@files
+ end
+
+ def self.data
+ @@data
+ end
+
+ def with_encoding(new_encoding)
+ self.class.new(root, path, new_encoding, body)
+ end
+
+ def fullpath
+ File.join(root, path)
+ end
+
+ def create
+ @@files[fullpath] = self
+ self.body = ""
+ yield
+ end
+
+ def read
+ body || @@data[fullpath] || ""
+ end
+
+ def write(contents)
+ self.body << contents
+ end
+ end
+ end
+end
View
19 spec/support/spec_helpers/memory_manifest.rb
@@ -0,0 +1,19 @@
+class Rake::Pipeline
+ module SpecHelpers
+ class MemoryManifest
+ def initialize
+ @entries = {}
+ end
+
+ # Look up an entry by filename.
+ def [](key)
+ @entries[key]
+ end
+
+ # Set an entry
+ def []=(key, value)
+ @entries[key] = value
+ end
+ end
+ end
+end
View
3  spec/tilt_filter_spec.rb
@@ -1,5 +1,6 @@
describe "TiltFilter" do
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:input_files) {
[
@@ -20,6 +21,8 @@ def make_filter(*args)
input.sub(/\.(erb|str)$/, '.txt')
end
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = input_files
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
3  spec/uglify_filter_spec.rb
@@ -1,6 +1,7 @@
describe "UglifyFilter" do
UglifyFilter ||= Rake::Pipeline::Web::Filters::UglifyFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:js_input) { <<-HERE }
var name = "Truckasaurus Gates";
@@ -25,6 +26,8 @@ def output_file(name)
def setup_filter(filter)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file("name.js", js_input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
3  spec/yui_css_filter_spec.rb
@@ -1,6 +1,7 @@
describe "YUICssFilter" do
YUICssFilter ||= Rake::Pipeline::Web::Filters::YUICssFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:css_input) { <<-HERE }
div.error {
@@ -29,6 +30,8 @@ def output_file(name)
def setup_filter(filter)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file("error.css", css_input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
View
3  spec/yui_javascript_filter_spec.rb
@@ -1,6 +1,7 @@
describe "YUIJavaScriptFilter" do
YUIFilter ||= Rake::Pipeline::Web::Filters::YUIJavaScriptFilter
MemoryFileWrapper ||= Rake::Pipeline::SpecHelpers::MemoryFileWrapper
+ MemoryManifest ||= Rake::Pipeline::SpecHelpers::MemoryManifest
let(:js_input) { <<-HERE }
var name = "Truckasaurus Gates";
@@ -25,6 +26,8 @@ def output_file(name)
def setup_filter(filter)
filter.file_wrapper_class = MemoryFileWrapper
+ filter.manifest = MemoryManifest.new
+ filter.last_manifest = MemoryManifest.new
filter.input_files = [input_file("name.js", js_input)]
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
Please sign in to comment.
Something went wrong with that request. Please try again.