refactored tests

This commit is contained in:
Scott Davis 2011-04-27 23:18:52 -04:00
parent f1061c474b
commit c317ef6870
12 changed files with 118 additions and 43 deletions

View File

@ -21,6 +21,8 @@ gem 'autotest-fsevent' if RUBY_PLATFORM =~ /darwin/
gem 'fakefs', :git => 'git://github.com/johnbintz/fakefs.git' gem 'fakefs', :git => 'git://github.com/johnbintz/fakefs.git'
gem 'mocha' gem 'mocha'
gem 'timecop' gem 'timecop'
gem 'diff-lcs', '~> 1.1.2'

View File

@ -7,10 +7,10 @@ GIT
PATH PATH
remote: . remote: .
specs: specs:
compass (0.11.1) compass (0.11.1.f1061c4)
chunky_png (~> 1.1.1) chunky_png (~> 1.1)
fssm (>= 0.2.7) fssm (>= 0.2.7)
sass (>= 3.1.0.alpha.249) sass (~> 3.1)
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
@ -71,7 +71,6 @@ GEM
gherkin (2.2.9) gherkin (2.2.9)
json (~> 1.4.6) json (~> 1.4.6)
term-ansicolor (~> 1.0.5) term-ansicolor (~> 1.0.5)
haml (3.1.0)
i18n (0.5.0) i18n (0.5.0)
json (1.4.6) json (1.4.6)
livereload (1.6) livereload (1.6)
@ -120,7 +119,7 @@ GEM
ruby-json (1.1.2) ruby-json (1.1.2)
ruby-prof (0.10.5) ruby-prof (0.10.5)
rubyzip (0.9.4) rubyzip (0.9.4)
sass (3.1.0.alpha.263) sass (3.1.1)
sys-uname (0.8.5) sys-uname (0.8.5)
term-ansicolor (1.0.5) term-ansicolor (1.0.5)
thor (0.14.6) thor (0.14.6)
@ -139,8 +138,8 @@ DEPENDENCIES
compass-validator (= 3.0.0) compass-validator (= 3.0.0)
css_parser (~> 1.0.1) css_parser (~> 1.0.1)
cucumber (~> 0.9.2) cucumber (~> 0.9.2)
diff-lcs (~> 1.1.2)
fakefs! fakefs!
haml (~> 3.1.0.alpha)
livereload livereload
mocha mocha
rails (~> 3.0.0.rc) rails (~> 3.0.0.rc)
@ -149,5 +148,4 @@ DEPENDENCIES
rspec (~> 2.0.0) rspec (~> 2.0.0)
ruby-prof ruby-prof
rubyzip rubyzip
sass (= 3.1.0.alpha.263)
timecop timecop

View File

@ -5,18 +5,14 @@ require 'compass/logger'
require 'sass/plugin' require 'sass/plugin'
class CompassTest < Test::Unit::TestCase class CompassTest < Test::Unit::TestCase
include Compass::TestCaseHelper
def setup def setup
Compass.reset_configuration! Compass.reset_configuration!
end end
def teardown def teardown
teardown_fixtures :blueprint, :empty, :compass, :image_urls, :relative [:blueprint, :empty, :compass, :image_urls, :relative].each do |project_name|
end ::FileUtils.rm_rf tempfile_path(project_name)
def teardown_fixtures(*project_names)
project_names.each do |project_name|
FileUtils.rm_rf tempfile_path(project_name)
end end
end end
@ -117,7 +113,11 @@ private
expected_lines = expected_lines.split("\n").reject{|l| l=~/\A\Z/} expected_lines = expected_lines.split("\n").reject{|l| l=~/\A\Z/}
expected_lines.zip(actual_lines).each_with_index do |pair, line| expected_lines.zip(actual_lines).each_with_index do |pair, line|
message = "template: #{name}\nline: #{line + 1}" message = "template: #{name}\nline: #{line + 1}"
assert_equal(pair.first, pair.last, message) if pair.first == pair.last
assert(true)
else
assert false, diff_as_string(pair.first.inspect, pair.last.inspect)
end
end end
if expected_lines.size < actual_lines.size if expected_lines.size < actual_lines.size
assert(false, "#{actual_lines.size - expected_lines.size} Trailing lines found in #{actual_result_file}.css: #{actual_lines[expected_lines.size..-1].join('\n')}") assert(false, "#{actual_lines.size - expected_lines.size} Trailing lines found in #{actual_result_file}.css: #{actual_lines[expected_lines.size..-1].join('\n')}")

View File

@ -3,9 +3,12 @@ require 'compass'
require 'stringio' require 'stringio'
class ConfigurationTest < Test::Unit::TestCase class ConfigurationTest < Test::Unit::TestCase
include Compass::IoHelper
def setup setup do
Compass.reset_configuration!
end
after do
Compass.reset_configuration! Compass.reset_configuration!
end end
@ -15,18 +18,23 @@ class ConfigurationTest < Test::Unit::TestCase
# Require any additional compass plugins here. # Require any additional compass plugins here.
project_type = :stand_alone project_type = :stand_alone
# Set this to the root of your project when deployed: # Set this to the root of your project when deployed:
http_path = "/" http_path = "/"
css_dir = "css" css_dir = "css"
sass_dir = "sass" sass_dir = "sass"
images_dir = "img" images_dir = "img"
javascripts_dir = "js" javascripts_dir = "js"
output_style = :nested output_style = :nested
# To enable relative paths to assets via compass helper functions. Uncomment: # To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true # relative_assets = true
# To disable debugging comments that display the original location of your selectors. Uncomment: # To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false # line_comments = false
# If you prefer the indented syntax, you might want to regenerate this # If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this: # project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass # preferred_syntax = :sass
@ -43,7 +51,7 @@ class ConfigurationTest < Test::Unit::TestCase
expected_lines = contents.string.split("\n").map{|l|l.strip} expected_lines = contents.string.split("\n").map{|l|l.strip}
actual_lines = Compass.configuration.serialize.split("\n").map{|l|l.strip} actual_lines = Compass.configuration.serialize.split("\n").map{|l|l.strip}
assert_equal expected_lines, actual_lines assert_correct expected_lines, actual_lines
end end
def test_serialization_warns_with_asset_host_set def test_serialization_warns_with_asset_host_set
@ -101,19 +109,23 @@ class ConfigurationTest < Test::Unit::TestCase
expected_serialization = <<EXPECTED expected_serialization = <<EXPECTED
# Require any additional compass plugins here. # Require any additional compass plugins here.
project_path = "/home/chris/my_compass_project" project_path = "/home/chris/my_compass_project"
# Set this to the root of your project when deployed: # Set this to the root of your project when deployed:
http_path = "/" http_path = "/"
css_dir = "css" css_dir = "css"
# You can select your preferred output style here (can be overridden via the command line): # You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed # output_style = :expanded or :nested or :compact or :compressed
# To enable relative paths to assets via compass helper functions. Uncomment: # To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true # relative_assets = true
additional_import_paths = ["../foo", "/path/to/my/framework"] additional_import_paths = ["../foo", "/path/to/my/framework"]
# To disable debugging comments that display the original location of your selectors. Uncomment: # To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false # line_comments = false
EXPECTED EXPECTED
assert_equal "/", Compass.configuration.http_path assert_equal "/", Compass.configuration.http_path
assert_equal expected_serialization.split("\n"), Compass.configuration.serialize.split("\n") assert_correct expected_serialization.split("\n"), Compass.configuration.serialize.split("\n")
end end
def test_config_with_pathname def test_config_with_pathname
@ -137,19 +149,23 @@ EXPECTED
expected_serialization = <<EXPECTED expected_serialization = <<EXPECTED
# Require any additional compass plugins here. # Require any additional compass plugins here.
project_path = "/home/chris/my_compass_project" project_path = "/home/chris/my_compass_project"
# Set this to the root of your project when deployed: # Set this to the root of your project when deployed:
http_path = "/" http_path = "/"
css_dir = "css" css_dir = "css"
# You can select your preferred output style here (can be overridden via the command line): # You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed # output_style = :expanded or :nested or :compact or :compressed
# To enable relative paths to assets via compass helper functions. Uncomment: # To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true # relative_assets = true
additional_import_paths = ["../foo", "/path/to/my/framework"] additional_import_paths = ["../foo", "/path/to/my/framework"]
# To disable debugging comments that display the original location of your selectors. Uncomment: # To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false # line_comments = false
EXPECTED EXPECTED
assert_equal "/", Compass.configuration.http_path assert_equal "/", Compass.configuration.http_path
assert_equal expected_serialization.split("\n"), Compass.configuration.serialize.split("\n") assert_correct expected_serialization.split("\n"), Compass.configuration.serialize.split("\n")
end end
def test_sass_options def test_sass_options
@ -164,18 +180,22 @@ EXPECTED
expected_serialization = <<EXPECTED expected_serialization = <<EXPECTED
# Require any additional compass plugins here. # Require any additional compass plugins here.
# Set this to the root of your project when deployed: # Set this to the root of your project when deployed:
http_path = "/" http_path = \"/\"
# You can select your preferred output style here (can be overridden via the command line): # You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed # output_style = :expanded or :nested or :compact or :compressed
# To enable relative paths to assets via compass helper functions. Uncomment: # To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true # relative_assets = true\nsass_options = {:foo=>\"bar\"}
sass_options = {:foo=>"bar"}
# To disable debugging comments that display the original location of your selectors. Uncomment: # To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false # line_comments = false
EXPECTED EXPECTED
assert_equal expected_serialization, Compass.configuration.serialize assert_correct(expected_serialization, Compass.configuration.serialize)
end end
def test_strip_trailing_directory_separators def test_strip_trailing_directory_separators
@ -223,18 +243,24 @@ EXPECTED
assert_equal "baz", Compass.configuration.foobar assert_equal "baz", Compass.configuration.foobar
expected_serialization = <<EXPECTED expected_serialization = <<EXPECTED
# Require any additional compass plugins here. # Require any additional compass plugins here.
# Set this to the root of your project when deployed: # Set this to the root of your project when deployed:
http_path = "/" http_path = "/"
# You can select your preferred output style here (can be overridden via the command line): # You can select your preferred output style here (can be overridden via the command line):
# output_style = :expanded or :nested or :compact or :compressed # output_style = :expanded or :nested or :compact or :compressed
# To enable relative paths to assets via compass helper functions. Uncomment: # To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true # relative_assets = true
# To disable debugging comments that display the original location of your selectors. Uncomment: # To disable debugging comments that display the original location of your selectors. Uncomment:
# line_comments = false # line_comments = false
# this is a foobar # this is a foobar
foobar = "baz" foobar = "baz"
EXPECTED EXPECTED
assert_equal expected_serialization, Compass.configuration.serialize assert_correct(expected_serialization, Compass.configuration.serialize)
Compass.reset_configuration! Compass.reset_configuration!
Compass.configuration.environment = :production Compass.configuration.environment = :production
assert_equal "foo", Compass.configuration.foobar assert_equal "foo", Compass.configuration.foobar
@ -255,5 +281,13 @@ EXPECTED
end.compact end.compact
end end
def assert_correct(before, after)
if before == after
assert(true)
else
assert false, diff_as_string(before.inspect, after.inspect)
end
end
end end

View File

@ -6,4 +6,5 @@ javascripts_dir = "assets/javascripts"
# Set this to the root of your project when deployed: # Set this to the root of your project when deployed:
http_path = "/" http_path = "/"
# To enable relative paths to assets via compass helper functions. Uncomment: # To enable relative paths to assets via compass helper functions. Uncomment:
output_style = :compact
relative_assets = true relative_assets = true

View File

@ -12,6 +12,7 @@ module Compass
# by manipulating the load path. # by manipulating the load path.
def generate_rails_app(name) def generate_rails_app(name)
if pid = fork if pid = fork
puts "HELP I FORKED"
Process.wait(pid) Process.wait(pid)
if $?.exitstatus == 2 if $?.exitstatus == 2
raise LoadError, "Couldn't load rails" raise LoadError, "Couldn't load rails"

44
test/helpers/test_case.rb Normal file
View File

@ -0,0 +1,44 @@
module Compass
module TestCaseHelper
def absolutize(path)
if Compass::Util.blank?(path)
File.expand_path('../../', __FILE__)
elsif path[0] == ?/
File.join(File.expand_path('../', __FILE__), path)
else
File.join(File.expand_path('../../', __FILE__), path)
end
end
module ClassMethods
def it(name, &block)
test(name, &block)
end
def test(name, &block)
define_method "test_#{underscore(name)}".to_sym, &block
end
def setup(&block)
define_method :setup do
yield
super
end
end
def after(&block)
define_method :teardown do
yield
super
end
end
private
def underscore(string)
string.gsub(' ', '_')
end
end
end
end

View File

@ -5,7 +5,6 @@ require 'compass/exec'
require 'timeout' require 'timeout'
class RailsIntegrationTest < Test::Unit::TestCase class RailsIntegrationTest < Test::Unit::TestCase
include Compass::TestCaseHelper
include Compass::CommandLineHelper include Compass::CommandLineHelper
include Compass::IoHelper include Compass::IoHelper
include Compass::RailsHelper include Compass::RailsHelper

View File

@ -1,13 +0,0 @@
module Compass
module TestCaseHelper
def absolutize(path)
if Compass::Util.blank?(path)
File.dirname(__FILE__)
elsif path[0] == ?/
"#{File.dirname(__FILE__)}#{path}"
else
"#{File.dirname(__FILE__)}/#{path}"
end
end
end
end

View File

@ -22,7 +22,16 @@ require 'compass'
require 'test/unit' require 'test/unit'
require 'test_case_helper'
require 'io_helper' %w(command_line diff io rails test_case).each do |helper|
require 'rails_helper' require "helpers/#{helper}"
require 'command_line_helper' end
class Test::Unit::TestCase
include Compass::Diff
include Compass::TestCaseHelper
include Compass::IoHelper
extend Compass::TestCaseHelper::ClassMethods
end