-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
test_helper.rb
80 lines (67 loc) · 1.87 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
lib_dir = File.dirname(__FILE__) + '/../lib'
require 'test/unit'
require 'fileutils'
$:.unshift lib_dir unless $:.include?(lib_dir)
require 'sass'
require 'mathn' if ENV['MATHN'] == 'true'
Sass::RAILS_LOADED = true unless defined?(Sass::RAILS_LOADED)
Encoding.default_external = 'UTF-8' if defined?(Encoding)
module Sass::Script::Functions
def option(name)
Sass::Script::String.new(@options[name.value.to_sym].to_s)
end
end
class Test::Unit::TestCase
def munge_filename(opts = {})
return if opts.has_key?(:filename)
opts[:filename] = filename_for_test(opts[:syntax] || :sass)
end
def filename_for_test(syntax = :sass)
test_name = caller.
map {|c| Sass::Util.caller_info(c)[2]}.
compact.
map {|c| c.sub(/^(block|rescue) in /, '')}.
find {|c| c =~ /^test_/}
"#{test_name}_inline.#{syntax}"
end
def clean_up_sassc
path = File.dirname(__FILE__) + "/../.sass-cache"
FileUtils.rm_r(path) if File.exist?(path)
end
def assert_warning(message)
the_real_stderr, $stderr = $stderr, StringIO.new
yield
if message.is_a?(Regexp)
assert_match message, $stderr.string.strip
else
assert_equal message.strip, $stderr.string.strip
end
ensure
$stderr = the_real_stderr
end
def assert_no_warning
the_real_stderr, $stderr = $stderr, StringIO.new
yield
assert_equal '', $stderr.string
ensure
$stderr = the_real_stderr
end
def silence_warnings(&block)
Sass::Util.silence_warnings(&block)
end
def assert_raise_message(klass, message)
yield
rescue Exception => e
assert_instance_of(klass, e)
assert_equal(message, e.message)
else
flunk "Expected exception #{klass}, none raised"
end
def assert_raise_line(line)
yield
rescue Sass::SyntaxError => e
assert_equal(line, e.sass_line)
else
flunk "Expected exception on line #{line}, none raised"
end
end