From c950d874320765ab8645bc4b6935eb57519a4247 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Tue, 26 Jul 2011 16:20:51 -0400 Subject: [PATCH] abstracted out test helpers --- test/test_helper.rb | 15 +++++++++++++++ test/units/sprites/image_test.rb | 2 +- test/units/sprites/importer_test.rb | 4 ++-- test/units/sprites/sprite_command_test.rb | 12 +----------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index a4146cc6..43981842 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -39,6 +39,11 @@ end module SpriteHelper URI = "selectors/*.png" + def init_sprite_helper + @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') + end + def sprite_map_test(options) importer = Compass::SpriteImporter.new path, name = Compass::SpriteImporter.path_and_name(URI) @@ -47,4 +52,14 @@ module SpriteHelper Compass::SassExtensions::Sprites::SpriteMap.new(sprite_names.map{|n| "selectors/#{n}.png"}, path, name, sass_engine, options) end + def create_sprite_temp + init_sprite_helper + ::FileUtils.cp_r @images_src_path, @images_tmp_path + end + + def clean_up_sprites + init_sprite_helper + ::FileUtils.rm_r @images_tmp_path + end + end \ No newline at end of file diff --git a/test/units/sprites/image_test.rb b/test/units/sprites/image_test.rb index afcc0c7c..24b635b1 100644 --- a/test/units/sprites/image_test.rb +++ b/test/units/sprites/image_test.rb @@ -5,7 +5,7 @@ require 'ostruct' class SpritesImageTest < Test::Unit::TestCase include SpriteHelper def setup - @images_src_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images') + create_sprite_temp file = StringIO.new("images_path = #{@images_src_path.inspect}\n") Compass.add_configuration(file, "sprite_config") @repeat = 'no-repeat' diff --git a/test/units/sprites/importer_test.rb b/test/units/sprites/importer_test.rb index f9b0d79d..094a1a0f 100644 --- a/test/units/sprites/importer_test.rb +++ b/test/units/sprites/importer_test.rb @@ -1,10 +1,10 @@ require 'test_helper' require 'timecop' class ImporterTest < Test::Unit::TestCase - URI = "selectors/*.png" + include SpriteHelper def setup - @images_src_path = File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'sprites', 'public', 'images') + create_sprite_temp file = StringIO.new("images_path = #{@images_src_path.inspect}\n") Compass.add_configuration(file, "sprite_config") @importer = Compass::SpriteImporter.new diff --git a/test/units/sprites/sprite_command_test.rb b/test/units/sprites/sprite_command_test.rb index 240b00c3..4e4354fb 100644 --- a/test/units/sprites/sprite_command_test.rb +++ b/test/units/sprites/sprite_command_test.rb @@ -2,10 +2,8 @@ require 'test_helper' class SpriteCommandTest < Test::Unit::TestCase attr_reader :test_dir - + include SpriteHelper 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') @before_dir = ::Dir.pwd create_temp_cli_dir create_sprite_temp @@ -14,14 +12,6 @@ class SpriteCommandTest < Test::Unit::TestCase end end - 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 - def config_data return <<-CONFIG images_path = #{@images_tmp_path.inspect}