-
Notifications
You must be signed in to change notification settings - Fork 791
/
Copy pathtest_sass.rb
129 lines (107 loc) · 2.78 KB
/
test_sass.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# frozen_string_literal: true
require 'sprockets_test'
require 'shared_sass_tests'
silence_warnings do
require 'sass'
end
require 'sprockets/sass_processor'
require 'sprockets/sass_compressor'
class TestBaseSass < Sprockets::TestCase
CACHE_PATH = File.expand_path("../../.sass-cache", __FILE__)
def sass
::Sass
end
def sass_functions
::Sass::Script::Functions
end
def sass_engine
::Sass::Engine
end
def compressor
Sprockets::SassCompressor
end
def teardown
refute ::Sass::Script::Functions.instance_methods.include?(:asset_path)
FileUtils.rm_r(CACHE_PATH) if File.exist?(CACHE_PATH)
assert !File.exist?(CACHE_PATH)
end
end
class TestNoSassFunctionSass < TestBaseSass
module ::Sass::Script::Functions
def javascript_path(path)
::Sass::Script::String.new("/js/#{path.value}", :string)
end
module Compass
def stylesheet_path(path)
::Sass::Script::String.new("/css/#{path.value}", :string)
end
end
include Compass
end
include SharedSassTestNoFunction
end
class TestSprocketsSass < TestBaseSass
def setup
super
@env = Sprockets::Environment.new(".") do |env|
env.cache = {}
env.append_path(fixture_path('.'))
env.append_path(fixture_path('compass'))
env.append_path(fixture_path('octicons'))
env.register_transformer 'text/sass', 'text/css', Sprockets::SassProcessor.new
env.register_transformer 'text/scss', 'text/css', Sprockets::ScssProcessor.new
end
end
def teardown
assert !File.exist?(CACHE_PATH)
end
def render(path)
path = fixture_path(path)
silence_warnings do
@env.find_asset(path, accept: 'text/css').to_s
end
end
test "raise sass error with line number" do
begin
::Sass::Util.silence_sass_warnings do
render('sass/error.sass')
end
flunk
rescue Sass::SyntaxError => error
assert error.message.include?("invalid")
trace = error.backtrace[0]
assert trace.include?("error.sass")
assert trace.include?(":5")
end
end
test "track sass dependencies metadata" do
asset = nil
silence_warnings do
asset = @env.find_asset('sass/import_partial.css')
end
assert asset
assert_equal [
fixture_path('sass/_rounded.scss'),
fixture_path('sass/import_partial.sass')
], asset.metadata[:sass_dependencies].to_a.sort
end
include SharedSassTestSprockets
end
class TestSassCompressor < TestBaseSass
include SharedSassTestCompressor
end
class TestSassFunctions < TestSprocketsSass
def setup
super
define_asset_path
end
def define_asset_path
@env.context_class.class_eval do
def asset_path(path, options = {})
link_asset(path)
"/#{path}"
end
end
end
include SharedSassTestFunctions
end