Skip to content

Commit

Permalink
sprite base spec
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdavis committed Mar 23, 2011
1 parent a5e2795 commit 03b0ee2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion lib/compass/sass_extensions/sprites/base.rb
Expand Up @@ -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
Expand Down
45 changes: 34 additions & 11 deletions spec/compass/sass_extensions/sprites/base_spec.rb
Expand Up @@ -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
4 changes: 3 additions & 1 deletion spec/compass/sass_extensions/sprites/image_spec.rb
Expand Up @@ -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 {
Expand Down Expand Up @@ -37,6 +36,7 @@
}

describe '#repeat' do
let(:type) { nil }
let(:get_var_return) { OpenStruct.new(:value => type) }

context 'specific image' do
Expand All @@ -61,6 +61,7 @@
end

describe '#position' do
let(:type) { nil }
let(:get_var_return) { type }

context 'specific image' do
Expand All @@ -85,6 +86,7 @@
end

describe '#spacing' do
let(:type) { nil }
let(:get_var_return) { OpenStruct.new(:value => type) }

context 'specific image' do
Expand Down
4 changes: 3 additions & 1 deletion spec/compass/sprite_map_spec.rb
Expand Up @@ -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

0 comments on commit 03b0ee2

Please sign in to comment.