-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers_test.rb
125 lines (110 loc) · 3.71 KB
/
helpers_test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require 'shoulda_tests/test_helper'
class HelpersTest < Test::Unit::TestCase
def app
@app = mock_app {
helpers Sinatra::Chicago::Helpers
}
end
context "including stylesheet" do
context "for plain old foo" do
setup do
extend_mock_app {
template(:foo) { "= stylesheet_include('foo')" }
get('/foo') { haml :foo }
}
get '/foo'
end
should_have_response_body %r[^<link( \w+=".+"){4}/>$]
should_have_response_body %r[href="/stylesheets/foo\.css"]
should_have_response_body %r[media="screen"]
should_have_response_body %r[rel="stylesheet"]
should_have_response_body %r[type="text/css"]
end # for plain old foo
context "for bar with options" do
setup do
extend_mock_app {
template(:foo) { "= stylesheet_include('bar', :media => 'print', :baz => 'boo')" }
get('/foo') { haml :foo }
}
get '/foo'
end
should_have_response_body %r[^<link( \w+=".+"){5}/>$]
should_have_response_body %r[href="/stylesheets/bar\.css"]
should_have_response_body %r[media="print"]
should_have_response_body %r[rel="stylesheet"]
should_have_response_body %r[type="text/css"]
should_have_response_body %r[baz="boo"]
end # for bar with options
context "with a specific href" do
setup do
extend_mock_app {
template(:foo) { "= stylesheet_include('http://example.com')" }
get('/foo') { haml :foo }
}
get '/foo'
end
should_have_response_body %r[href="http://example.com"]
end # with a specific href
end # including stylesheets
context "including javascript" do
context "for plain old foo" do
setup do
extend_mock_app {
template(:foo) { "= javascript_include('foo')" }
get('/foo') { haml :foo }
}
get '/foo'
end
should_have_response_body %r[^<script( \w+=".+"){2}></script>$]
should_have_response_body %r[src="/javascripts/foo\.js"]
should_have_response_body %r[type="text/javascript"]
end # for plain old foo
context "for foo with options" do
setup do
extend_mock_app {
template(:foo) { "= javascript_include('foo', :type => 'text/blarg', :gus => 'nice')" }
get('/foo') { haml :foo }
}
get '/foo'
end
should_have_response_body %r[^<script( \w+=".+"){3}></script>$]
should_have_response_body %r[src="/javascripts/foo\.js"]
should_have_response_body %r[type="text/blarg"]
should_have_response_body %r[gus="nice"]
end # for foo with options
context "with a specific src" do
setup do
extend_mock_app {
template(:foo) { "= javascript_include('http://example.com')" }
get('/foo') { haml :foo }
}
get '/foo'
end
should_have_response_body %r[src="http://example.com"]
end # with a specific src
end # including javascript
context "using an anchor" do
context "for plain old foo" do
setup do
extend_mock_app {
template(:foo) { "= anchor('foo', '/bar')" }
get('/foo') { haml :foo }
}
get '/foo'
end
should_have_response_body %Q[<a href="/bar">foo</a>]
end # for plain old foo
context "with options" do
setup do
extend_mock_app {
template(:foo) { "= anchor('foo bear', '/bar/ler', :title => 'gus is nice')" }
get('/foo') { haml :foo }
}
get '/foo'
end
should_have_response_body %r[^<a( \w+=".+"){2}>foo bear</a>$]
should_have_response_body %r[href="/bar/ler"]
should_have_response_body %r[title="gus is nice"]
end # with options
end # using an anchor
end