diff --git a/Gemfile.lock b/Gemfile.lock index 85b70cc176..88e6d4920d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT PATH remote: . specs: - compass (0.11.beta.3.6e1daf6) + compass (0.11.beta.3.a5e2795) chunky_png (~> 1.1.0) sass (>= 3.1.0.alpha.249) diff --git a/lib/compass/sass_extensions/sprites/base.rb b/lib/compass/sass_extensions/sprites/base.rb index 18120922d2..8a35b04042 100644 --- a/lib/compass/sass_extensions/sprites/base.rb +++ b/lib/compass/sass_extensions/sprites/base.rb @@ -143,7 +143,10 @@ def image_filenames # Checks whether this sprite is outdated def outdated? - @images.map(&:mtime).any? { |mtime| mtime > self.mtime } + if File.exists?(filename) + return @images.map(&:mtime).any? { |mtime| mtime > self.mtime } + end + true end def mtime diff --git a/spec/compass/sass_extensions/sprites/base_spec.rb b/spec/compass/sass_extensions/sprites/base_spec.rb index 179325e376..413448854b 100644 --- a/spec/compass/sass_extensions/sprites/base_spec.rb +++ b/spec/compass/sass_extensions/sprites/base_spec.rb @@ -3,27 +3,50 @@ before :each do @images_src_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'test_project', 'public', 'images') - @images_tmp_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'test_project', 'public', 'selectors-images-tmp') - #FileUtils.mkdir_p @images_src_path - #FileUtils.mkdir_p @images_tmp_path + @images_tmp_path = File.join(File.dirname(__FILE__), '..', '..', '..', 'test_project', 'public', 'images-tmp') FileUtils.cp_r @images_src_path, @images_tmp_path - file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n") - Compass.add_configuration(file, "sprite_config") + config = Compass::Configuration::Data.new('config') + config.images_path = @images_tmp_path + Compass.add_configuration(config) Compass.configure_sass_plugin! - rels = Dir["#{@images_src_path}/selectors/*.png"].sort.map { |f| f.split('/')[-2..-1].join('/') } - Compass::SassExtensions::Sprites::Base.new(rels, @images_src_path, 'selectors', self, options) + #fix this eww + 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 after :each do FileUtils.rm_r @images_tmp_path end - it "should" do - "foo" - end - + subject { @base } + its(:size) { should == [10,40] } + its(:sprite_names) { should == @map.sprite_names } + its(:image_filenames) { should == Dir["#{@images_tmp_path}/selectors/*.png"].sort } + its(:generation_required?) { should be_true } + its(:uniqueness_hash) { should == 'ef52c5c63a'} + its(:outdated?) { should be_true } + its(:filename) { should == File.join(@images_tmp_path, "#{@base.path}-#{@base.uniqueness_hash}.png")} + it "should return the 'ten-by-ten' image" do + subject.image_for('ten-by-ten').name.should == 'ten-by-ten' + subject.image_for('ten-by-ten').should be_a Compass::SassExtensions::Sprites::Image + end + %w(target hover active).each do |selector| + it "should have a #{selector}" do + subject.send(:"has_#{selector}?", 'ten-by-ten').should be_true + end + end + context "#generate" do + before { @base.generate } + it "should generate sprite" do + File.exists?(@base.filename).should be_true + end + + its(:generation_required?) { should be_false } + its(:outdated?) { should be_false } + end end \ No newline at end of file diff --git a/spec/compass/sass_extensions/sprites/image_spec.rb b/spec/compass/sass_extensions/sprites/image_spec.rb index 7708233f78..5c61e0f618 100644 --- a/spec/compass/sass_extensions/sprites/image_spec.rb +++ b/spec/compass/sass_extensions/sprites/image_spec.rb @@ -7,7 +7,6 @@ let(:sprite_name) { File.basename(sprite_filename, '.png') } let(:image) { self.class.describes.new(nil, File.join(sprite_filename), options)} let(:digest) { Digest::MD5.file(sprite_path).hexdigest } - subject { image } before { @@ -37,6 +36,7 @@ } describe '#repeat' do + let(:type) { nil } let(:get_var_return) { OpenStruct.new(:value => type) } context 'specific image' do @@ -61,6 +61,7 @@ end describe '#position' do + let(:type) { nil } let(:get_var_return) { type } context 'specific image' do @@ -85,6 +86,7 @@ end describe '#spacing' do + let(:type) { nil } let(:get_var_return) { OpenStruct.new(:value => type) } context 'specific image' do diff --git a/spec/compass/sprite_map_spec.rb b/spec/compass/sprite_map_spec.rb index 8df74e4879..b356d1ed4a 100644 --- a/spec/compass/sprite_map_spec.rb +++ b/spec/compass/sprite_map_spec.rb @@ -45,6 +45,8 @@ its(:mtime) { should == mtime } - it "should have a test for the sass engine" + it "should have a test for the sass engine" do + pending 'sass' + end end end