2009-02-13 07:08:57 +00:00
|
|
|
require File.dirname(__FILE__)+'/test_helper'
|
|
|
|
require 'compass'
|
2009-08-25 21:18:58 +00:00
|
|
|
require 'stringio'
|
2009-02-13 07:08:57 +00:00
|
|
|
|
|
|
|
class ConfigurationTest < Test::Unit::TestCase
|
2009-08-25 21:18:58 +00:00
|
|
|
include Compass::IoHelper
|
2009-05-08 15:08:26 +00:00
|
|
|
|
2009-05-08 15:11:42 +00:00
|
|
|
def setup
|
2009-08-25 21:18:58 +00:00
|
|
|
Compass.reset_configuration!
|
2009-05-08 15:11:42 +00:00
|
|
|
end
|
|
|
|
|
2009-02-13 07:08:57 +00:00
|
|
|
def test_parse_and_serialize
|
2009-08-25 21:18:58 +00:00
|
|
|
contents = StringIO.new(<<-CONFIG)
|
2009-02-13 07:08:57 +00:00
|
|
|
require 'compass'
|
2009-02-21 01:11:22 +00:00
|
|
|
# Require any additional compass plugins here.
|
2009-02-13 07:08:57 +00:00
|
|
|
|
2009-05-08 15:08:26 +00:00
|
|
|
project_type = :stand_alone
|
2009-02-13 07:08:57 +00:00
|
|
|
css_dir = "css"
|
|
|
|
sass_dir = "sass"
|
|
|
|
images_dir = "img"
|
|
|
|
javascripts_dir = "js"
|
2009-08-25 21:18:58 +00:00
|
|
|
# Set this to the root of your project when deployed:
|
|
|
|
http_path = "/"
|
2009-05-08 15:08:26 +00:00
|
|
|
output_style = :nested
|
2009-07-04 01:42:16 +00:00
|
|
|
# To enable relative paths to assets via compass helper functions. Uncomment:
|
|
|
|
# relative_assets = true
|
2009-02-13 07:08:57 +00:00
|
|
|
CONFIG
|
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
Compass.add_configuration(contents, "test_parse")
|
2009-02-13 07:08:57 +00:00
|
|
|
|
|
|
|
assert_equal 'sass', Compass.configuration.sass_dir
|
|
|
|
assert_equal 'css', Compass.configuration.css_dir
|
|
|
|
assert_equal 'img', Compass.configuration.images_dir
|
|
|
|
assert_equal 'js', Compass.configuration.javascripts_dir
|
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
expected_lines = contents.string.split("\n").map{|l|l.strip}
|
2009-02-13 07:08:57 +00:00
|
|
|
actual_lines = Compass.configuration.serialize.split("\n").map{|l|l.strip}
|
|
|
|
assert_equal expected_lines, actual_lines
|
|
|
|
end
|
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
def test_serialization_warns_with_asset_host_set
|
|
|
|
contents = StringIO.new(<<-CONFIG)
|
2009-06-27 18:28:16 +00:00
|
|
|
asset_host do |path|
|
|
|
|
"http://example.com"
|
|
|
|
end
|
|
|
|
CONFIG
|
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
Compass.add_configuration(contents, "test_serialization_warns_with_asset_host_set")
|
2009-06-27 18:28:16 +00:00
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
warning = capture_warning do
|
2009-06-27 18:28:16 +00:00
|
|
|
Compass.configuration.serialize
|
|
|
|
end
|
2009-08-25 21:18:58 +00:00
|
|
|
assert_equal "WARNING: asset_host is code and cannot be written to a file. You'll need to copy it yourself.\n", warning
|
2009-06-27 18:28:16 +00:00
|
|
|
end
|
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
def test_serialization_warns_with_asset_cache_buster_set
|
|
|
|
contents = StringIO.new(<<-CONFIG)
|
2009-06-27 18:28:16 +00:00
|
|
|
asset_cache_buster do |path|
|
|
|
|
"http://example.com"
|
|
|
|
end
|
|
|
|
CONFIG
|
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
Compass.add_configuration(contents, "test_serialization_warns_with_asset_cache_buster_set")
|
2009-06-27 18:28:16 +00:00
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
warning = capture_warning do
|
2009-06-27 18:28:16 +00:00
|
|
|
Compass.configuration.serialize
|
|
|
|
end
|
2009-08-25 21:18:58 +00:00
|
|
|
assert_equal "WARNING: asset_cache_buster is code and cannot be written to a file. You'll need to copy it yourself.\n", warning
|
2009-06-27 18:28:16 +00:00
|
|
|
end
|
|
|
|
|
2009-06-27 19:15:28 +00:00
|
|
|
def test_additional_import_paths
|
2009-08-25 21:18:58 +00:00
|
|
|
contents = StringIO.new(<<-CONFIG)
|
2009-07-04 01:45:19 +00:00
|
|
|
http_path = "/"
|
2009-06-27 19:15:28 +00:00
|
|
|
project_path = "/home/chris/my_compass_project"
|
|
|
|
css_dir = "css"
|
|
|
|
additional_import_paths = ["../foo"]
|
|
|
|
add_import_path "/path/to/my/framework"
|
|
|
|
CONFIG
|
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
Compass.add_configuration(contents, "test_additional_import_paths")
|
2009-06-27 19:15:28 +00:00
|
|
|
|
|
|
|
assert Compass.configuration.to_sass_engine_options[:load_paths].include?("/home/chris/my_compass_project/../foo")
|
|
|
|
assert Compass.configuration.to_sass_engine_options[:load_paths].include?("/path/to/my/framework"), Compass.configuration.to_sass_engine_options[:load_paths].inspect
|
|
|
|
assert_equal "/home/chris/my_compass_project/css/framework", Compass.configuration.to_sass_plugin_options[:template_location]["/path/to/my/framework"]
|
|
|
|
assert_equal "/home/chris/my_compass_project/css/foo", Compass.configuration.to_sass_plugin_options[:template_location]["/home/chris/my_compass_project/../foo"]
|
|
|
|
|
|
|
|
expected_serialization = <<EXPECTED
|
|
|
|
# Require any additional compass plugins here.
|
|
|
|
project_path = "/home/chris/my_compass_project"
|
2009-08-25 21:18:58 +00:00
|
|
|
css_dir = "css"
|
2009-07-04 01:45:19 +00:00
|
|
|
# Set this to the root of your project when deployed:
|
|
|
|
http_path = "/"
|
2009-07-04 01:42:16 +00:00
|
|
|
# To enable relative paths to assets via compass helper functions. Uncomment:
|
|
|
|
# relative_assets = true
|
2009-06-27 19:15:28 +00:00
|
|
|
additional_import_paths = ["../foo", "/path/to/my/framework"]
|
|
|
|
EXPECTED
|
2009-07-04 01:45:19 +00:00
|
|
|
assert_equal "/", Compass.configuration.http_path
|
2009-08-25 21:18:58 +00:00
|
|
|
assert_equal expected_serialization.split("\n"), Compass.configuration.serialize.split("\n")
|
2009-06-27 19:15:28 +00:00
|
|
|
end
|
|
|
|
|
2009-06-27 20:05:30 +00:00
|
|
|
def test_sass_options
|
2009-08-25 21:18:58 +00:00
|
|
|
contents = StringIO.new(<<-CONFIG)
|
2009-06-27 20:05:30 +00:00
|
|
|
sass_options = {:foo => 'bar'}
|
|
|
|
CONFIG
|
|
|
|
|
2009-08-25 21:18:58 +00:00
|
|
|
Compass.add_configuration(contents, "test_sass_options")
|
2009-06-27 20:05:30 +00:00
|
|
|
|
|
|
|
assert_equal 'bar', Compass.configuration.to_sass_engine_options[:foo]
|
|
|
|
assert_equal 'bar', Compass.configuration.to_sass_plugin_options[:foo]
|
|
|
|
|
|
|
|
expected_serialization = <<EXPECTED
|
|
|
|
# Require any additional compass plugins here.
|
2009-07-04 01:42:16 +00:00
|
|
|
# Set this to the root of your project when deployed:
|
2009-08-25 21:18:58 +00:00
|
|
|
http_path = "/"
|
2009-07-04 01:42:16 +00:00
|
|
|
# To enable relative paths to assets via compass helper functions. Uncomment:
|
|
|
|
# relative_assets = true
|
2009-06-27 20:05:30 +00:00
|
|
|
sass_options = {:foo=>"bar"}
|
|
|
|
EXPECTED
|
2009-07-04 01:42:16 +00:00
|
|
|
|
2009-06-27 20:05:30 +00:00
|
|
|
assert_equal expected_serialization, Compass.configuration.serialize
|
|
|
|
end
|
|
|
|
|
2009-02-13 07:08:57 +00:00
|
|
|
end
|