Created
July 20, 2009 19:35
-
-
Save craigw/150794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../../spec_helper' | |
describe "Stylesheet" do | |
stylesheet_root = File.expand_path(RAILS_ROOT + '/public') | |
stylesheets = Dir[File.join(stylesheet_root, "**", "*.css")] | |
stylesheets.each do |stylesheet| | |
describe stylesheet do | |
it "should not @import files that don't exist" do | |
missing_imports = [] | |
imports = File.read(stylesheet).split(/\n|\r/).grep(/\@import url\((.*)\)/) | |
imports.each do |import| | |
desired_path = import.scan(/url\((["'\ ])?(.*)\1\)/).to_a.first.to_a.last | |
desired_root = desired_path[0,1] == "/" ? stylesheet_root : File.dirname(stylesheet) | |
filesystem_path = File.expand_path(File.join(desired_root, desired_path)) | |
if !File.exists?(filesystem_path) | |
missing_imports << { :path => filesystem_path, :directive => import } | |
end | |
end | |
if missing_imports.any? | |
exception = [] | |
missing_imports.each do |import| | |
exception << "Missing @import file (#{import[:path]}) required for #{import[:directive]}" | |
end | |
raise exception.join("\n") | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment