Skip to content

Commit 7366c26

Browse files
committed
Add test to check that files are recompiled if dependencies and sub dependencies change
1 parent abc6998 commit 7366c26

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

lib/less/rails/import_processor.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ class ImportProcessor
44

55
IMPORT_SCANNER = /@import\s*['"]([^'"]+)['"]\s*;/.freeze
66

7-
PATHNAME_FINDER = Proc.new { |scope, path|
7+
PATHNAME_FINDER = Proc.new do |scope, path|
88
begin
99
scope.resolve(path)
1010
rescue Sprockets::FileNotFound
1111
nil
1212
end
13-
}
13+
end
1414

1515
def initialize(filename, &block)
1616
@filename = filename
@@ -38,7 +38,7 @@ def self.call(input)
3838
def self.depend_on(scope, source, base=File.dirname(scope.logical_path))
3939
import_paths = source.scan(IMPORT_SCANNER).flatten.compact.uniq
4040
import_paths.each do |path|
41-
pathname = PATHNAME_FINDER.call(scope,path) || PATHNAME_FINDER.call(scope, File.join(base, path))
41+
pathname = PATHNAME_FINDER.call(scope, path) || PATHNAME_FINDER.call(scope, File.join(base, path))
4242
scope.depend_on(pathname) if pathname && pathname.to_s.ends_with?('.less')
4343
depend_on scope, File.read(pathname), File.dirname(path) if pathname
4444
end

test/cases/basics_spec.rb

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,54 @@
11
require 'spec_helper'
22

33
class BasicsSpec < Less::Rails::Spec
4-
4+
55
it 'must render variables' do
66
basics.must_match %r{#test-variable\{color:#4d926f\}}
77
end
8-
8+
99
it 'must render mixins' do
1010
basics.must_match %r{#test-mixin span\{border:1px solid black\}}
1111
end
12-
12+
1313
it 'must be able to use vendored less files' do
1414
basics.must_match %r{#test-vendored\{border-radius:10px\}}
1515
end
16-
16+
1717
describe 'less import dependency hooks' do
18-
18+
1919
it 'must update when imported file changes' do
2020
basics.must_match %r{#test-radiused\{border-radius:5px\}}, 'default is 5px'
2121
safely_edit(:mixins) do |data, asset|
22-
data.gsub! '5px', '10px'
22+
data.gsub! '5px', '8px'
2323
File.open(asset.pathname,'w') { |f| f.write(data) }
24-
basics.must_match %r{#test-radiused\{border-radius:10px\}}, 'mixins.less should be a sprockets context dependency'
24+
basics.must_match %r{#test-radiused\{border-radius:8px\}}, 'mixins.less should be a sprockets context dependency'
25+
26+
data.gsub! '8px', '15px'
27+
File.open(asset.pathname,'w') { |f| f.write(data) }
28+
29+
# Force a recompile
30+
# https://github.com/rails/sprockets/blob/master/test/shared_sass_tests.rb#L164
31+
mtime = Time.now + 1
32+
File.utime(mtime, mtime, asset.pathname)
33+
34+
basics.must_match %r{#test-radiused\{border-radius:15px\}}, 'mixins.less should be a sprockets context dependency'
2535
end
2636
end
27-
37+
2838
it 'must update when an imported file of another imported file changes' do
2939
basics.must_match %r{#test-variable-colored\{color:#424242\}}, 'default is #424242'
3040
safely_edit(:variables) do |data, asset|
3141
data.gsub! '424242', '666666'
3242
File.open(asset.pathname,'w') { |f| f.write(data) }
3343
basics.must_match %r{#test-variable-colored\{color:#666\}}, 'variables.less should be a sprockets context dependency'
44+
45+
data.gsub! '666666', '888888'
46+
File.open(asset.pathname,'w') { |f| f.write(data) }
47+
48+
mtime = Time.now + 1
49+
File.utime(mtime, mtime, asset.pathname)
50+
51+
basics.must_match %r{#test-variable-colored\{color:#888\}}, 'variables.less should be a sprockets context dependency'
3452
end
3553
end
3654

@@ -61,15 +79,15 @@ class BasicsSpec < Less::Rails::Spec
6179
end
6280

6381
protected
64-
82+
6583
def basics
6684
dummy_asset 'basics'
6785
end
68-
86+
6987
def mixins_asset
7088
dummy_assets['frameworks/bootstrap/mixins.less']
7189
end
72-
90+
7391
def variables_asset
7492
dummy_assets['frameworks/bootstrap/variables.less']
7593
end

0 commit comments

Comments
 (0)