Skip to content
Newer
Older
100644 71 lines (61 sloc) 1.67 KB
dd81da1 @rkh Add nokogiri helper method. Tilt supports Nokogiri for quite some tim…
rkh authored
1 require File.dirname(__FILE__) + '/helper'
2
3 begin
4 require 'nokogiri'
5
6 class NokogiriTest < Test::Unit::TestCase
7 def nokogiri_app(&block)
8 mock_app do
9 set :views, File.dirname(__FILE__) + '/views'
10 get '/', &block
11 end
12 get '/'
13 end
14
15 it 'renders inline Nokogiri strings' do
16 nokogiri_app { nokogiri 'xml' }
17 assert ok?
fcabf93 @rkh fix tests to pass with latest Nokogiri
rkh authored
18 assert_body %{<?xml version="1.0"?>\n}
dd81da1 @rkh Add nokogiri helper method. Tilt supports Nokogiri for quite some tim…
rkh authored
19 end
20
21 it 'renders inline blocks' do
22 nokogiri_app do
23 @name = "Frank & Mary"
24 nokogiri do |xml|
25 xml.couple @name
26 end
27 end
28 assert ok?
fcabf93 @rkh fix tests to pass with latest Nokogiri
rkh authored
29 assert_body "<?xml version=\"1.0\"?>\n<couple>Frank &amp; Mary</couple>\n"
dd81da1 @rkh Add nokogiri helper method. Tilt supports Nokogiri for quite some tim…
rkh authored
30 end
31
32 it 'renders .nokogiri files in views path' do
33 nokogiri_app do
34 @name = "Blue"
35 nokogiri :hello
36 end
37 assert ok?
fcabf93 @rkh fix tests to pass with latest Nokogiri
rkh authored
38 assert_body %(<?xml version="1.0"?>\n<exclaim>You're my boy, Blue!</exclaim>\n)
dd81da1 @rkh Add nokogiri helper method. Tilt supports Nokogiri for quite some tim…
rkh authored
39 end
40
41 it "renders with inline layouts" do
42 next if Tilt::VERSION <= "1.1"
43 mock_app do
44 layout { %(xml.layout { xml << yield }) }
45 get('/') { nokogiri %(xml.em 'Hello World') }
46 end
47 get '/'
48 assert ok?
fcabf93 @rkh fix tests to pass with latest Nokogiri
rkh authored
49 assert_body "<?xml version=\"1.0\"?>\n<layout>\n <em>Hello World</em>\n</layout>\n"
dd81da1 @rkh Add nokogiri helper method. Tilt supports Nokogiri for quite some tim…
rkh authored
50 end
51
52 it "renders with file layouts" do
53 next if Tilt::VERSION <= "1.1"
54 nokogiri_app do
55 @name = "Blue"
56 nokogiri %(xml.em 'Hello World'), :layout => :layout2
57 end
58 assert ok?
fcabf93 @rkh fix tests to pass with latest Nokogiri
rkh authored
59 assert_body "<?xml version=\"1.0\"?>\n<layout>\n <em>Hello World</em>\n</layout>\n"
dd81da1 @rkh Add nokogiri helper method. Tilt supports Nokogiri for quite some tim…
rkh authored
60 end
61
62 it "raises error if template not found" do
63 mock_app { get('/') { nokogiri :no_such_template } }
64 assert_raise(Errno::ENOENT) { get('/') }
65 end
66 end
e16bc71 Explicitly handle the exception for failed loading.
elij authored
67
68 rescue LoadError
dd81da1 @rkh Add nokogiri helper method. Tilt supports Nokogiri for quite some tim…
rkh authored
69 warn "#{$!.to_s}: skipping nokogiri tests"
70 end
Something went wrong with that request. Please try again.