Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 7033 Bytes
- Properties:
- Property svn:executable is set to *
1 | #!/usr/bin/env ruby |
2 | require File.dirname(__FILE__) + '/../test_helper' |
3 | require 'sass/plugin' |
4 | require 'fileutils' |
5 | |
6 | class SassPluginTest < Test::Unit::TestCase |
7 | @@templates = %w{ |
8 | complex script parent_ref import alt |
9 | subdir/subdir subdir/nested_subdir/nested_subdir |
10 | } |
11 | |
12 | def setup |
13 | FileUtils.mkdir tempfile_loc |
14 | FileUtils.mkdir tempfile_loc(nil,"more_") |
15 | set_plugin_opts |
16 | Sass::Plugin.update_stylesheets |
17 | reset_mtimes |
18 | end |
19 | |
20 | def teardown |
21 | clean_up_sassc |
22 | FileUtils.rm_r tempfile_loc |
23 | FileUtils.rm_r tempfile_loc(nil,"more_") |
24 | end |
25 | |
26 | @@templates.each do |name| |
27 | define_method("test_template_renders_correctly (#{name})") do |
28 | assert_renders_correctly(name) |
29 | end |
30 | end |
31 | |
32 | def test_no_update |
33 | File.delete(tempfile_loc('basic')) |
34 | assert_needs_update 'basic' |
35 | Sass::Plugin.update_stylesheets |
36 | assert_stylesheet_updated 'basic' |
37 | end |
38 | |
39 | def test_update_needed_when_modified |
40 | touch 'basic' |
41 | assert_needs_update 'basic' |
42 | Sass::Plugin.update_stylesheets |
43 | assert_stylesheet_updated 'basic' |
44 | end |
45 | |
46 | def test_update_needed_when_dependency_modified |
47 | touch 'basic' |
48 | assert_needs_update 'import' |
49 | Sass::Plugin.update_stylesheets |
50 | assert_stylesheet_updated 'basic' |
51 | end |
52 | |
53 | def test_full_exception_handling |
54 | File.delete(tempfile_loc('bork')) |
55 | Sass::Plugin.update_stylesheets |
56 | File.open(tempfile_loc('bork')) do |file| |
57 | assert_equal("/*\nSass::SyntaxError: Undefined variable: \"!bork\".\non line 2 of #{template_loc('bork')}\n\n1: bork\n2: :bork= !bork", file.read.split("\n")[0...6].join("\n")) |
58 | end |
59 | File.delete(tempfile_loc('bork')) |
60 | end |
61 | |
62 | def test_nonfull_exception_handling |
63 | old_full_exception = Sass::Plugin.options[:full_exception] |
64 | Sass::Plugin.options[:full_exception] = false |
65 | |
66 | File.delete(tempfile_loc('bork')) |
67 | assert_raise(Sass::SyntaxError) {Sass::Plugin.update_stylesheets} |
68 | ensure |
69 | Sass::Plugin.options[:full_exception] = old_full_exception |
70 | end |
71 | |
72 | def test_two_template_directories |
73 | set_plugin_opts :template_location => { |
74 | template_loc => tempfile_loc, |
75 | template_loc(nil,'more_') => tempfile_loc(nil,'more_') |
76 | } |
77 | Sass::Plugin.update_stylesheets |
78 | ['more1', 'more_import'].each { |name| assert_renders_correctly(name, :prefix => 'more_') } |
79 | end |
80 | |
81 | def test_two_template_directories_with_line_annotations |
82 | set_plugin_opts :line_comments => true, |
83 | :style => :nested, |
84 | :template_location => { |
85 | template_loc => tempfile_loc, |
86 | template_loc(nil,'more_') => tempfile_loc(nil,'more_') |
87 | } |
88 | Sass::Plugin.update_stylesheets |
89 | assert_renders_correctly('more1_with_line_comments', 'more1', :prefix => 'more_') |
90 | end |
91 | |
92 | def test_merb_update |
93 | begin |
94 | require 'merb' |
95 | rescue LoadError |
96 | puts "\nmerb couldn't be loaded, skipping a test" |
97 | return |
98 | end |
99 | |
100 | require 'sass/plugin/merb' |
101 | if defined?(MerbHandler) |
102 | MerbHandler.send(:define_method, :process_without_sass) { |*args| } |
103 | else |
104 | Merb::Rack::Application.send(:define_method, :call_without_sass) { |*args| } |
105 | end |
106 | |
107 | set_plugin_opts |
108 | |
109 | File.delete(tempfile_loc('basic')) |
110 | assert_needs_update 'basic' |
111 | |
112 | if defined?(MerbHandler) |
113 | MerbHandler.new('.').process nil, nil |
114 | else |
115 | Merb::Rack::Application.new.call(::Rack::MockRequest.env_for('/')) |
116 | end |
117 | |
118 | assert_stylesheet_updated 'basic' |
119 | end |
120 | |
121 | def test_doesnt_render_partials |
122 | assert !File.exists?(tempfile_loc('_partial')) |
123 | end |
124 | |
125 | ## Regression |
126 | |
127 | def test_cached_dependencies_update |
128 | FileUtils.mv(template_loc("basic"), template_loc("basic", "more_")) |
129 | set_plugin_opts :load_paths => [result_loc, template_loc(nil, "more_")] |
130 | |
131 | touch 'basic', 'more_' |
132 | assert_needs_update "import" |
133 | Sass::Plugin.update_stylesheets |
134 | assert_renders_correctly("import") |
135 | ensure |
136 | FileUtils.mv(template_loc("basic", "more_"), template_loc("basic")) |
137 | end |
138 | |
139 | private |
140 | |
141 | def assert_renders_correctly(*arguments) |
142 | options = arguments.last.is_a?(Hash) ? arguments.pop : {} |
143 | prefix = options[:prefix] |
144 | result_name = arguments.shift |
145 | tempfile_name = arguments.shift || result_name |
146 | expected_lines = File.read(result_loc(result_name, prefix)).split("\n") |
147 | actual_lines = File.read(tempfile_loc(tempfile_name, prefix)).split("\n") |
148 | |
149 | if actual_lines.first == "/*" && expected_lines.first != "/*" |
150 | assert(false, actual_lines[0..actual_lines.enum_with_index.find {|l, i| l == "*/"}.last].join("\n")) |
151 | end |
152 | |
153 | expected_lines.zip(actual_lines).each_with_index do |pair, line| |
154 | message = "template: #{result_name}\nline: #{line + 1}" |
155 | assert_equal(pair.first, pair.last, message) |
156 | end |
157 | if expected_lines.size < actual_lines.size |
158 | assert(false, "#{actual_lines.size - expected_lines.size} Trailing lines found in #{tempfile_name}.css: #{actual_lines[expected_lines.size..-1].join('\n')}") |
159 | end |
160 | end |
161 | |
162 | def assert_stylesheet_updated(name) |
163 | assert_doesnt_need_update name |
164 | |
165 | # Make sure it isn't an exception |
166 | expected_lines = File.read(result_loc(name)).split("\n") |
167 | actual_lines = File.read(tempfile_loc(name)).split("\n") |
168 | if actual_lines.first == "/*" && expected_lines.first != "/*" |
169 | assert(false, actual_lines[0..actual_lines.enum_with_index.find {|l, i| l == "*/"}.last].join("\n")) |
170 | end |
171 | end |
172 | |
173 | def assert_needs_update(name) |
174 | assert(Sass::Plugin.stylesheet_needs_update?(name, template_loc, tempfile_loc), |
175 | "Expected #{template_loc(name)} to need an update.") |
176 | end |
177 | |
178 | def assert_doesnt_need_update(name) |
179 | assert(!Sass::Plugin.stylesheet_needs_update?(name, template_loc, tempfile_loc), |
180 | "Expected #{template_loc(name)} not to need an update.") |
181 | end |
182 | |
183 | def touch(*args) |
184 | FileUtils.touch(template_loc(*args)) |
185 | end |
186 | |
187 | def reset_mtimes |
188 | Dir["{#{template_loc},#{tempfile_loc}}/**/*.{css,sass}"].each {|f| File.utime(Time.now, Time.now - 1, f)} |
189 | end |
190 | |
191 | def template_loc(name = nil, prefix = nil) |
192 | if name |
193 | absolutize "#{prefix}templates/#{name}.sass" |
194 | else |
195 | absolutize "#{prefix}templates" |
196 | end |
197 | end |
198 | |
199 | def tempfile_loc(name = nil, prefix = nil) |
200 | if name |
201 | absolutize "#{prefix}tmp/#{name}.css" |
202 | else |
203 | absolutize "#{prefix}tmp" |
204 | end |
205 | end |
206 | |
207 | def result_loc(name = nil, prefix = nil) |
208 | if name |
209 | absolutize "#{prefix}results/#{name}.css" |
210 | else |
211 | absolutize "#{prefix}results" |
212 | end |
213 | end |
214 | |
215 | def absolutize(file) |
216 | "#{File.dirname(__FILE__)}/#{file}" |
217 | end |
218 | |
219 | def set_plugin_opts(overrides = {}) |
220 | Sass::Plugin.options = { |
221 | :template_location => template_loc, |
222 | :css_location => tempfile_loc, |
223 | :style => :compact, |
224 | :load_paths => [result_loc], |
225 | :always_update => true, |
226 | }.merge(overrides) |
227 | end |
228 | end |
229 | |
230 | module Sass::Plugin |
231 | class << self |
232 | public :stylesheet_needs_update? |
233 | end |
234 | end |
235 | |
236 | class Sass::Engine |
237 | alias_method :old_render, :render |
238 | |
239 | def render |
240 | raise "bork bork bork!" if @template[0] == "{bork now!}" |
241 | old_render |
242 | end |
243 | end |