2011-06-09 19:44:35 +00:00
|
|
|
require 'test_helper'
|
|
|
|
require 'timecop'
|
|
|
|
class ImporterTest < Test::Unit::TestCase
|
2011-07-26 20:20:51 +00:00
|
|
|
include SpriteHelper
|
2011-06-09 19:44:35 +00:00
|
|
|
|
|
|
|
def setup
|
2011-07-26 20:20:51 +00:00
|
|
|
create_sprite_temp
|
2011-06-09 19:44:35 +00:00
|
|
|
file = StringIO.new("images_path = #{@images_src_path.inspect}\n")
|
|
|
|
Compass.add_configuration(file, "sprite_config")
|
2011-06-16 03:37:23 +00:00
|
|
|
@importer = Compass::SpriteImporter.new
|
2011-06-09 19:44:35 +00:00
|
|
|
end
|
2011-06-11 17:24:17 +00:00
|
|
|
|
|
|
|
def teardown
|
|
|
|
Compass.reset_configuration!
|
|
|
|
end
|
2011-06-09 19:44:35 +00:00
|
|
|
|
|
|
|
def options
|
|
|
|
{:foo => 'bar'}
|
|
|
|
end
|
|
|
|
|
2011-07-26 20:21:59 +00:00
|
|
|
test "should use search path to find sprites" do
|
|
|
|
Compass.reset_configuration!
|
|
|
|
uri = 'foo/*.png'
|
|
|
|
other_folder = File.join(@images_tmp_path, '../other-temp')
|
|
|
|
FileUtils.mkdir_p other_folder
|
|
|
|
FileUtils.mkdir_p File.join(other_folder, 'foo')
|
|
|
|
%w(my bar).each do |file|
|
|
|
|
FileUtils.touch(File.join(other_folder, "foo/#{file}.png"))
|
|
|
|
end
|
|
|
|
config = Compass::Configuration::Data.new('config')
|
|
|
|
config.images_path = @images_tmp_path
|
2011-07-26 21:53:56 +00:00
|
|
|
config.sprite_load_path = [@images_tmp_path, other_folder]
|
2011-07-26 20:21:59 +00:00
|
|
|
Compass.add_configuration(config, "sprite_config")
|
|
|
|
importer = Compass::SpriteImporter.new
|
2011-07-26 21:53:56 +00:00
|
|
|
assert_equal 2, Compass.configuration.sprite_load_path.compact.size
|
|
|
|
assert Compass.configuration.sprite_load_path.include?(other_folder)
|
2011-07-26 20:21:59 +00:00
|
|
|
assert_equal ["bar", "my"], Compass::SpriteImporter.sprite_names(uri)
|
|
|
|
|
|
|
|
FileUtils.rm_rf other_folder
|
|
|
|
end
|
|
|
|
|
2011-06-09 19:44:35 +00:00
|
|
|
test "name should return the sprite name" do
|
2011-06-16 03:37:23 +00:00
|
|
|
assert_equal 'selectors', Compass::SpriteImporter.sprite_name(URI)
|
2011-06-09 19:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "path should return the sprite path" do
|
2011-06-16 03:37:23 +00:00
|
|
|
assert_equal 'selectors', Compass::SpriteImporter.path(URI)
|
2011-06-09 19:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "should return all the sprite names" do
|
2011-06-16 03:37:23 +00:00
|
|
|
assert_equal ["ten-by-ten", "ten-by-ten_active", "ten-by-ten_hover", "ten-by-ten_target"], Compass::SpriteImporter.sprite_names(URI)
|
2011-06-09 19:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "should have correct mtime" do
|
|
|
|
thirtydays = Time.now.to_i + (60*60*24*30)
|
|
|
|
file = Dir[File.join(@images_src_path, URI)].sort.first
|
|
|
|
File.utime(thirtydays, thirtydays, file)
|
|
|
|
assert_equal thirtydays, File.mtime(file).to_i
|
|
|
|
assert_equal thirtydays, @importer.mtime(URI, {}).to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should return sass engine on find" do
|
|
|
|
assert @importer.find(URI, {}).is_a?(Sass::Engine)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "sass options should contain options" do
|
2011-06-19 16:26:38 +00:00
|
|
|
opts = Compass::SpriteImporter.sass_options('foo', @importer, options)
|
2011-06-16 03:37:23 +00:00
|
|
|
assert_equal 'bar', opts[:foo]
|
2011-06-09 19:44:35 +00:00
|
|
|
end
|
|
|
|
|
2011-09-13 00:44:12 +00:00
|
|
|
test "verify that the sass_engine passes the correct filename" do
|
|
|
|
importer = Compass::SpriteImporter.new
|
|
|
|
engine = Compass::SpriteImporter.sass_engine(URI, 'foo', importer, options)
|
|
|
|
assert_equal engine.options[:filename], URI
|
|
|
|
end
|
|
|
|
|
2011-06-11 17:24:17 +00:00
|
|
|
test "should fail given bad sprite extensions" do
|
2011-06-09 20:27:23 +00:00
|
|
|
@images_src_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images')
|
|
|
|
file = StringIO.new("images_path = #{@images_src_path.inspect}\n")
|
|
|
|
Compass.add_configuration(file, "sprite_config")
|
2011-06-16 03:37:23 +00:00
|
|
|
importer = Compass::SpriteImporter.new
|
|
|
|
uri = "bad_extensions/*.jpg"
|
2011-06-09 20:27:23 +00:00
|
|
|
begin
|
2011-06-16 03:37:23 +00:00
|
|
|
Compass::SpriteImporter.sass_engine(uri, Compass::SpriteImporter.sprite_name(uri), importer, {})
|
2011-06-11 17:24:17 +00:00
|
|
|
assert false, "An invalid sprite file made it past validation."
|
2011-06-09 20:27:23 +00:00
|
|
|
rescue Compass::Error => e
|
2011-06-16 03:37:23 +00:00
|
|
|
assert e.message.include?("invalid sprite path")
|
2011-06-09 20:27:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-09 19:44:35 +00:00
|
|
|
end
|