refactored tests
This commit is contained in:
parent
f1061c474b
commit
c317ef6870
2
Gemfile
2
Gemfile
@ -21,6 +21,8 @@ gem 'autotest-fsevent' if RUBY_PLATFORM =~ /darwin/
|
||||
gem 'fakefs', :git => 'git://github.com/johnbintz/fakefs.git'
|
||||
gem 'mocha'
|
||||
gem 'timecop'
|
||||
gem 'diff-lcs', '~> 1.1.2'
|
||||
|
||||
|
||||
|
||||
|
||||
|
12
Gemfile.lock
12
Gemfile.lock
@ -7,10 +7,10 @@ GIT
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
compass (0.11.1)
|
||||
chunky_png (~> 1.1.1)
|
||||
compass (0.11.1.f1061c4)
|
||||
chunky_png (~> 1.1)
|
||||
fssm (>= 0.2.7)
|
||||
sass (>= 3.1.0.alpha.249)
|
||||
sass (~> 3.1)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
@ -71,7 +71,6 @@ GEM
|
||||
gherkin (2.2.9)
|
||||
json (~> 1.4.6)
|
||||
term-ansicolor (~> 1.0.5)
|
||||
haml (3.1.0)
|
||||
i18n (0.5.0)
|
||||
json (1.4.6)
|
||||
livereload (1.6)
|
||||
@ -120,7 +119,7 @@ GEM
|
||||
ruby-json (1.1.2)
|
||||
ruby-prof (0.10.5)
|
||||
rubyzip (0.9.4)
|
||||
sass (3.1.0.alpha.263)
|
||||
sass (3.1.1)
|
||||
sys-uname (0.8.5)
|
||||
term-ansicolor (1.0.5)
|
||||
thor (0.14.6)
|
||||
@ -139,8 +138,8 @@ DEPENDENCIES
|
||||
compass-validator (= 3.0.0)
|
||||
css_parser (~> 1.0.1)
|
||||
cucumber (~> 0.9.2)
|
||||
diff-lcs (~> 1.1.2)
|
||||
fakefs!
|
||||
haml (~> 3.1.0.alpha)
|
||||
livereload
|
||||
mocha
|
||||
rails (~> 3.0.0.rc)
|
||||
@ -149,5 +148,4 @@ DEPENDENCIES
|
||||
rspec (~> 2.0.0)
|
||||
ruby-prof
|
||||
rubyzip
|
||||
sass (= 3.1.0.alpha.263)
|
||||
timecop
|
||||
|
@ -5,18 +5,14 @@ require 'compass/logger'
|
||||
require 'sass/plugin'
|
||||
|
||||
class CompassTest < Test::Unit::TestCase
|
||||
include Compass::TestCaseHelper
|
||||
|
||||
def setup
|
||||
Compass.reset_configuration!
|
||||
end
|
||||
|
||||
def teardown
|
||||
teardown_fixtures :blueprint, :empty, :compass, :image_urls, :relative
|
||||
end
|
||||
|
||||
def teardown_fixtures(*project_names)
|
||||
project_names.each do |project_name|
|
||||
FileUtils.rm_rf tempfile_path(project_name)
|
||||
[:blueprint, :empty, :compass, :image_urls, :relative].each do |project_name|
|
||||
::FileUtils.rm_rf tempfile_path(project_name)
|
||||
end
|
||||
end
|
||||
|
||||
@ -117,7 +113,11 @@ private
|
||||
expected_lines = expected_lines.split("\n").reject{|l| l=~/\A\Z/}
|
||||
expected_lines.zip(actual_lines).each_with_index do |pair, line|
|
||||
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
|
||||
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')}")
|
||||
|
@ -3,9 +3,12 @@ require 'compass'
|
||||
require 'stringio'
|
||||
|
||||
class ConfigurationTest < Test::Unit::TestCase
|
||||
include Compass::IoHelper
|
||||
|
||||
def setup
|
||||
setup do
|
||||
Compass.reset_configuration!
|
||||
end
|
||||
|
||||
after do
|
||||
Compass.reset_configuration!
|
||||
end
|
||||
|
||||
@ -15,18 +18,23 @@ class ConfigurationTest < Test::Unit::TestCase
|
||||
# Require any additional compass plugins here.
|
||||
|
||||
project_type = :stand_alone
|
||||
|
||||
# Set this to the root of your project when deployed:
|
||||
http_path = "/"
|
||||
css_dir = "css"
|
||||
sass_dir = "sass"
|
||||
images_dir = "img"
|
||||
javascripts_dir = "js"
|
||||
|
||||
output_style = :nested
|
||||
|
||||
# To enable relative paths to assets via compass helper functions. Uncomment:
|
||||
# relative_assets = true
|
||||
|
||||
# To disable debugging comments that display the original location of your selectors. Uncomment:
|
||||
# line_comments = false
|
||||
|
||||
|
||||
# If you prefer the indented syntax, you might want to regenerate this
|
||||
# project again passing --syntax sass, or you can uncomment this:
|
||||
# preferred_syntax = :sass
|
||||
@ -43,7 +51,7 @@ class ConfigurationTest < Test::Unit::TestCase
|
||||
|
||||
expected_lines = contents.string.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
|
||||
|
||||
def test_serialization_warns_with_asset_host_set
|
||||
@ -101,19 +109,23 @@ class ConfigurationTest < Test::Unit::TestCase
|
||||
expected_serialization = <<EXPECTED
|
||||
# Require any additional compass plugins here.
|
||||
project_path = "/home/chris/my_compass_project"
|
||||
|
||||
# Set this to the root of your project when deployed:
|
||||
http_path = "/"
|
||||
css_dir = "css"
|
||||
|
||||
# You can select your preferred output style here (can be overridden via the command line):
|
||||
# output_style = :expanded or :nested or :compact or :compressed
|
||||
|
||||
# To enable relative paths to assets via compass helper functions. Uncomment:
|
||||
# relative_assets = true
|
||||
additional_import_paths = ["../foo", "/path/to/my/framework"]
|
||||
|
||||
# To disable debugging comments that display the original location of your selectors. Uncomment:
|
||||
# line_comments = false
|
||||
EXPECTED
|
||||
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
|
||||
|
||||
def test_config_with_pathname
|
||||
@ -137,19 +149,23 @@ EXPECTED
|
||||
expected_serialization = <<EXPECTED
|
||||
# Require any additional compass plugins here.
|
||||
project_path = "/home/chris/my_compass_project"
|
||||
|
||||
# Set this to the root of your project when deployed:
|
||||
http_path = "/"
|
||||
css_dir = "css"
|
||||
|
||||
# You can select your preferred output style here (can be overridden via the command line):
|
||||
# output_style = :expanded or :nested or :compact or :compressed
|
||||
|
||||
# To enable relative paths to assets via compass helper functions. Uncomment:
|
||||
# relative_assets = true
|
||||
additional_import_paths = ["../foo", "/path/to/my/framework"]
|
||||
|
||||
# To disable debugging comments that display the original location of your selectors. Uncomment:
|
||||
# line_comments = false
|
||||
EXPECTED
|
||||
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
|
||||
|
||||
def test_sass_options
|
||||
@ -164,18 +180,22 @@ EXPECTED
|
||||
|
||||
expected_serialization = <<EXPECTED
|
||||
# Require any additional compass plugins here.
|
||||
|
||||
# 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):
|
||||
# output_style = :expanded or :nested or :compact or :compressed
|
||||
|
||||
# To enable relative paths to assets via compass helper functions. Uncomment:
|
||||
# relative_assets = true
|
||||
sass_options = {:foo=>"bar"}
|
||||
# relative_assets = true\nsass_options = {:foo=>\"bar\"}
|
||||
|
||||
# To disable debugging comments that display the original location of your selectors. Uncomment:
|
||||
# line_comments = false
|
||||
|
||||
EXPECTED
|
||||
|
||||
assert_equal expected_serialization, Compass.configuration.serialize
|
||||
assert_correct(expected_serialization, Compass.configuration.serialize)
|
||||
end
|
||||
|
||||
def test_strip_trailing_directory_separators
|
||||
@ -223,18 +243,24 @@ EXPECTED
|
||||
assert_equal "baz", Compass.configuration.foobar
|
||||
expected_serialization = <<EXPECTED
|
||||
# Require any additional compass plugins here.
|
||||
|
||||
# Set this to the root of your project when deployed:
|
||||
http_path = "/"
|
||||
|
||||
# You can select your preferred output style here (can be overridden via the command line):
|
||||
# output_style = :expanded or :nested or :compact or :compressed
|
||||
|
||||
# To enable relative paths to assets via compass helper functions. Uncomment:
|
||||
# relative_assets = true
|
||||
|
||||
# To disable debugging comments that display the original location of your selectors. Uncomment:
|
||||
# line_comments = false
|
||||
|
||||
|
||||
# this is a foobar
|
||||
foobar = "baz"
|
||||
EXPECTED
|
||||
assert_equal expected_serialization, Compass.configuration.serialize
|
||||
assert_correct(expected_serialization, Compass.configuration.serialize)
|
||||
Compass.reset_configuration!
|
||||
Compass.configuration.environment = :production
|
||||
assert_equal "foo", Compass.configuration.foobar
|
||||
@ -255,5 +281,13 @@ EXPECTED
|
||||
end.compact
|
||||
end
|
||||
|
||||
def assert_correct(before, after)
|
||||
if before == after
|
||||
assert(true)
|
||||
else
|
||||
assert false, diff_as_string(before.inspect, after.inspect)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
1
test/fixtures/stylesheets/relative/config.rb
vendored
1
test/fixtures/stylesheets/relative/config.rb
vendored
@ -6,4 +6,5 @@ javascripts_dir = "assets/javascripts"
|
||||
# Set this to the root of your project when deployed:
|
||||
http_path = "/"
|
||||
# To enable relative paths to assets via compass helper functions. Uncomment:
|
||||
output_style = :compact
|
||||
relative_assets = true
|
||||
|
@ -12,6 +12,7 @@ module Compass
|
||||
# by manipulating the load path.
|
||||
def generate_rails_app(name)
|
||||
if pid = fork
|
||||
puts "HELP I FORKED"
|
||||
Process.wait(pid)
|
||||
if $?.exitstatus == 2
|
||||
raise LoadError, "Couldn't load rails"
|
44
test/helpers/test_case.rb
Normal file
44
test/helpers/test_case.rb
Normal 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
|
@ -5,7 +5,6 @@ require 'compass/exec'
|
||||
require 'timeout'
|
||||
|
||||
class RailsIntegrationTest < Test::Unit::TestCase
|
||||
include Compass::TestCaseHelper
|
||||
include Compass::CommandLineHelper
|
||||
include Compass::IoHelper
|
||||
include Compass::RailsHelper
|
||||
|
@ -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
|
@ -22,7 +22,16 @@ require 'compass'
|
||||
|
||||
require 'test/unit'
|
||||
|
||||
require 'test_case_helper'
|
||||
require 'io_helper'
|
||||
require 'rails_helper'
|
||||
require 'command_line_helper'
|
||||
|
||||
%w(command_line diff io rails test_case).each do |helper|
|
||||
require "helpers/#{helper}"
|
||||
end
|
||||
|
||||
|
||||
class Test::Unit::TestCase
|
||||
include Compass::Diff
|
||||
include Compass::TestCaseHelper
|
||||
include Compass::IoHelper
|
||||
extend Compass::TestCaseHelper::ClassMethods
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user