sinatra-tests 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,342 @@
1
+
2
+
3
+ module Sinatra
4
+ module Tests
5
+
6
+ module RSpec
7
+
8
+ # == Shared Specs
9
+ #
10
+ # === DEBUG
11
+ #
12
+ # * <b><tt>it_should_behave_like "debug => app.methods"</tt></b>
13
+ #
14
+ # dumps a list of methods for the current <tt>app</tt>
15
+ #
16
+ # * <b><tt>it_should_behave_like "debug"</tt></b>
17
+ #
18
+ # tests the body output for a <tt><debug></tt> tag.
19
+ #
20
+ #
21
+ # === RESPONSE
22
+ #
23
+ # * <b><tt>it_should_behave_like "HTTP headers"</tt></b>
24
+ #
25
+ # checks that we got a 200 status (OK), and content-type is <tt>text/html</tt>
26
+ #
27
+ # * <b><tt>it_should_behave_like "HTML"</tt></b>
28
+ #
29
+ # checks that we got a 200 status (OK), and content-type is <tt>text/html</tt>
30
+ #
31
+ # * <b><tt>it_should_behave_like "CSS"</tt></b>
32
+ #
33
+ # checks that we got a 200 status (OK), and content-type is <tt>text/css</tt>
34
+ #
35
+ #
36
+ # === HTML OUTPUT
37
+ #
38
+ # * <b><tt>it_should_behave_like "div#main-content"</tt></b>
39
+ #
40
+ # checks that the page has a <tt><div id="main-content"></div></tt>
41
+ #
42
+ # * <b><tt>it_should_behave_like "div#main-content > h2"</tt></b>
43
+ #
44
+ # checks that the page has an <tt><h2></tt> tag within the <tt><div id="main-content"></div></tt>
45
+ #
46
+ #
47
+ # ==== ADMIN SECTION
48
+ #
49
+ # * <b><tt>it_should_behave_like "div.admin-section-header > div.actions > h4 with HELP"</tt></b>
50
+ #
51
+ # checks that the page has an...
52
+ #
53
+ #
54
+ # ==== FORMS
55
+ #
56
+ # * <b><tt>it_should_behave_like "forms > faux method > input.hidden"</tt></b>
57
+ #
58
+ # checks that the page has a form with a <tt><input type="hidden"...></tt> tag
59
+ #
60
+ module SharedSpecs
61
+
62
+ include Sinatra::Tests::RSpec::Matchers
63
+
64
+ # :stopdoc:
65
+
66
+ share_examples_for 'MyTestApp' do
67
+
68
+ before(:each) do
69
+ class ::Test::Unit::TestCase
70
+ def app; ::MyTestApp.new ; end
71
+ end
72
+ @app = app
73
+ end
74
+
75
+ after(:each) do
76
+ class ::Test::Unit::TestCase
77
+ def app; nil ; end
78
+ end
79
+ @app = nil
80
+ end
81
+
82
+ describe "Sanity" do
83
+
84
+ it "should be a MyTestApp kind of app" do
85
+ # FIXME:: HACK to prevent errors due to stupid Rack::CommonLogger error, when testing.
86
+ unless app.class == MyTestApp
87
+ pending "app.class returns [#{app.class}]"
88
+ else
89
+ app.class.should == MyTestApp
90
+ end
91
+ end
92
+
93
+ # it_should_behave_like "debug => app.methods"
94
+
95
+ end #/ Sanity
96
+
97
+ end
98
+
99
+ share_examples_for 'MyAdminTestApp' do
100
+
101
+ before(:each) do
102
+ class ::Test::Unit::TestCase
103
+ def app; ::MyAdminTestApp.new ; end
104
+ end
105
+ @app = app
106
+ end
107
+
108
+ after(:each) do
109
+ class ::Test::Unit::TestCase
110
+ def app; nil ; end
111
+ end
112
+ @app = nil
113
+ end
114
+
115
+ describe "Sanity" do
116
+
117
+ it "should be a MyAdminTestApp kind of app" do
118
+ # FIXME:: HACK to prevent errors due to stupid Rack::CommonLogger error, when testing.
119
+ unless app.class == MyAdminTestApp
120
+ pending "app.class returns [#{app.class}]"
121
+ else
122
+ app.class.should == MyAdminTestApp
123
+ end
124
+ end
125
+
126
+ # it_should_behave_like "debug => app.methods"
127
+
128
+ end #/ Sanity
129
+
130
+ end
131
+
132
+ # :startdoc:
133
+
134
+ # it_should_behave_like "debug => app.methods"
135
+ #
136
+ share_examples_for "debug => app.methods" do
137
+ it "app should have the right methods" do
138
+ app.methods.sort.should == 'debug => app.methods.sort'
139
+ end
140
+ end
141
+
142
+ share_examples_for "debug" do
143
+
144
+ it "should output the whole html" do
145
+ body.should have_tag('debug')
146
+ end
147
+
148
+ end #/debug
149
+
150
+ share_examples_for "HTTP headers" do
151
+
152
+ it "should return status: 200" do
153
+ assert response.ok?
154
+ end
155
+
156
+ it "should return 'text/html'" do
157
+ response.headers['Content-Type'].should == 'text/html'
158
+ # assert_equal('text/html', last_response.headers['Content-Type'])
159
+ end
160
+
161
+ end #/headers
162
+
163
+ share_examples_for "HTML" do
164
+
165
+ it "should return status: 200" do
166
+ assert response.ok?
167
+ end
168
+
169
+ it "should return 'text/html'" do
170
+ response.headers['Content-Type'].should == 'text/html'
171
+ end
172
+
173
+ end #/HTML
174
+
175
+ share_examples_for "CSS" do
176
+
177
+ it "should return status: 200" do
178
+ assert response.ok?
179
+ end
180
+
181
+ it "should return 'text/css'" do
182
+ response.headers['Content-Type'].should == 'text/css'
183
+ end
184
+
185
+ end #/HTML
186
+
187
+
188
+ ###### HTML OUTPUT #######
189
+
190
+ share_examples_for 'div#main-content' do
191
+ it "should have a div#main-content tag" do
192
+ body.should have_tag('div#main-content')
193
+ end
194
+ end #/div
195
+
196
+ share_examples_for 'div#main-content > h2' do
197
+ it "should have a div#main-content h2 tag" do
198
+ body.should have_tag('div#main-content > h2', :count => 1)
199
+ end
200
+ end #/share_examples_for
201
+
202
+
203
+ ###### ADMIN SECTIONS #######
204
+
205
+ share_examples_for 'div.admin-section-header > div.actions > h4 with HELP' do
206
+ it "should have div.admin-section-header > div.actions > h4 with HELP" do
207
+ body.should have_tag('div.admin-section-header > div.actions > h4') do |h4|
208
+ h4.inner_text.should match(/\s*HELP$/)
209
+ end
210
+ end
211
+ end
212
+
213
+
214
+ ###### FORMS ########
215
+
216
+ # share_examples_for 'forms > faux method > input.hidden[@value=put|delete]' do
217
+ share_examples_for 'forms > faux method > input.hidden' do
218
+ it "should have a faux method input hidden with method = PUT or DELETE" do
219
+ body.should match(/<input (name="_method"\s*|type="hidden"\s*|value="(put|delete)"\s*){3}>/)
220
+ end
221
+ end
222
+
223
+
224
+ ###### CSS ########
225
+
226
+ share_examples_for 'get_all_css_requests("/css")' do
227
+
228
+ it_should_behave_like "CSS [screen, print]"
229
+
230
+ it_should_behave_like "CSS [ie]"
231
+
232
+ end
233
+
234
+ share_examples_for 'get_all_css_requests("/css") (NO IE)' do
235
+
236
+ it_should_behave_like "CSS [screen, print]"
237
+
238
+ end
239
+
240
+ share_examples_for 'CSS [screen, print]' do
241
+
242
+ describe "CSS - GET /css/screen.css" do
243
+
244
+ before(:each) do
245
+ get("/css/screen.css")
246
+ end
247
+
248
+ it "should return status: 200" do
249
+ assert response.ok?
250
+ end
251
+
252
+ it "should return 'text/css'" do
253
+ # response.headers['Content-Type'].should == 'text/css;charset=utf-8'
254
+ response.headers['Content-Type'].should == 'text/css'
255
+ end
256
+
257
+ describe "the CSS" do
258
+
259
+ # it_should_behave_like "debug"
260
+
261
+ it "should NOT have a Sass::SyntaxError" do
262
+ body.should_not match(/Sass::SyntaxError/)
263
+ end
264
+
265
+ # TODO:: Need to write further tests here
266
+ # it "should have further tests"
267
+
268
+ end #/ the CSS
269
+
270
+ end #/CSS - GET /css/screen.css
271
+
272
+ describe "CSS - GET /css/print.css" do
273
+
274
+ before(:each) do
275
+ get("/css/print.css")
276
+ end
277
+
278
+ it "should return status: 200" do
279
+ assert response.ok?
280
+ end
281
+
282
+ it "should return 'text/css'" do
283
+ # response.headers['Content-Type'].should == 'text/css;charset=utf-8'
284
+ response.headers['Content-Type'].should == 'text/css'
285
+ end
286
+
287
+ describe "the CSS" do
288
+
289
+ # it_should_behave_like "debug"
290
+
291
+ it "should NOT have a Sass::SyntaxError" do
292
+ body.should_not match(/Sass::SyntaxError/)
293
+ end
294
+
295
+ # TODO:: Need to write further tests here
296
+ # it "should have further tests"
297
+
298
+ end #/ the CSS
299
+
300
+ end #/CSS - GET /css/print.css
301
+
302
+ end
303
+
304
+ share_examples_for 'CSS [ie]' do
305
+
306
+ describe "CSS - GET /css/ie.css" do
307
+
308
+ before(:each) do
309
+ get("/css/ie.css")
310
+ end
311
+
312
+ it "should return status: 200" do
313
+ assert response.ok?
314
+ end
315
+
316
+ it "should return 'text/css'" do
317
+ # response.headers['Content-Type'].should == 'text/css;charset=utf-8' # tilt version
318
+ response.headers['Content-Type'].should == 'text/css'
319
+ end
320
+
321
+ describe "the CSS" do
322
+
323
+ # it_should_behave_like "debug"
324
+
325
+ it "should NOT have a Sass::SyntaxError" do
326
+ body.should_not match(/Sass::SyntaxError/)
327
+ end
328
+
329
+ # TODO:: Need to write further tests here
330
+ # it "should have further tests"
331
+
332
+ end #/ the CSS
333
+
334
+ end #/CSS - GET /css/print.css
335
+
336
+ end
337
+
338
+
339
+ end #/module SharedSpecs
340
+ end #/module RSpec
341
+ end #/module Tests
342
+ end #/module Sinatra
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra-tests}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kematzy"]
12
- s.date = %q{2009-10-15}
12
+ s.date = %q{2010-02-23}
13
13
  s.email = %q{kematzy@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -23,20 +23,24 @@ Gem::Specification.new do |s|
23
23
  "Rakefile",
24
24
  "VERSION",
25
25
  "lib/sinatra/tests.rb",
26
- "lib/sinatra/tests/init.rb",
27
- "lib/sinatra/tests/shared_specs.rb",
26
+ "lib/sinatra/tests/rspec/matchers.rb",
27
+ "lib/sinatra/tests/rspec/shared_specs.rb",
28
28
  "lib/sinatra/tests/test_case.rb",
29
29
  "sinatra-tests.gemspec",
30
+ "spec/sinatra/tests/rspec/matchers_spec.rb",
30
31
  "spec/sinatra/tests/test_case_spec.rb",
32
+ "spec/sinatra/tests/tests_spec.rb",
31
33
  "spec/spec_helper.rb"
32
34
  ]
33
35
  s.homepage = %q{http://github.com/kematzy/sinatra-tests}
34
36
  s.rdoc_options = ["--charset=UTF-8"]
35
37
  s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.3.5}
38
+ s.rubygems_version = %q{1.3.6}
37
39
  s.summary = %q{Sinatra::Tests is a repository of common Test/RSpec helpers}
38
40
  s.test_files = [
39
- "spec/sinatra/tests/test_case_spec.rb",
41
+ "spec/sinatra/tests/rspec/matchers_spec.rb",
42
+ "spec/sinatra/tests/test_case_spec.rb",
43
+ "spec/sinatra/tests/tests_spec.rb",
40
44
  "spec/spec_helper.rb"
41
45
  ]
42
46
 
@@ -46,19 +50,20 @@ Gem::Specification.new do |s|
46
50
 
47
51
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
48
52
  s.add_runtime_dependency(%q<sinatra>, [">= 0.10.1"])
49
- s.add_runtime_dependency(%q<rack-test>, [">= 0.4.1"])
50
- s.add_runtime_dependency(%q<rspec>, [">= 1.2.8"])
51
- s.add_runtime_dependency(%q<rspec_hpricot_matchers>, [">= 1.0.0"])
53
+ s.add_runtime_dependency(%q<rack-test>, [">= 0.5.3"])
54
+ s.add_runtime_dependency(%q<rspec>, [">= 1.3.0"])
55
+ s.add_runtime_dependency(%q<rspec_hpricot_matchers>, [">= 1.0"])
52
56
  else
53
57
  s.add_dependency(%q<sinatra>, [">= 0.10.1"])
54
- s.add_dependency(%q<rack-test>, [">= 0.4.1"])
55
- s.add_dependency(%q<rspec>, [">= 1.2.8"])
56
- s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0.0"])
58
+ s.add_dependency(%q<rack-test>, [">= 0.5.3"])
59
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
60
+ s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0"])
57
61
  end
58
62
  else
59
63
  s.add_dependency(%q<sinatra>, [">= 0.10.1"])
60
- s.add_dependency(%q<rack-test>, [">= 0.4.1"])
61
- s.add_dependency(%q<rspec>, [">= 1.2.8"])
62
- s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0.0"])
64
+ s.add_dependency(%q<rack-test>, [">= 0.5.3"])
65
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
66
+ s.add_dependency(%q<rspec_hpricot_matchers>, [">= 1.0"])
63
67
  end
64
68
  end
69
+
@@ -0,0 +1,274 @@
1
+
2
+ require "#{File.dirname(File.dirname(File.expand_path(__FILE__)))}/../../spec_helper"
3
+
4
+
5
+ describe "Sinatra" do
6
+
7
+ it_should_behave_like "MyTestApp"
8
+
9
+ describe "Tests" do
10
+
11
+ describe "RSpec" do
12
+
13
+ describe "Matchers" do
14
+
15
+ describe "#be_even" do
16
+
17
+ it "should return true when even" do
18
+ 1.should_not be_even
19
+ 2.should be_even
20
+ end
21
+
22
+ it "should raise an Exception when not even" do
23
+ lambda { 1.should be_even }.should raise_error(Exception, /"an even number" but got 1/)
24
+ end
25
+
26
+ end #/ #be_even
27
+
28
+ describe "#have_a_page_title" do
29
+
30
+ it "should return true when there is a page title" do
31
+ erb_app "<head><title>It works</title></head>"
32
+ body.should have_a_page_title('It works')
33
+ erb_app "<head><title>Home | Default Site Title</title></head>"
34
+ body.should have_a_page_title('Home | Default Site Title')
35
+ end
36
+
37
+ it "should raise an Exception when the searched for page title contains entities" do
38
+ lambda {
39
+ erb_app "<head><title>Home &amp; Default Site Title</title></head>"
40
+ body.should have_a_page_title('Home &amp; Default Site Title')
41
+ }.should raise_error(Exception)
42
+ end
43
+
44
+ it "should NOT raise an Exception when the searched for page title contains decoded entities" do
45
+ lambda {
46
+ erb_app "<head><title>Home &amp; Default Site Title</title></head>"
47
+ body.should have_a_page_title('Home & Default Site Title')
48
+ }.should_not raise_error(Exception)
49
+
50
+ end
51
+
52
+ it "should raise an Exception when the page titles are NOT the same" do
53
+ erb_app "<head><title>It still works</title></head>"
54
+ lambda {
55
+ body.should have_a_page_title('It works')
56
+ }.should raise_error(Exception)
57
+ end
58
+
59
+ it "should return true when the page title is empty" do
60
+ erb_app "<head><title></title></head>"
61
+ body.should have_a_page_title('')
62
+ end
63
+
64
+ it "should return true when given a RegExp that matches " do
65
+ erb_app "<head><title>It works</title></head>"
66
+ body.should have_a_page_title(/^It /)
67
+ end
68
+
69
+ it "should raise an Exception when given a RegExp that does NOT match" do
70
+ erb_app "<head><title>It works</title></head>"
71
+ lambda {
72
+ body.should have_a_page_title(/^It does not match/)
73
+ }.should raise_error(Exception, /<head><title>It works<\/title><\/head>\nto have an element matching "head > title" with inner text \/\^It does not match\/, but found 0/m)
74
+ end
75
+
76
+ it "should raise an Exception when there is no <head> elment" do
77
+ erb_app "<title>It works</title>"
78
+ lambda {
79
+ body.should have_a_page_title(/^It works/)
80
+ }.should raise_error(Exception, /<title>It works<\/title>\nto have an element matching "head > title" with inner text \/\^It works\/, but did not/m)
81
+ end
82
+
83
+ end #/ #have_a_page_title
84
+
85
+ describe "#have_a_page_header" do
86
+
87
+ it "should return true when there is a page header" do
88
+ erb_app "<%= '<h2>Page Header</h2>' %>"
89
+ body.should have_a_page_header('Page Header')
90
+ erb_app "<%= '<h2 class=\"page-header\">Page Header</h2>' %>"
91
+ body.should have_a_page_header('Page Header')
92
+ end
93
+
94
+ it "should raise an error when the page headers are NOT the same" do
95
+ erb_app "<%= '<h2>Page Header</h2>' %>"
96
+ lambda {
97
+ body.should have_a_page_header('Different Page Header')
98
+ }.should raise_error(Exception)
99
+ end
100
+
101
+ it "should return true when the page header is empty" do
102
+ erb_app "<h2></h2>"
103
+ body.should have_a_page_header('')
104
+ end
105
+
106
+ it "should return true when given a RegExp that matches " do
107
+ erb_app "<h2>Page Header</h2>"
108
+ body.should have_a_page_header(/^Page /)
109
+ end
110
+
111
+ it "should raise an Exception when given a RegExp that does NOT match" do
112
+ erb_app "<h2>Page Header</h2>"
113
+ lambda {
114
+ body.should have_a_page_header(/^Different Page Header/)
115
+ }.should raise_error(Exception, /<h2>Page Header<\/h2>\nto have 1 elements matching "h2" with inner text \/\^Different Page Header\/, but found 0/m)
116
+ end
117
+
118
+ it "should accept dynamic page headers" do
119
+ erb_app "<%= '<h1>Page Header</h1>' %>"
120
+ body.should have_a_page_header('Page Header','h1')
121
+ erb_app "<%= '<div id=\"main-content\"><h2>Page Header</h2></div>' %>"
122
+ body.should have_a_page_header('Page Header','div#main-content > h2')
123
+ erb_app "<%= '<span class=\"page-header\">Page Header</span>' %>"
124
+ body.should have_a_page_header('Page Header','span.page-header')
125
+ end
126
+
127
+ it "should raise an Exception when there are more than one page header" do
128
+ erb_app "<h2>Page Header1</h2><h2>Page Header2</h2><h2>Page Header3</h2>"
129
+ lambda {
130
+ body.should have_a_page_header(/^Page Header/)
131
+ }.should raise_error(Exception, /<h2>Page Header1<\/h2><h2>Page Header2<\/h2><h2>Page Header3<\/h2>\nto have 1 elements matching "h2" with inner text \/\^Page Header\/, but found 3/m)
132
+
133
+ end
134
+
135
+ end #/ #have_a_page_header
136
+
137
+ describe "#have_a_td_actions" do
138
+
139
+ before(:each) do
140
+ @html = %Q[
141
+ <table id="posts-table">
142
+ <tbody>
143
+ <tr>
144
+ <td id="post-actions-98" class="actions">
145
+ <a href="/posts/98/edit" class="ui-btn edit-link" title="edit post">EDIT</a> |
146
+ <a href="/posts/98" class="ui-btn delete-link" title="delete post">DELETE</a>
147
+ </td>
148
+ </tr>
149
+ <tr>
150
+ <td id="post-actions-99" class="actions">
151
+ <a href="/posts/99/edit" class="ui-btn edit-link" title="edit post">EDIT</a> |
152
+ <a href="/posts/99" class="ui-btn delete-link" title="delete post">DELETE</a>
153
+ </td>
154
+ </tr>
155
+ </tbody>
156
+ </table>]
157
+
158
+ end
159
+
160
+ it "should return true when looking for a simple model only" do
161
+ erb_app @html
162
+ # body.should have_tag(:debug)
163
+ body.should have_a_td_actions(:post)
164
+ end
165
+
166
+ it "should return true when providing a buttons array" do
167
+ erb_app @html
168
+ # body.should have_tag(:debug)
169
+ body.should have_a_td_actions(:post, %w(edit))
170
+ end
171
+
172
+ it "should raise an Exception when asking for buttons that are NOT present" do
173
+ lambda {
174
+ erb_app @html
175
+ # body.should have_tag(:debug)
176
+ body.should have_a_td_actions(:post,%w(delete edit show))
177
+ }.should raise_error(Exception)
178
+ end
179
+
180
+ it "should have more tests here...."
181
+
182
+ end #/ #have_a_td_actions
183
+
184
+ describe "#have_a_ui_btn" do
185
+
186
+ it "should return true for an Edit button with (div, :edit,:post, 'EDIT')" do
187
+ erb_app '<%= "<div><a href=\"/posts/99/edit\" class=\"ui-btn edit-link\" title=\"edit post\">EDIT</a></div>" %>'
188
+ body.should have_a_ui_btn('div', :edit, :post, 'EDIT')
189
+ end
190
+
191
+ it "should return true for an Edit button without link text (div, :edit,:post)" do
192
+ erb_app '<%= "<div><a href=\"/posts/99/edit\" class=\"ui-btn edit-link some-other-class\" title=\"edit post with extra text\">EDIT</a></div>" %>'
193
+ body.should have_a_ui_btn('div', :edit, :post)
194
+ end
195
+
196
+ it "should return true for a Delete button with (div, :delete,:post, 'DELETE')" do
197
+ erb_app '<%= "<div><a href=\"/posts/99\" class=\"ui-btn delete-link\" title=\"delete post\">DELETE</a></div>" %>'
198
+ body.should have_a_ui_btn('div', :delete, :post, 'DELETE')
199
+ end
200
+
201
+ it "should return true for a Delete button without link text (div, :delete,:post)" do
202
+ erb_app '<%= "<div><a href=\"/photos/99\" class=\"ui-btn delete-link some-other-class\" title=\"delete photo with extra text\">DELETE</a></div>" %>'
203
+ body.should have_a_ui_btn('div', :delete, :photo)
204
+ erb_app '<%= "<div><a href=\"/photos/99\" class=\"ui-btn delete-link some-other-class\" title=\"delete photo with extra text\"></a></div>" %>'
205
+ body.should have_a_ui_btn('div', :delete, :photo,'')
206
+ end
207
+
208
+ it "should return true for a Show button with custom link text" do
209
+ erb_app '<%= "<div><a href=\"/posts/99\" class=\"ui-btn show-link\" title=\"show post\">Custom</a></div>" %>'
210
+ body.should have_a_ui_btn('div', :show, :post, 'Custom')
211
+ end
212
+
213
+ it "should raise an Exception when given wrong arguments" do
214
+ lambda {
215
+ erb_app '<%= "<div><a href=\"/photos/99\" class=\"ui-btn delete-link\" title=\"delete photo\">DELETE</a></div>" %>'
216
+ body.should have_a_ui_btn('div', nil, :photo)
217
+ }.should raise_error(Exception)
218
+ end
219
+
220
+ end #/ #have_a_ui_btn
221
+
222
+ describe "#have_an_edit_btn" do
223
+
224
+ it "should return true when there is an edit_btn with 'EDIT'" do
225
+ erb_app '<%= "<div><a href=\"/posts/99/edit\" class=\"ui-btn edit-link\" title=\"edit post\">EDIT</a></div>" %>'
226
+ body.should have_an_edit_btn('div', :post)
227
+ erb_app '<%= "<div><a href=\"/posts/99/edit\" class=\"ui-btn edit-link some-other-class\" title=\"edit post with extra text\">EDIT</a></div>" %>'
228
+ body.should have_an_edit_btn('div', :post)
229
+ end
230
+
231
+ it "should return true when there is an edit_btn with custom text" do
232
+ erb_app '<%= "<div><a href=\"/posts/99/edit\" class=\"ui-btn edit-link\" title=\"edit post\">Custom</a></div>" %>'
233
+ body.should have_an_edit_btn('div', :post, 'Custom')
234
+ end
235
+
236
+ end #/ #have_an_edit_btn
237
+
238
+ describe "#have_a_delete_btn" do
239
+
240
+ it "should return true when there is an delete_btn with 'DELETE'" do
241
+ erb_app '<%= "<div><a href=\"/posts/99\" class=\"ui-btn delete-link\" title=\"delete post\">DELETE</a></div>" %>'
242
+ body.should have_a_delete_btn('div', :post)
243
+ erb_app '<%= "<div><a href=\"/posts/99\" class=\"ui-btn delete-link some-other-class\" title=\"delete post with extra text\">DELETE</a></div>" %>'
244
+ body.should have_a_delete_btn('div', :post)
245
+ end
246
+
247
+ it "should return true when there is an delete_btn with custom text" do
248
+ erb_app '<%= "<div><a href=\"/posts/99\" class=\"ui-btn delete-link\" title=\"delete post\">Custom</a></div>" %>'
249
+ body.should have_a_delete_btn('div', :post, 'Custom')
250
+ end
251
+
252
+ end #/ #have_an_edit_btn
253
+
254
+ describe "#have_a_show_btn" do
255
+
256
+ it "should return true when there is an show_btn with 'Show'" do
257
+ erb_app '<%= "<div><a href=\"/posts/99\" class=\"ui-btn show-link\" title=\"show post\">SHOW</a></div>" %>'
258
+ body.should have_a_show_btn('div', :post)
259
+ erb_app '<%= "<div><a href=\"/posts/99\" class=\"ui-btn show-link some-other-class\" title=\"show post with extra text\">SHOW</a></div>" %>'
260
+ body.should have_a_show_btn('div', :post)
261
+ end
262
+
263
+ it "should return true when there is an show_btn with custom text" do
264
+ erb_app '<%= "<div><a href=\"/posts/99\" class=\"ui-btn show-link\" title=\"show post\">Custom</a></div>" %>'
265
+ body.should have_a_show_btn('div', :post, 'Custom')
266
+ end
267
+
268
+ end #/ #have_an_edit_btn
269
+
270
+ end #/ Matchers
271
+
272
+ end #/ RSpec
273
+ end #/ Tests
274
+ end #/ Sinatra