-
Notifications
You must be signed in to change notification settings - Fork 36
/
tilt_filter_spec.rb
77 lines (63 loc) · 1.98 KB
/
tilt_filter_spec.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
describe "TiltFilter" do
let(:input_files) {
[
MemoryFileWrapper.new("/path/to/input", "foo.erb", "UTF-8", "<%= 'foo' %>\n"),
MemoryFileWrapper.new("/path/to/input", "bar.str", "UTF-8", '#{ "bar" }')
]
}
let(:output_files) {
[
MemoryFileWrapper.new("/path/to/output", "foo.txt", "UTF-8"),
MemoryFileWrapper.new("/path/to/output", "bar.txt", "UTF-8")
]
}
def make_filter(*args)
filter = Rake::Pipeline::Web::Filters::TiltFilter.new(*args) do |input|
input.sub(/\.(erb|str)$/, '.txt')
end
filter.file_wrapper_class = MemoryFileWrapper
filter.input_files = input_files
filter.output_root = "/path/to/output"
filter.rake_application = Rake::Application.new
filter
end
it "generates output" do
filter = make_filter
filter.output_files.should == output_files
tasks = filter.generate_rake_tasks
tasks.each(&:invoke)
file = MemoryFileWrapper.files["/path/to/output/foo.txt"]
file.body.should == "foo"
file.encoding.should == "UTF-8"
file = MemoryFileWrapper.files["/path/to/output/bar.txt"]
file.body.should == "bar"
file.encoding.should == "UTF-8"
end
it "accepts options to pass to the template class" do
# :trim => '' should tell ERB not to trim newlines
filter = make_filter(:trim => '')
tasks = filter.generate_rake_tasks
tasks.each(&:invoke)
file = MemoryFileWrapper.files["/path/to/output/foo.txt"]
file.body.should == "foo\n"
end
describe 'with a rendering context' do
let(:input_files) do
[
MemoryFileWrapper.new("/path/to/input", "foo.erb", "UTF-8", "<%= foo %>"),
]
end
let(:context) do
context = Class.new do
def foo; 'foo'; end
end.new
end
it 'uses the context' do
filter = make_filter({}, context)
tasks = filter.generate_rake_tasks
tasks.each(&:invoke)
file = MemoryFileWrapper.files["/path/to/output/foo.txt"]
file.body.should == "foo"
end
end
end