This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters_spec.rb
49 lines (37 loc) · 1.48 KB
/
filters_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
require File.dirname(__FILE__) + '/spec_helper.rb'
describe Hpreserve::Filters do
describe "sandbox" do
before { @f = Hpreserve::Filters.create }
# note: #should and #should_not are undefined at initialize and are not available
it "extends with @@filter_modules" do
@f.respond_to?('capitalize').should be_true
end
it "does not respond to or send non-allowed methods" do
lambda { @f.__send__('instance_eval')}.should raise_error(NoMethodError)
end
it "executes filters via the 'run' method" do
@doc = Hpricot('<span>foo</span>')
@f.run('capitalize', @doc.at('span'))
@doc.at('span').inner_html.should == 'Foo'
end
end
describe "filterstring parser" do
it "handles single filters without arguments" do
Hpreserve::Filters.parse('upcase').should == [['upcase']]
end
it "handles multiple filters without arguments" do
Hpreserve::Filters.parse('upcase; downcase').should == [['upcase'], ['downcase']]
end
it "handles single filters with arguments" do
Hpreserve::Filters.parse('truncate: 30, ...').should == [['truncate', '30', '...']]
end
it "handles complex filter directives" do
Hpreserve::Filters.parse(
'truncate: 30, ...; capitalize; link_to: @item.link; add_class: @item.type'
).should == [
['truncate', '30', '...'], ['capitalize'], ['link_to', '@item.link'],
['add_class', '@item.type']
]
end
end
end