Fix some failing tests and refactor the tests to make better use of new compass facilities that didn't exist when the tests were first written.
This commit is contained in:
parent
3921465e95
commit
d4aa36f0f0
@ -138,6 +138,7 @@ FRAMEWORKS
|
|||||||
end
|
end
|
||||||
message = "Action #{action.inspect} was not performed on: #{path}."
|
message = "Action #{action.inspect} was not performed on: #{path}."
|
||||||
message += "The following actions were performed: #{actions_found.join(", ")}" if actions_found.any?
|
message += "The following actions were performed: #{actions_found.join(", ")}" if actions_found.any?
|
||||||
|
puts @last_result
|
||||||
fail message
|
fail message
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,71 +5,67 @@ require 'compass'
|
|||||||
class CompassTest < Test::Unit::TestCase
|
class CompassTest < Test::Unit::TestCase
|
||||||
include Compass::TestCaseHelper
|
include Compass::TestCaseHelper
|
||||||
def setup
|
def setup
|
||||||
setup_fixtures :blueprint, :yui, :empty
|
Compass.configuration.reset!
|
||||||
@original_options = Sass::Plugin.options
|
|
||||||
end
|
|
||||||
|
|
||||||
def setup_fixtures(*folders)
|
|
||||||
folders.each do |folder|
|
|
||||||
FileUtils.mkdir_p stylesheet_fixtures(folder)
|
|
||||||
mkdir_clean tempfile_loc(folder)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
teardown_fixtures :blueprint, :yui, :empty
|
teardown_fixtures :blueprint, :yui, :empty, :compass
|
||||||
Sass::Plugin.options = @original_options
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown_fixtures(*folders)
|
def teardown_fixtures(*project_names)
|
||||||
folders.each do |folder|
|
project_names.each do |project_name|
|
||||||
FileUtils.rm_rf tempfile_loc(folder)
|
FileUtils.rm_rf tempfile_path(project_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_blueprint_generates_no_files
|
def test_blueprint_generates_no_files
|
||||||
with_templates(:empty) do
|
within_project(:empty) do |proj|
|
||||||
Dir.new(tempfile_loc(:empty)).each do |f|
|
return unless File.exists?(proj.css_path)
|
||||||
|
Dir.new(proj.css_path).each do |f|
|
||||||
fail "This file should not have been generated: #{f}" unless f == "." || f == ".."
|
fail "This file should not have been generated: #{f}" unless f == "." || f == ".."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_blueprint
|
def test_blueprint
|
||||||
with_templates(:blueprint) do
|
within_project(:blueprint) do |proj|
|
||||||
each_css_file(tempfile_loc(:blueprint)) do |css_file|
|
each_css_file(proj.css_path) do |css_file|
|
||||||
assert_no_errors css_file, :blueprint
|
assert_no_errors css_file, :blueprint
|
||||||
end
|
end
|
||||||
assert_renders_correctly :typography
|
assert_renders_correctly :typography
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_yui
|
def test_yui
|
||||||
with_templates('yui') do
|
within_project('yui') do |proj|
|
||||||
each_css_file(tempfile_loc('yui')) do |css_file|
|
each_css_file(proj.css_path) do |css_file|
|
||||||
assert_no_errors css_file, 'yui'
|
assert_no_errors css_file, 'yui'
|
||||||
end
|
end
|
||||||
assert_renders_correctly :mixins
|
assert_renders_correctly :mixins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_compass
|
def test_compass
|
||||||
with_templates('compass') do
|
within_project('compass') do |proj|
|
||||||
each_css_file(tempfile_loc('compass')) do |css_file|
|
each_css_file(proj.css_path) do |css_file|
|
||||||
assert_no_errors css_file, 'compass'
|
assert_no_errors css_file, 'compass'
|
||||||
end
|
end
|
||||||
assert_renders_correctly :reset, :layout, :utilities
|
assert_renders_correctly :reset, :layout, :utilities
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
private
|
|
||||||
def assert_no_errors(css_file, folder)
|
private
|
||||||
file = css_file[(tempfile_loc(folder).size+1)..-1]
|
def assert_no_errors(css_file, project_name)
|
||||||
msg = "Syntax Error found in #{file}. Results saved into #{save_loc(folder)}/#{file}"
|
file = css_file[(tempfile_path(project_name).size+1)..-1]
|
||||||
|
msg = "Syntax Error found in #{file}. Results saved into #{save_path(project_name)}/#{file}"
|
||||||
assert_equal 0, open(css_file).readlines.grep(/Sass::SyntaxError/).size, msg
|
assert_equal 0, open(css_file).readlines.grep(/Sass::SyntaxError/).size, msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_renders_correctly(*arguments)
|
def assert_renders_correctly(*arguments)
|
||||||
options = arguments.last.is_a?(Hash) ? arguments.pop : {}
|
options = arguments.last.is_a?(Hash) ? arguments.pop : {}
|
||||||
for name in arguments
|
for name in arguments
|
||||||
actual_result_file = "#{tempfile_loc(@current_template_folder)}/#{name}.css"
|
actual_result_file = "#{tempfile_path(@current_project)}/#{name}.css"
|
||||||
expected_result_file = "#{result_loc(@current_template_folder)}/#{name}.css"
|
expected_result_file = "#{result_path(@current_project)}/#{name}.css"
|
||||||
actual_lines = File.read(actual_result_file).split("\n")
|
actual_lines = File.read(actual_result_file).split("\n")
|
||||||
expected_lines = File.read(expected_result_file).split("\n")
|
expected_lines = File.read(expected_result_file).split("\n")
|
||||||
expected_lines.zip(actual_lines).each_with_index do |pair, line|
|
expected_lines.zip(actual_lines).each_with_index do |pair, line|
|
||||||
@ -81,27 +77,17 @@ class CompassTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def with_templates(folder)
|
|
||||||
old_template_loc = Sass::Plugin.options[:template_location]
|
def within_project(project_name)
|
||||||
Sass::Plugin.options[:template_location] = if old_template_loc.is_a?(Hash)
|
@current_project = project_name
|
||||||
old_template_loc.dup
|
Compass.configuration.parse(configuration_file(project_name))
|
||||||
else
|
Compass.configuration.project_path = project_path(project_name)
|
||||||
Hash.new
|
args = Compass.configuration.to_compiler_arguments(:logger => Compass::NullLogger.new)
|
||||||
end
|
compiler = Compass::Compiler.new *args
|
||||||
@current_template_folder = folder
|
compiler.run
|
||||||
begin
|
yield Compass.configuration
|
||||||
Sass::Plugin.options[:template_location][template_loc(folder)] = tempfile_loc(folder)
|
|
||||||
Compass::Frameworks::ALL.each do |framework|
|
|
||||||
Sass::Plugin.options[:template_location][framework.stylesheets_directory] = tempfile_loc(folder)
|
|
||||||
end
|
|
||||||
Sass::Plugin.update_stylesheets
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
@current_template_folder = nil
|
|
||||||
Sass::Plugin.options[:template_location] = old_template_loc
|
|
||||||
end
|
|
||||||
rescue
|
rescue
|
||||||
save_output(folder)
|
save_output(project_name)
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -112,37 +98,32 @@ class CompassTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def save_output(dir)
|
def save_output(dir)
|
||||||
FileUtils.rm_rf(save_loc(dir))
|
FileUtils.rm_rf(save_path(dir))
|
||||||
FileUtils.cp_r(tempfile_loc(dir), save_loc(dir))
|
FileUtils.cp_r(tempfile_path(dir), save_path(dir)) if File.exists?(tempfile_path(dir))
|
||||||
end
|
end
|
||||||
|
|
||||||
def mkdir_clean(dir)
|
def project_path(project_name)
|
||||||
begin
|
absolutize("fixtures/stylesheets/#{project_name}")
|
||||||
FileUtils.mkdir dir
|
|
||||||
rescue Errno::EEXIST
|
|
||||||
FileUtils.rm_r dir
|
|
||||||
FileUtils.mkdir dir
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def stylesheet_fixtures(folder)
|
def configuration_file(project_name)
|
||||||
absolutize("fixtures/stylesheets/#{folder}")
|
File.join(project_path(project_name), "config.rb")
|
||||||
end
|
end
|
||||||
|
|
||||||
def tempfile_loc(folder)
|
def tempfile_path(project_name)
|
||||||
"#{stylesheet_fixtures(folder)}/tmp"
|
File.join(project_path(project_name), "tmp")
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_loc(folder)
|
def template_path(project_name)
|
||||||
"#{stylesheet_fixtures(folder)}/sass"
|
File.join(project_path(project_name), "sass")
|
||||||
end
|
end
|
||||||
|
|
||||||
def result_loc(folder)
|
def result_path(project_name)
|
||||||
"#{stylesheet_fixtures(folder)}/css"
|
File.join(project_path(project_name), "css")
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_loc(folder)
|
def save_path(project_name)
|
||||||
"#{stylesheet_fixtures(folder)}/saved"
|
File.join(project_path(project_name), "saved")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -2,18 +2,21 @@ require File.dirname(__FILE__)+'/test_helper'
|
|||||||
require 'compass'
|
require 'compass'
|
||||||
|
|
||||||
class ConfigurationTest < Test::Unit::TestCase
|
class ConfigurationTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_parse_and_serialize
|
def test_parse_and_serialize
|
||||||
contents = <<-CONFIG
|
contents = <<-CONFIG
|
||||||
require 'compass'
|
require 'compass'
|
||||||
require 'sass'
|
|
||||||
# Require any additional compass plugins here.
|
# Require any additional compass plugins here.
|
||||||
|
|
||||||
|
project_type = :stand_alone
|
||||||
css_dir = "css"
|
css_dir = "css"
|
||||||
sass_dir = "sass"
|
sass_dir = "sass"
|
||||||
images_dir = "img"
|
images_dir = "img"
|
||||||
javascripts_dir = "js"
|
javascripts_dir = "js"
|
||||||
|
output_style = :nested
|
||||||
# To enable relative image paths using the images_url() function:
|
# To enable relative image paths using the images_url() function:
|
||||||
# http_images_path = :relative
|
# http_images_path = :relative
|
||||||
|
http_images_path = "/images"
|
||||||
CONFIG
|
CONFIG
|
||||||
|
|
||||||
Compass.configuration.parse_string(contents, "test_parse")
|
Compass.configuration.parse_string(contents, "test_parse")
|
||||||
|
9
test/fixtures/stylesheets/blueprint/config.rb
vendored
Normal file
9
test/fixtures/stylesheets/blueprint/config.rb
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Require any additional compass plugins here.
|
||||||
|
project_type = :stand_alone
|
||||||
|
css_dir = "tmp"
|
||||||
|
sass_dir = "sass"
|
||||||
|
images_dir = "images"
|
||||||
|
output_style = :nested
|
||||||
|
# To enable relative image paths using the images_url() function:
|
||||||
|
# http_images_path = :relative
|
||||||
|
http_images_path = "/images"
|
9
test/fixtures/stylesheets/compass/config.rb
vendored
Normal file
9
test/fixtures/stylesheets/compass/config.rb
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Require any additional compass plugins here.
|
||||||
|
project_type = :stand_alone
|
||||||
|
css_dir = "tmp"
|
||||||
|
sass_dir = "sass"
|
||||||
|
images_dir = "images"
|
||||||
|
output_style = :nested
|
||||||
|
# To enable relative image paths using the images_url() function:
|
||||||
|
# http_images_path = :relative
|
||||||
|
http_images_path = "/images"
|
9
test/fixtures/stylesheets/yui/config.rb
vendored
Normal file
9
test/fixtures/stylesheets/yui/config.rb
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Require any additional compass plugins here.
|
||||||
|
project_type = :stand_alone
|
||||||
|
css_dir = "tmp"
|
||||||
|
sass_dir = "sass"
|
||||||
|
images_dir = "images"
|
||||||
|
output_style = :nested
|
||||||
|
# To enable relative image paths using the images_url() function:
|
||||||
|
# http_images_path = :relative
|
||||||
|
http_images_path = "/images"
|
Loading…
Reference in New Issue
Block a user