closes #320 and refactored the rspec tests

This commit is contained in:
Scott Davis 2011-03-29 19:26:11 -04:00
parent 4a5c968739
commit 96f1e4dc96
6 changed files with 47 additions and 32 deletions

View File

@ -7,7 +7,7 @@ GIT
PATH
remote: .
specs:
compass (0.11.beta.5.7571d4a)
compass (0.11.beta.5.4a5c968)
chunky_png (~> 1.1.0)
sass (>= 3.1.0.alpha.249)

View File

@ -38,14 +38,11 @@ module Compass
end
def perform
sprites = Compass::Sprites.new
relative_uri = options[:uri].gsub(/^#{Compass.configuration.images_dir}\//, '')
sprite_images = Compass::Sprites.discover_sprites(relative_uri)
image_names = sprite_images.map{|i| File.basename(i, '.png')}
sprites.path, sprites.name = Compass::Sprites.path_and_name(relative_uri)
sprites = Compass::SpriteMap.new(relative_uri, Compass.sass_engine_options)
options[:output_file] ||= File.join(Compass.configuration.sass_path, "sprites", "_#{sprites.name}.#{Compass.configuration.preferred_syntax}")
options[:skip_overrides] ||= false
contents = sprites.content_for_images(relative_uri, sprites.name, image_names, options[:skip_overrides])
contents = sprites.content_for_images(options[:skip_overrides])
if options[:output_file][-4..-1] != "scss"
contents = Sass::Engine.new(contents, Compass.sass_engine_options.merge(:syntax => :scss)).to_tree.to_sass
end

View File

@ -9,7 +9,7 @@ module Compass
end
def self.discover_sprites(uri)
self.load_map(uri, options).files
self.load_map(uri, {}).files
end
def self.sprite_name(file)

View File

@ -37,13 +37,19 @@ describe Compass::Commands::Sprite do
end
after :each do
clean_up_sprites
FileUtils.rm_r @test_dir if File.exists?(@test_dir)
if File.exists?(@test_dir)
::FileUtils.rm_r @test_dir
end
end
it "should create sprite file" do
puts run_compass_with_options(['sprite', "-f", "stylesheet.scss", "'#{@images_tmp_path}/*.png'"]).inspect
run_compass_with_options(['sprite', "-f", "stylesheet.scss", "'#{@images_tmp_path}/*.png'"]).to_i.should == 0
File.exists?(File.join(test_dir, 'stylesheet.scss')).should be_true
end
it "should fail gracfuly when giving bad arguments" do
pending
end
end

View File

@ -16,8 +16,22 @@ module CompassGlobalInclude
end
end
module CompassSpriteHelpers
def create_sprite_temp
::FileUtils.cp_r @images_src_path, @images_tmp_path
end
def clean_up_sprites
::FileUtils.rm_r @images_tmp_path
end
end
RSpec.configure do |config|
config.include(CompassGlobalInclude)
config.include(CompassSpriteHelpers)
config.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', 'images-tmp')
end
config.mock_with :mocha
end
end

View File

@ -4,16 +4,14 @@ require 'digest/md5'
describe Compass::Sprites do
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', 'images-tmp')
::FileUtils.cp_r @images_src_path, @images_tmp_path
create_sprite_temp
file = StringIO.new("images_path = #{@images_tmp_path.inspect}\n")
Compass.add_configuration(file, "sprite_config")
Compass.configure_sass_plugin!
end
after :each do
FileUtils.rm_r @images_tmp_path
clean_up_sprites
end
def map_location(file)
@ -75,7 +73,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-161c60ad78.png') no-repeat;
background: url('/images/squares-161c60ad78.png') no-repeat;
}
.squares-ten-by-ten {
@ -98,7 +96,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-161c60ad78.png') no-repeat;
background: url('/images/squares-161c60ad78.png') no-repeat;
}
.squares-ten-by-ten {
@ -130,7 +128,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .cubicle, .large-cube {
background: url('/squares-161c60ad78.png') no-repeat;
background: url('/images/squares-161c60ad78.png') no-repeat;
}
.cubicle {
@ -155,7 +153,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.circles {
background: url('/squares-161c60ad78.png') no-repeat;
background: url('/images/squares-161c60ad78.png') no-repeat;
}
CSS
image_size('squares-*.png').should == [20, 30]
@ -169,7 +167,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-89450808af.png') no-repeat;
background: url('/images/squares-89450808af.png') no-repeat;
}
.squares-ten-by-ten {
@ -191,7 +189,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-673837183a.png') no-repeat;
background: url('/images/squares-673837183a.png') no-repeat;
}
.squares-ten-by-ten {
@ -214,7 +212,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-1cd84c9068.png') no-repeat;
background: url('/images/squares-1cd84c9068.png') no-repeat;
}
.squares-ten-by-ten {
@ -237,7 +235,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-f25b7090ca.png') no-repeat;
background: url('/images/squares-f25b7090ca.png') no-repeat;
}
.squares-ten-by-ten {
@ -259,7 +257,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-d66bf24bab.png') no-repeat;
background: url('/images/squares-d66bf24bab.png') no-repeat;
}
.squares-ten-by-ten {
@ -294,7 +292,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite {
background: url('/squares-8e490168dd.png') no-repeat;
background: url('/images/squares-8e490168dd.png') no-repeat;
}
.adjusted-percentage {
@ -332,7 +330,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .adjusted-percentage, .adjusted-px-1, .adjusted-px-2 {
background: url('/squares-8e490168dd.png') no-repeat;
background: url('/images/squares-8e490168dd.png') no-repeat;
}
.adjusted-percentage {
@ -359,7 +357,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-a5550fd132.png') no-repeat;
background: url('/images/squares-a5550fd132.png') no-repeat;
}
.squares-ten-by-ten {
@ -383,7 +381,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.squares-sprite, .squares-ten-by-ten, .squares-twenty-by-twenty {
background: url('/squares-89a274044e.png') no-repeat;
background: url('/images/squares-89a274044e.png') no-repeat;
}
.squares-ten-by-ten {
@ -435,7 +433,7 @@ describe Compass::Sprites do
SCSS
actual_css.should == <<-CSS
.squares {
background: url('/squares-145869726f.png') 0 -10px no-repeat;
background: url('/images/squares-145869726f.png') 0 -10px no-repeat;
}
CSS
end
@ -454,7 +452,7 @@ describe Compass::Sprites do
image_size('squares-*.png').should == [20, 40]
css.should == <<-CSS
.squares-sprite {
background: url('/squares-e3c68372d9.png') no-repeat;
background: url('/images/squares-e3c68372d9.png') no-repeat;
}
.foo {
@ -474,7 +472,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.selectors-sprite, .selectors-ten-by-ten {
background: url('/selectors-edfef809e2.png') no-repeat;
background: url('/images/selectors-edfef809e2.png') no-repeat;
}
.selectors-ten-by-ten {
@ -501,7 +499,7 @@ describe Compass::Sprites do
SCSS
css.should == <<-CSS
.selectors-sprite, a {
background: url('/selectors-edfef809e2.png') no-repeat;
background: url('/images/selectors-edfef809e2.png') no-repeat;
}
a {