Skip to content
Newer
Older
100644 68 lines (57 sloc) 1.74 KB
e001d62 @rkh adjust require lines for test helper, so it also works properly on 1.9.2
rkh authored May 11, 2011
1 require File.expand_path('../helper', __FILE__)
e16bc71 Explicitly handle the exception for failed loading.
elij authored Jan 25, 2011
2
3 begin
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
4 require 'less'
5
6 class LessTest < Test::Unit::TestCase
1d676f4 @rkh Sets default content type according to template engine used instead o…
rkh authored Sep 19, 2010
7 def less_app(options = {}, &block)
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
8 mock_app {
9 set :views, File.dirname(__FILE__) + '/views'
1d676f4 @rkh Sets default content type according to template engine used instead o…
rkh authored Sep 19, 2010
10 set options
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
11 get '/', &block
12 }
13 get '/'
14 end
ceac46f @sr fix whitespace errors
sr authored Mar 1, 2010
15
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
16 it 'renders inline Less strings' do
1d676f4 @rkh Sets default content type according to template engine used instead o…
rkh authored Sep 19, 2010
17 less_app { less "@white_color: #fff; #main { background-color: @white_color }" }
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
18 assert ok?
bcc1d34 @rkh adjust tests for less 2.0
rkh authored Sep 30, 2011
19 assert_body "#main {background-color: #ffffff;}"
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
20 end
ceac46f @sr fix whitespace errors
sr authored Mar 2, 2010
21
1d676f4 @rkh Sets default content type according to template engine used instead o…
rkh authored Sep 19, 2010
22 it 'defaults content type to css' do
23 less_app { less "@white_color: #fff; #main { background-color: @white_color }" }
24 assert ok?
25 assert_equal "text/css;charset=utf-8", response['Content-Type']
26 end
27
28 it 'defaults allows setting content type per route' do
29 less_app do
30 content_type :html
31 less "@white_color: #fff; #main { background-color: @white_color }"
32 end
33 assert ok?
34 assert_equal "text/html;charset=utf-8", response['Content-Type']
35 end
36
37 it 'defaults allows setting content type globally' do
38 less_app(:less => { :content_type => 'html' }) do
39 less "@white_color: #fff; #main { background-color: @white_color }"
40 end
41 assert ok?
42 assert_equal "text/html;charset=utf-8", response['Content-Type']
43 end
44
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
45 it 'renders .less files in views path' do
46 less_app { less :hello }
47 assert ok?
bcc1d34 @rkh adjust tests for less 2.0
rkh authored Sep 30, 2011
48 assert_body "#main {background-color: #ffffff;}"
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
49 end
ceac46f @sr fix whitespace errors
sr authored Mar 2, 2010
50
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
51 it 'ignores the layout option' do
52 less_app { less :hello, :layout => :layout2 }
53 assert ok?
bcc1d34 @rkh adjust tests for less 2.0
rkh authored Sep 30, 2011
54 assert_body "#main {background-color: #ffffff;}"
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
55 end
ceac46f @sr fix whitespace errors
sr authored Mar 2, 2010
56
621bfcb @Ptico Added Less support
Ptico authored Mar 1, 2010
57 it "raises error if template not found" do
58 mock_app {
59 get('/') { less :no_such_template }
60 }
61 assert_raise(Errno::ENOENT) { get('/') }
62 end
63 end
e16bc71 Explicitly handle the exception for failed loading.
elij authored Jan 25, 2011
64
65 rescue LoadError
66 warn "#{$!.to_s}: skipping less tests"
67 end
Something went wrong with that request. Please try again.