From 8e2292b2a595ad52bd4dd8365bfcf3d641d0a327 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Thu, 28 Apr 2011 00:35:10 -0400 Subject: [PATCH] sprite base test --- test/sprites/base_test.rb | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/sprites/base_test.rb diff --git a/test/sprites/base_test.rb b/test/sprites/base_test.rb new file mode 100644 index 00000000..7205b027 --- /dev/null +++ b/test/sprites/base_test.rb @@ -0,0 +1,73 @@ +require 'test_helper' + +class SpritesBaseTest < Test::Unit::TestCase + + def setup + @images_src_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'sprites', 'public', 'images') + @images_tmp_path = File.join(File.dirname(__FILE__), '..', 'fixtures', 'sprites', 'public', 'images-tmp') + FileUtils.cp_r @images_src_path, @images_tmp_path + config = Compass::Configuration::Data.new('config') + config.images_path = @images_tmp_path + Compass.add_configuration(config) + Compass.configure_sass_plugin! + options = Compass.sass_engine_options.extend Compass::SassExtensions::Functions::Sprites::VariableReader + @map = Compass::SpriteMap.new("selectors/*.png", options) + @base = Compass::SassExtensions::Sprites::Base.new(@map.sprite_names.map{|n| "selectors/#{n}.png"}, @map.path, 'selectors', @map.sass_engine, @map.options) + end + + def teardown + FileUtils.rm_r @images_tmp_path + end + + it "should have the correct size" do + assert_equal [10,40], @base.size + end + + it "should have the sprite names" do + assert_equal @map.sprite_names, @base.sprite_names + end + + it 'should have image filenames' do + assert_equal Dir["#{@images_tmp_path}/selectors/*.png"].sort, @base.image_filenames + end + + it 'should need generation' do + assert @base.generation_required? + end + + test 'uniqueness_hash' do + assert_equal 'ef52c5c63a', @base.uniqueness_hash + end + + it 'should be outdated' do + assert @base.outdated? + end + + it 'should have correct filename' do + assert_equal File.join(@images_tmp_path, "#{@base.path}-#{@base.uniqueness_hash}.png"), @base.filename + end + + it "should return the 'ten-by-ten' image" do + assert_equal 'ten-by-ten', @base.image_for('ten-by-ten').name + assert @base.image_for('ten-by-ten').is_a?(Compass::SassExtensions::Sprites::Image) + end + + %w(target hover active).each do |selector| + it "should have a #{selector}" do + assert @base.send(:"has_#{selector}?", 'ten-by-ten') + end + + it "should return #{selector} image class" do + assert_equal "ten-by-ten_#{selector}", @base.image_for('ten-by-ten').send(:"#{selector}").name + end + + end + + it "should generate sprite" do + @base.generate + assert File.exists?(@base.filename) + assert !@base.generation_required? + assert !@base.outdated? + end + +end \ No newline at end of file