Skip to content

Commit

Permalink
Additional specs
Browse files Browse the repository at this point in the history
  • Loading branch information
merbjedi committed Nov 18, 2009
1 parent 3f81658 commit 04dac31
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/sprite/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ def output_file
File.open(path, 'w') do |f|
@output.each do |dest, results|
results.each do |result|
f.puts ".#{result[:name]}"
f.puts ".#{result[:name]} {"
f.puts " background: url('/images/#{dest}') no-repeat #{result[:x]}px #{result[:y]}px;"
f.puts " width: #{result[:width]}px;"
f.puts " height: #{result[:height]}px;"
f.puts ""
f.puts "}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/resources/configs/android_icons.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
config:
style: css
output_path: output/stylesheets/android_cions
output_path: output/stylesheets/android_icons
image_output_path: output/images/sprites/
source_path: resources/images/
class_separator: '_'
Expand Down
17 changes: 16 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
require 'rubygems'
require 'spec/autorun'
require 'date'
require 'fileutils'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "/../lib"))

require 'sprite'

# set Sprite.root to be this spec/ folder
Sprite.module_eval{ @root = File.dirname(__FILE__) }
Sprite.module_eval{ @root = File.dirname(__FILE__) }

Spec::Runner.configure do |config|

module SpriteSpecHelpers
def clear_output
FileUtils.rm_rf("#{Sprite.root}/output")
end
end

config.include(SpriteSpecHelpers)
config.before(:all) do
end

end
29 changes: 26 additions & 3 deletions spec/sprite/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,42 @@
end
end


context "generate android icon sprites" do
before(:all) do
clear_output
@sprite = Sprite::Builder.from_config("resources/configs/android_icons.yml")
@sprite.build
end

it "should generate android.png" do
File.exists?("#{Sprite.root}/output/images/sprites/android_icons.png")
File.exists?("#{Sprite.root}/output/images/sprites/android_icons.png").should be_true
end

it "should generate android_icons.css" do
File.exists?("#{Sprite.root}/output/stylesheets/android_icons.css")
File.exists?("#{Sprite.root}/output/stylesheets/android_icons.css").should be_true
end

context "sprite result image" do
before(:all) do
combiner = Sprite::ImageCombiner.new
@result_image = combiner.get_image("#{Sprite.root}/output/images/sprites/android_icons.png")
@result_properties = combiner.image_properties(@result_image)
end

it "should be 2890x48" do
@result_properties[:width].should == 48
@result_properties[:height].should == 2890
end
end

context "sprite result styles" do
before(:all) do
@styles = File.read("#{Sprite.root}/output/stylesheets/android_icons.css")
end

it "should have some styles in it" do
@styles.should_not be_nil
end
end
end

Expand Down

0 comments on commit 04dac31

Please sign in to comment.