2006-11-28 20:33:22 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
require 'test/unit'
|
2006-12-03 23:56:47 +00:00
|
|
|
require File.dirname(__FILE__) + '/../../lib/sass'
|
2006-12-04 02:47:37 +00:00
|
|
|
|
|
|
|
RAILS_ENV = 'testing'
|
|
|
|
|
|
|
|
require 'sass/plugin'
|
2006-11-28 20:33:22 +00:00
|
|
|
|
|
|
|
class SassPluginTest < Test::Unit::TestCase
|
2006-12-22 01:52:45 +00:00
|
|
|
@@templates = %w{ complex constants }
|
2006-12-04 02:47:37 +00:00
|
|
|
|
2006-11-28 20:33:22 +00:00
|
|
|
def setup
|
2007-01-31 04:40:55 +00:00
|
|
|
Sass::Plugin.options = {
|
|
|
|
:template_location => File.dirname(__FILE__) + '/templates',
|
|
|
|
:css_location => File.dirname(__FILE__) + '/tmp',
|
|
|
|
}
|
2007-01-07 04:08:48 +00:00
|
|
|
Sass::Plugin.options[:always_update] = true
|
2006-12-04 02:47:37 +00:00
|
|
|
|
|
|
|
Sass::Plugin.update_stylesheets
|
2006-11-28 20:33:22 +00:00
|
|
|
end
|
2006-12-03 23:17:45 +00:00
|
|
|
|
|
|
|
def teardown
|
2006-12-04 02:47:37 +00:00
|
|
|
File.delete(*Dir[tempfile_loc('*')])
|
2006-12-03 23:17:45 +00:00
|
|
|
end
|
2006-11-28 20:39:33 +00:00
|
|
|
|
2006-12-04 02:47:37 +00:00
|
|
|
def test_templates_should_render_correctly
|
|
|
|
@@templates.each { |name| assert_renders_correctly(name) }
|
2006-11-28 20:39:33 +00:00
|
|
|
end
|
2006-12-04 02:47:37 +00:00
|
|
|
|
2006-11-28 20:39:33 +00:00
|
|
|
def test_no_update
|
2006-12-04 02:47:37 +00:00
|
|
|
File.delete(tempfile_loc('basic'))
|
|
|
|
assert Sass::Plugin.stylesheet_needs_update?('basic')
|
|
|
|
Sass::Plugin.update_stylesheets
|
|
|
|
assert !Sass::Plugin.stylesheet_needs_update?('basic')
|
|
|
|
end
|
|
|
|
|
2006-12-22 06:59:38 +00:00
|
|
|
def test_exception_handling
|
|
|
|
File.open(tempfile_loc('bork')) do |file|
|
2007-01-31 04:30:30 +00:00
|
|
|
assert_equal("Undefined constant: \"!bork\"", file.gets.strip)
|
2006-12-22 06:59:38 +00:00
|
|
|
end
|
|
|
|
File.delete(tempfile_loc('bork'))
|
|
|
|
Sass.const_set('RAILS_ENV', 'production')
|
|
|
|
raised = false
|
|
|
|
begin
|
|
|
|
Sass::Plugin.update_stylesheets
|
|
|
|
rescue
|
|
|
|
raised = true
|
|
|
|
end
|
|
|
|
assert raised
|
|
|
|
assert !File.exists?(tempfile_loc('bork'))
|
|
|
|
Sass::Plugin.const_set('RAILS_ENV', 'testing')
|
2006-12-04 02:47:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_controller_process
|
|
|
|
File.delete(tempfile_loc('basic'))
|
|
|
|
assert Sass::Plugin.stylesheet_needs_update?('basic')
|
|
|
|
|
|
|
|
ActionController::Base.new.process
|
|
|
|
|
|
|
|
assert !Sass::Plugin.stylesheet_needs_update?('basic')
|
2006-11-28 20:39:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2006-12-03 23:17:45 +00:00
|
|
|
|
|
|
|
def assert_renders_correctly(name)
|
2006-12-04 03:55:34 +00:00
|
|
|
File.read(result_loc(name)).split("\n").zip(File.read(tempfile_loc(name)).split("\n")).each_with_index do |pair, line|
|
2006-12-22 05:09:00 +00:00
|
|
|
message = "template: #{name}\nline: #{line + 1}"
|
2006-12-03 23:17:45 +00:00
|
|
|
assert_equal(pair.first, pair.last, message)
|
|
|
|
end
|
|
|
|
end
|
2006-11-28 20:33:22 +00:00
|
|
|
|
2006-12-04 02:47:37 +00:00
|
|
|
def tempfile_loc(name)
|
|
|
|
File.dirname(__FILE__) + "/tmp/#{name}.css"
|
2006-11-28 20:39:33 +00:00
|
|
|
end
|
2006-12-03 23:17:45 +00:00
|
|
|
|
2006-12-04 02:47:37 +00:00
|
|
|
def result_loc(name)
|
|
|
|
File.dirname(__FILE__) + "/results/#{name}.css"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Sass::Plugin
|
|
|
|
class << self
|
|
|
|
public :stylesheet_needs_update?
|
2006-11-28 20:33:22 +00:00
|
|
|
end
|
|
|
|
end
|
2006-12-04 02:47:37 +00:00
|
|
|
|
2006-12-22 06:59:38 +00:00
|
|
|
class Sass::Engine
|
|
|
|
alias_method :old_render, :render
|
|
|
|
|
|
|
|
def render
|
|
|
|
raise "bork bork bork!" if @template[0] == "{bork now!}"
|
|
|
|
old_render
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-12-04 02:47:37 +00:00
|
|
|
class ActionController::Base
|
|
|
|
def sass_old_process(*args); end
|
|
|
|
end
|