require 'test_helper' require 'compass' require 'stringio' class ConfigurationTest < Test::Unit::TestCase setup do Compass.reset_configuration! end after do Compass.reset_configuration! end def test_parse_and_serialize contents = StringIO.new(<<-CONFIG) require 'compass' # Require any additional compass plugins here. project_type = :stand_alone http_path = "/" css_dir = "css" sass_dir = "sass" images_dir = "img" javascripts_dir = "js" output_style = :nested # To enable relative paths to assets via compass helper functions. Uncomment: # relative_assets = true # To disable debugging comments that display the original location of your selectors. Uncomment: # line_comments = false # If you prefer the indented syntax, you might want to regenerate this # project again passing --syntax sass, or you can uncomment this: # preferred_syntax = :sass # and then run: # sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass CONFIG Compass.add_configuration(contents, "test_parse") 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 expected_lines = contents.string.split("\n").map{|l|l.strip} actual_lines = Compass.configuration.serialize.split("\n").map{|l|l.strip} assert_correct expected_lines, actual_lines end def test_serialization_warns_with_asset_host_set contents = StringIO.new(<<-CONFIG) asset_host do |path| "http://example.com" end CONFIG Compass.add_configuration(contents, "test_serialization_warns_with_asset_host_set") warning = capture_warning do Compass.configuration.serialize end assert_equal "WARNING: asset_host is code and cannot be written to a file. You'll need to copy it yourself.\n", warning end class TestData < Compass::Configuration::Data def initialize super(:test) end inherited_array :stuff end def test_inherited_array_can_clobber data1 = TestData.new data1.stuff = [:a] data2 = TestData.new data2.stuff = [:b] data2.inherit_from!(data1) assert_equal [:b], data2.stuff.to_a end def test_inherited_array_can_append data1 = TestData.new data1.stuff = [:a] data2 = TestData.new data2.stuff << :b data2.inherit_from!(data1) assert_equal [:b, :a], data2.stuff.to_a end def test_inherited_array_can_append_2 data1 = TestData.new data1.stuff = [:a] data2 = TestData.new data2.stuff << :b data2.inherit_from!(data1) data3 = TestData.new data3.stuff << :c data3.inherit_from!(data2) assert_equal [:c, :b, :a], data3.stuff.to_a end def test_inherited_array_can_remove data1 = TestData.new data1.stuff = [:a] data2 = TestData.new data2.stuff >> :a data2.inherit_from!(data1) assert_equal [], data2.stuff.to_a end def test_inherited_array_combined_augmentations data1 = TestData.new data1.stuff = [:a] data2 = TestData.new data2.stuff >> :a data2.stuff << :b data2.inherit_from!(data1) assert_equal [:b], data2.stuff.to_a end def test_inherited_array_long_methods data1 = TestData.new data1.stuff = [:a] data2 = TestData.new data2.remove_from_stuff(:a) data2.add_to_stuff(:b) data2.inherit_from!(data1) assert_equal [:b], data2.stuff.to_a end def test_inherited_array_augmentations_can_be_clobbered data1 = TestData.new data1.stuff = [:a] data2 = TestData.new data2.stuff >> :a data2.stuff << :b data2.stuff = [:c] data2.inherit_from!(data1) assert_equal [:c], data2.stuff.to_a end def test_inherited_array_augmentations_after_clobbering data1 = TestData.new data1.stuff = [:a] data2 = TestData.new data2.stuff >> :a data2.stuff << :b data2.stuff = [:c, :d] data2.stuff << :e data2.stuff >> :c data2.inherit_from!(data1) assert_equal [:d, :e], data2.stuff.to_a end def test_serialization_warns_with_asset_cache_buster_set contents = StringIO.new(<<-CONFIG) asset_cache_buster do |path| "http://example.com" end CONFIG Compass.add_configuration(contents, "test_serialization_warns_with_asset_cache_buster_set") assert_kind_of Proc, Compass.configuration.asset_cache_buster_without_default assert_equal "http://example.com", Compass.configuration.asset_cache_buster_without_default.call("whatever") warning = capture_warning do Compass.configuration.serialize end assert_equal "WARNING: asset_cache_buster is code and cannot be written to a file. You'll need to copy it yourself.\n", warning end def test_inherited_arrays_augmentations_serialize inherited = TestData.new inherited.stuff << :a d = TestData.new d.stuff << :b d.stuff >> :c assert_equal <> :c CONFIG end def test_inherited_arrays_clobbering_with_augmentations_serialize inherited = TestData.new inherited.stuff << :a d = TestData.new d.stuff << :b d.stuff = [:c, :d] d.stuff << :e assert_equal < 'bar'} CONFIG Compass.add_configuration(contents, "test_sass_options") assert_equal 'bar', Compass.configuration.to_sass_engine_options[:foo] assert_equal 'bar', Compass.configuration.to_sass_plugin_options[:foo] expected_serialization = <\"bar\"} # To disable debugging comments that display the original location of your selectors. Uncomment: # line_comments = false EXPECTED assert_correct(expected_serialization, Compass.configuration.serialize) end def test_sprite_load_path_clobbers contents = StringIO.new(<<-CONFIG) sprite_load_path = ["/Users/chris/Projects/my_compass_project/images/sprites"] CONFIG Compass.add_configuration(contents, "test_sass_options") assert_equal ["/Users/chris/Projects/my_compass_project/images/sprites"], Compass.configuration.sprite_load_path.to_a expected_serialization = <