rspec-html-matchers 0.3.5 → 0.4.0
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.
- data/.gitignore +5 -2
- data/CHANGELOG.md +19 -1
- data/README.md +115 -84
- data/Rakefile +5 -6
- data/features/support/env.rb +1 -1
- data/lib/rspec-html-matchers.rb +112 -81
- data/rspec-html-matchers.gemspec +2 -1
- data/{assets → spec/assets}/form.html +0 -0
- data/{assets → spec/assets}/ordered_list.html +0 -0
- data/{assets → spec/assets}/paragraphs.html +0 -0
- data/spec/assets/quotes.html +15 -0
- data/{assets → spec/assets}/search_and_submit.html +0 -0
- data/{assets → spec/assets}/special.html +0 -0
- data/spec/matchers/form_matchers_spec.rb +3 -2
- data/spec/matchers/have_tag_spec.rb +223 -97
- data/spec/spec_helper.rb +21 -4
- metadata +36 -11
- data/assets/quotes.html +0 -26
- data/mikhalok.jpg +0 -0
- data/spec/support/helpers.rb +0 -11
data/rspec-html-matchers.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "rspec-html-matchers"
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.4.0'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["kucaahbe"]
|
9
9
|
s.email = ["kucaahbe@ukr.net"]
|
@@ -28,4 +28,5 @@ DESC
|
|
28
28
|
s.add_development_dependency 'capybara'
|
29
29
|
s.add_development_dependency 'sinatra'
|
30
30
|
s.add_development_dependency 'rake'
|
31
|
+
s.add_development_dependency 'rspec', '>= 2.11.0' # in order to use new expect().to syntax
|
31
32
|
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<div>sample text</div>
|
2
|
+
<span>sample with 'single' quotes</span>
|
3
|
+
<span>sample with 'single' and "double" quotes</span>
|
4
|
+
<p>one</p>
|
5
|
+
<p>two</p>
|
6
|
+
<p>three </p>
|
7
|
+
<p>315</p>
|
8
|
+
<p>content with nbsp</p>
|
9
|
+
<pre> 1. bla
|
10
|
+
2. bla </pre>
|
11
|
+
|
12
|
+
<a href="#">học</a>
|
13
|
+
<!--
|
14
|
+
vim:list
|
15
|
+
-->
|
File without changes
|
File without changes
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "have_form" do
|
4
|
-
|
4
|
+
asset 'form'
|
5
5
|
|
6
6
|
context "without &block" do
|
7
7
|
it "should find form" do
|
8
|
-
rendered.should have_form("/books", :post)
|
8
|
+
rendered.should have_form("/books", :post) # just to make sure it just works
|
9
|
+
# params checking:
|
9
10
|
self.should_receive(:have_tag).with("form#new_book", :with => { :method => "post", :action => "/books", :class => %w(book formtastic) })
|
10
11
|
rendered.should have_form("/books", "post", :with => { :id => "new_book", :class => %w(book formtastic) })
|
11
12
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe 'have_tag' do
|
5
5
|
context "through css selector" do
|
6
|
-
|
6
|
+
asset 'search_and_submit'
|
7
7
|
|
8
8
|
it "should have right description" do
|
9
9
|
have_tag('div').description.should == 'have at least 1 element matching "div"'
|
@@ -28,25 +28,25 @@ describe 'have_tag' do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should not find tags and display appropriate message" do
|
31
|
-
expect { rendered.should have_tag('span') }.
|
31
|
+
expect { rendered.should have_tag('span') }.to raise_spec_error(
|
32
32
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "span", found 0.}
|
33
33
|
)
|
34
|
-
expect { rendered.should have_tag('span#some_id') }.
|
34
|
+
expect { rendered.should have_tag('span#some_id') }.to raise_spec_error(
|
35
35
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "span#some_id", found 0.}
|
36
36
|
)
|
37
|
-
expect { rendered.should have_tag('span.some_class') }.
|
37
|
+
expect { rendered.should have_tag('span.some_class') }.to raise_spec_error(
|
38
38
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "span.some_class", found 0.}
|
39
39
|
)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should find unexpected tags and display appropriate message" do
|
43
|
-
expect { rendered.should_not have_tag('div') }.
|
43
|
+
expect { rendered.should_not have_tag('div') }.to raise_spec_error(
|
44
44
|
%Q{expected following:\n#{rendered}\nto NOT have element matching "div", found 2.}
|
45
45
|
)
|
46
|
-
expect { rendered.should_not have_tag('div#div') }.
|
46
|
+
expect { rendered.should_not have_tag('div#div') }.to raise_spec_error(
|
47
47
|
%Q{expected following:\n#{rendered}\nto NOT have element matching "div#div", found 1.}
|
48
48
|
)
|
49
|
-
expect { rendered.should_not have_tag('p.paragraph') }.
|
49
|
+
expect { rendered.should_not have_tag('p.paragraph') }.to raise_spec_error(
|
50
50
|
%Q{expected following:\n#{rendered}\nto NOT have element matching "p.paragraph", found 1.}
|
51
51
|
)
|
52
52
|
end
|
@@ -67,14 +67,14 @@ describe 'have_tag' do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should not find tags that have classes specified via array and display appropriate message" do
|
70
|
-
expect
|
70
|
+
expect {
|
71
71
|
rendered.should have_tag('div',:with => {:class => %w(class-other class-two)})
|
72
|
-
|
72
|
+
}.to raise_spec_error(
|
73
73
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
|
74
74
|
)
|
75
|
-
expect
|
75
|
+
expect {
|
76
76
|
rendered.should have_tag('div',:with => {:class => 'class-other class-two'})
|
77
|
-
|
77
|
+
}.to raise_spec_error(
|
78
78
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
|
79
79
|
)
|
80
80
|
end
|
@@ -85,13 +85,13 @@ describe 'have_tag' do
|
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should not find tags and display appropriate message" do
|
88
|
-
expect { rendered.should have_tag('input#search',:with => {:type => "some_other_type"}) }.
|
88
|
+
expect { rendered.should have_tag('input#search',:with => {:type => "some_other_type"}) }.to raise_spec_error(
|
89
89
|
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "input#search[type='some_other_type']", found 0.}
|
90
90
|
)
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should find unexpected tags and display appropriate message" do
|
94
|
-
expect { rendered.should_not have_tag('input#search',:with => {:type => "text"}) }.
|
94
|
+
expect { rendered.should_not have_tag('input#search',:with => {:type => "text"}) }.to raise_spec_error(
|
95
95
|
%Q{expected following:\n#{rendered}\nto NOT have element matching "input#search[type='text']", found 1.}
|
96
96
|
)
|
97
97
|
end
|
@@ -101,7 +101,7 @@ describe 'have_tag' do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
context "by count" do
|
104
|
-
|
104
|
+
asset 'paragraphs'
|
105
105
|
|
106
106
|
it "should have right description" do
|
107
107
|
have_tag('div', :count => 100500).description.should == 'have 100500 element(s) matching "div"'
|
@@ -132,146 +132,272 @@ describe 'have_tag' do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should not find tags and display appropriate message(with :count)" do
|
135
|
-
expect { rendered.should have_tag('p', :count => 10) }.
|
135
|
+
expect { rendered.should have_tag('p', :count => 10) }.to raise_spec_error(
|
136
136
|
%Q{expected following:\n#{rendered}\nto have 10 element(s) matching "p", found 3.}
|
137
137
|
)
|
138
138
|
|
139
|
-
expect { rendered.should have_tag('p', :count => 4..8) }.
|
139
|
+
expect { rendered.should have_tag('p', :count => 4..8) }.to raise_spec_error(
|
140
140
|
%Q{expected following:\n#{rendered}\nto have at least 4 and at most 8 element(s) matching "p", found 3.}
|
141
141
|
)
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should find unexpected tags and display appropriate message(with :count)" do
|
145
|
-
expect { rendered.should_not have_tag('p', :count => 3) }.
|
145
|
+
expect { rendered.should_not have_tag('p', :count => 3) }.to raise_spec_error(
|
146
146
|
%Q{expected following:\n#{rendered}\nto NOT have 3 element(s) matching "p", but found.}
|
147
147
|
)
|
148
148
|
|
149
|
-
expect { rendered.should_not have_tag('p', :count => 1..3) }.
|
149
|
+
expect { rendered.should_not have_tag('p', :count => 1..3) }.to raise_spec_error(
|
150
150
|
%Q{expected following:\n#{rendered}\nto NOT have at least 1 and at most 3 element(s) matching "p", but found 3.}
|
151
151
|
)
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should not find tags and display appropriate message(with :minimum)" do
|
155
|
-
expect { rendered.should have_tag('p', :min => 100) }.
|
155
|
+
expect { rendered.should have_tag('p', :min => 100) }.to raise_spec_error(
|
156
156
|
%Q{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
|
157
157
|
)
|
158
|
-
expect { rendered.should have_tag('p', :minimum => 100) }.
|
158
|
+
expect { rendered.should have_tag('p', :minimum => 100) }.to raise_spec_error(
|
159
159
|
%Q{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
|
160
160
|
)
|
161
161
|
end
|
162
162
|
|
163
163
|
it "should find unexpected tags and display appropriate message(with :minimum)" do
|
164
|
-
expect { rendered.should_not have_tag('p', :min => 2) }.
|
164
|
+
expect { rendered.should_not have_tag('p', :min => 2) }.to raise_spec_error(
|
165
165
|
%Q{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
|
166
166
|
)
|
167
|
-
expect { rendered.should_not have_tag('p', :minimum => 2) }.
|
167
|
+
expect { rendered.should_not have_tag('p', :minimum => 2) }.to raise_spec_error(
|
168
168
|
%Q{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
|
169
169
|
)
|
170
170
|
end
|
171
171
|
|
172
172
|
it "should not find tags and display appropriate message(with :maximum)" do
|
173
|
-
expect { rendered.should have_tag('p', :max => 2) }.
|
173
|
+
expect { rendered.should have_tag('p', :max => 2) }.to raise_spec_error(
|
174
174
|
%Q{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
|
175
175
|
)
|
176
|
-
expect { rendered.should have_tag('p', :maximum => 2) }.
|
176
|
+
expect { rendered.should have_tag('p', :maximum => 2) }.to raise_spec_error(
|
177
177
|
%Q{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
|
178
178
|
)
|
179
179
|
end
|
180
180
|
|
181
181
|
it "should find unexpected tags and display appropriate message(with :maximum)" do
|
182
|
-
expect { rendered.should_not have_tag('p', :max => 5) }.
|
182
|
+
expect { rendered.should_not have_tag('p', :max => 5) }.to raise_spec_error(
|
183
183
|
%Q{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
|
184
184
|
)
|
185
|
-
expect { rendered.should_not have_tag('p', :maximum => 5) }.
|
185
|
+
expect { rendered.should_not have_tag('p', :maximum => 5) }.to raise_spec_error(
|
186
186
|
%Q{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
|
187
187
|
)
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should raise error when wrong params specified" do
|
191
|
-
expect { rendered.should have_tag('div', :count => 'string') }.
|
191
|
+
expect { rendered.should have_tag('div', :count => 'string') }.to raise_error(/wrong :count/)
|
192
192
|
wrong_params_error_msg_1 = ':count with :minimum or :maximum has no sence!'
|
193
|
-
expect { rendered.should have_tag('div', :count => 2, :minimum => 1) }.
|
194
|
-
expect { rendered.should have_tag('div', :count => 2, :min => 1) }.
|
195
|
-
expect { rendered.should have_tag('div', :count => 2, :maximum => 1) }.
|
196
|
-
expect { rendered.should have_tag('div', :count => 2, :max => 1) }.
|
193
|
+
expect { rendered.should have_tag('div', :count => 2, :minimum => 1) }.to raise_error(wrong_params_error_msg_1)
|
194
|
+
expect { rendered.should have_tag('div', :count => 2, :min => 1) }.to raise_error(wrong_params_error_msg_1)
|
195
|
+
expect { rendered.should have_tag('div', :count => 2, :maximum => 1) }.to raise_error(wrong_params_error_msg_1)
|
196
|
+
expect { rendered.should have_tag('div', :count => 2, :max => 1) }.to raise_error(wrong_params_error_msg_1)
|
197
197
|
wrong_params_error_msg_2 = ':minimum shold be less than :maximum!'
|
198
|
-
expect { rendered.should have_tag('div', :minimum => 2, :maximum => 1) }.
|
198
|
+
expect { rendered.should have_tag('div', :minimum => 2, :maximum => 1) }.to raise_error(wrong_params_error_msg_2)
|
199
199
|
[ 4..1, -2..6, 'a'..'z', 3..-9 ].each do |range|
|
200
|
-
expect { rendered.should have_tag('div', :count => range ) }.
|
200
|
+
expect { rendered.should have_tag('div', :count => range ) }.to raise_error("Your :count range(#{range.to_s}) has no sence!")
|
201
201
|
end
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
-
context "with
|
206
|
-
|
205
|
+
context "with :text specified" do
|
206
|
+
asset 'quotes'
|
207
207
|
|
208
|
-
|
209
|
-
rendered.should have_tag('div', :text => 'sample text')
|
210
|
-
rendered.should have_tag('p', :text => 'one')
|
211
|
-
rendered.should have_tag('div', :text => /SAMPLE/i)
|
212
|
-
rendered.should have_tag('span', :text => "sample with 'single' quotes")
|
213
|
-
rendered.should have_tag('span', :text => %Q{sample with 'single' and "double" quotes})
|
214
|
-
rendered.should have_tag('span', :text => /sample with 'single' and "double" quotes/)
|
215
|
-
|
216
|
-
rendered.should have_tag('p', :text => 'content with ignored spaces around')
|
217
|
-
rendered.should have_tag('p', :text => 'content with ignored spaces in')
|
218
|
-
rendered.should have_tag('p', :text => 'content with nbsp')
|
219
|
-
rendered.should have_tag('p', :text => 'content with nbsp and spaces around')
|
220
|
-
rendered.should have_tag('pre', :text => " 1. bla \n 2. bla ")
|
221
|
-
end
|
208
|
+
context 'using standard syntax' do
|
222
209
|
|
223
|
-
|
224
|
-
|
225
|
-
|
210
|
+
it "should find tags" do
|
211
|
+
rendered.should have_tag('div', :text => 'sample text')
|
212
|
+
rendered.should have_tag('p', :text => 'one')
|
213
|
+
rendered.should have_tag('div', :text => /SAMPLE/i)
|
214
|
+
rendered.should have_tag('span', :text => "sample with 'single' quotes")
|
215
|
+
rendered.should have_tag('span', :text => %Q{sample with 'single' and "double" quotes})
|
216
|
+
rendered.should have_tag('span', :text => /sample with 'single' and "double" quotes/)
|
217
|
+
|
218
|
+
rendered.should have_tag('p', :text => 'content with nbsp')
|
219
|
+
rendered.should have_tag('pre', :text => " 1. bla \n 2. bla ")
|
220
|
+
end
|
226
221
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
end
|
222
|
+
it "should map a string argument to :text => string" do
|
223
|
+
rendered.should have_tag('div', 'sample text')
|
224
|
+
end
|
231
225
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
rendered.should_not have_tag('strong', :text => /text does not present/)
|
237
|
-
|
238
|
-
rendered.should_not have_tag('p', :text => 'content with ignoredspaces around')
|
239
|
-
rendered.should_not have_tag('p', :text => 'content with ignored spaces around')
|
240
|
-
rendered.should_not have_tag('p', :text => 'content withignored spaces in')
|
241
|
-
rendered.should_not have_tag('p', :text => 'contentwith nbsp')
|
242
|
-
rendered.should_not have_tag('p', :text => 'content with nbsp and spaces around')
|
243
|
-
rendered.should_not have_tag('pre', :text => "1. bla\n2. bla")
|
244
|
-
end
|
226
|
+
it "should find with unicode text specified" do
|
227
|
+
expect { rendered.should have_tag('a', :text => "học") }.to_not raise_exception(Encoding::CompatibilityError) if RUBY_VERSION =~ /^1\.9/
|
228
|
+
rendered.should have_tag('a', :text => "học")
|
229
|
+
end
|
245
230
|
|
246
|
-
|
247
|
-
|
248
|
-
rendered.should_not have_tag('
|
249
|
-
rendered.
|
250
|
-
|
251
|
-
|
231
|
+
it "should not find tags" do
|
232
|
+
rendered.should_not have_tag('p', :text => 'text does not present')
|
233
|
+
rendered.should_not have_tag('strong', :text => 'text does not present')
|
234
|
+
rendered.should_not have_tag('p', :text => /text does not present/)
|
235
|
+
rendered.should_not have_tag('strong', :text => /text does not present/)
|
236
|
+
|
237
|
+
rendered.should_not have_tag('p', :text => 'contentwith nbsp')
|
238
|
+
rendered.should_not have_tag('pre', :text => "1. bla\n2. bla")
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should invoke #to_s method for :text" do
|
242
|
+
expect {
|
243
|
+
rendered.should_not have_tag('p', :text => 100500 )
|
244
|
+
rendered.should have_tag('p', :text => 315 )
|
245
|
+
}.to_not raise_exception
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should not find tags and display appropriate message" do
|
249
|
+
# TODO make diffable,maybe...
|
250
|
+
expect { rendered.should have_tag('div', :text => 'SAMPLE text') }.to raise_spec_error(
|
251
|
+
%Q{"SAMPLE text" expected within "div" in following template:\n#{rendered}}
|
252
|
+
)
|
253
|
+
expect { rendered.should have_tag('div', :text => /SAMPLE tekzt/i) }.to raise_spec_error(
|
254
|
+
%Q{/SAMPLE tekzt/i regexp expected within "div" in following template:\n#{rendered}}
|
255
|
+
)
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should find unexpected tags and display appropriate message" do
|
259
|
+
expect { rendered.should_not have_tag('div', :text => 'sample text') }.to raise_spec_error(
|
260
|
+
%Q{"sample text" unexpected within "div" in following template:\n#{rendered}\nbut was found.}
|
261
|
+
)
|
262
|
+
expect { rendered.should_not have_tag('div', :text => /SAMPLE text/i) }.to raise_spec_error(
|
263
|
+
%Q{/SAMPLE text/i regexp unexpected within "div" in following template:\n#{rendered}\nbut was found.}
|
264
|
+
)
|
265
|
+
end
|
252
266
|
|
253
|
-
it "should not find tags and display appropriate message" do
|
254
|
-
# TODO make diffable,maybe...
|
255
|
-
expect { rendered.should have_tag('div', :text => 'SAMPLE text') }.should raise_spec_error(
|
256
|
-
%Q{"SAMPLE text" expected within "div" in following template:\n#{rendered}}
|
257
|
-
)
|
258
|
-
expect { rendered.should have_tag('div', :text => /SAMPLE tekzt/i) }.should raise_spec_error(
|
259
|
-
%Q{/SAMPLE tekzt/i regexp expected within "div" in following template:\n#{rendered}}
|
260
|
-
)
|
261
267
|
end
|
262
268
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
269
|
+
context 'using alternative syntax(with_text/without_text)' do
|
270
|
+
|
271
|
+
it "should raise exception when used outside any other tag matcher" do
|
272
|
+
expect { with_text 'sample text' }.to raise_error(StandardError,/inside "have_tag"/)
|
273
|
+
expect { without_text 'sample text' }.to raise_error(StandardError,/inside "have_tag"/)
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should raise exception when used with block" do
|
277
|
+
expect {
|
278
|
+
rendered.should have_tag('div') do
|
279
|
+
with_text 'sample text' do
|
280
|
+
puts 'bla'
|
281
|
+
end
|
282
|
+
end
|
283
|
+
}.to raise_error(ArgumentError,/does not accept block/)
|
284
|
+
expect {
|
285
|
+
rendered.should have_tag('div') do
|
286
|
+
with_text 'sample text', proc { puts 'bla' }
|
287
|
+
end
|
288
|
+
}.to raise_error(ArgumentError)
|
289
|
+
|
290
|
+
expect {
|
291
|
+
rendered.should have_tag('div') do
|
292
|
+
without_text 'sample text' do
|
293
|
+
puts 'bla'
|
294
|
+
end
|
295
|
+
end
|
296
|
+
}.to raise_error(ArgumentError,/does not accept block/)
|
297
|
+
expect {
|
298
|
+
rendered.should have_tag('div') do
|
299
|
+
without_text 'sample text', proc { puts 'bla' }
|
300
|
+
end
|
301
|
+
}.to raise_error(ArgumentError)
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should find tags" do
|
305
|
+
rendered.should have_tag('div') do
|
306
|
+
with_text 'sample text'
|
307
|
+
end
|
308
|
+
|
309
|
+
rendered.should have_tag('p') do
|
310
|
+
with_text 'one'
|
311
|
+
end
|
312
|
+
|
313
|
+
rendered.should have_tag('div') do
|
314
|
+
with_text /SAMPLE/i
|
315
|
+
end
|
316
|
+
|
317
|
+
rendered.should have_tag('span') do
|
318
|
+
with_text "sample with 'single' quotes"
|
319
|
+
end
|
320
|
+
|
321
|
+
rendered.should have_tag('span') do
|
322
|
+
with_text %Q{sample with 'single' and "double" quotes}
|
323
|
+
end
|
324
|
+
|
325
|
+
rendered.should have_tag('span') do
|
326
|
+
with_text /sample with 'single' and "double" quotes/
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
rendered.should have_tag('p') do
|
331
|
+
with_text 'content with nbsp'
|
332
|
+
end
|
333
|
+
|
334
|
+
rendered.should have_tag('pre') do
|
335
|
+
with_text " 1. bla \n 2. bla "
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
it "should not find tags" do
|
340
|
+
rendered.should have_tag('p') do
|
341
|
+
but_without_text 'text does not present'
|
342
|
+
without_text 'text does not present'
|
343
|
+
end
|
344
|
+
|
345
|
+
rendered.should have_tag('p') do
|
346
|
+
but_without_text /text does not present/
|
347
|
+
without_text /text does not present/
|
348
|
+
end
|
349
|
+
|
350
|
+
rendered.should have_tag('p') do
|
351
|
+
but_without_text 'contentwith nbsp'
|
352
|
+
without_text 'contentwith nbsp'
|
353
|
+
end
|
354
|
+
|
355
|
+
rendered.should have_tag('pre') do
|
356
|
+
but_without_text "1. bla\n2. bla"
|
357
|
+
without_text "1. bla\n2. bla"
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should not find tags and display appropriate message" do
|
362
|
+
expect {
|
363
|
+
rendered.should have_tag('div') do
|
364
|
+
with_text 'SAMPLE text'
|
365
|
+
end
|
366
|
+
}.to raise_spec_error(
|
367
|
+
%Q{"SAMPLE text" expected within "div" in following template:\n<div>sample text</div>}
|
368
|
+
)
|
369
|
+
expect {
|
370
|
+
rendered.should have_tag('div') do
|
371
|
+
with_text /SAMPLE tekzt/i
|
372
|
+
end
|
373
|
+
}.to raise_spec_error(
|
374
|
+
%Q{/SAMPLE tekzt/i regexp expected within "div" in following template:\n<div>sample text</div>}
|
375
|
+
)
|
376
|
+
end
|
377
|
+
|
378
|
+
it "should find unexpected tags and display appropriate message" do
|
379
|
+
expect {
|
380
|
+
rendered.should have_tag('div') do
|
381
|
+
without_text 'sample text'
|
382
|
+
end
|
383
|
+
}.to raise_spec_error(
|
384
|
+
%Q{"sample text" unexpected within "div" in following template:\n<div>sample text</div>\nbut was found.}
|
385
|
+
)
|
386
|
+
expect {
|
387
|
+
rendered.should have_tag('div') do
|
388
|
+
without_text /SAMPLE text/i
|
389
|
+
end
|
390
|
+
}.to raise_spec_error(
|
391
|
+
%Q{/SAMPLE text/i regexp unexpected within "div" in following template:\n<div>sample text</div>\nbut was found.}
|
392
|
+
)
|
393
|
+
end
|
394
|
+
|
270
395
|
end
|
396
|
+
|
271
397
|
end
|
272
398
|
|
273
399
|
context "mixed matching" do
|
274
|
-
|
400
|
+
asset 'special'
|
275
401
|
|
276
402
|
it "should find tags by count and exact content" do
|
277
403
|
rendered.should have_tag("td", :text => 'a', :count => 3)
|
@@ -312,7 +438,7 @@ describe 'have_tag' do
|
|
312
438
|
end
|
313
439
|
|
314
440
|
context "nested matching:" do
|
315
|
-
|
441
|
+
asset 'ordered_list'
|
316
442
|
|
317
443
|
it "should find tags" do
|
318
444
|
rendered.should have_tag('ol') {
|
@@ -339,24 +465,24 @@ describe 'have_tag' do
|
|
339
465
|
end
|
340
466
|
|
341
467
|
it "should handle do; end" do
|
342
|
-
expect
|
468
|
+
expect {
|
343
469
|
rendered.should have_tag('ol') do
|
344
470
|
with_tag('div')
|
345
471
|
end
|
346
|
-
|
472
|
+
}.to raise_spec_error(/have at least 1 element matching "div", found 0/)
|
347
473
|
end
|
348
474
|
|
349
475
|
it "should not find tags and display appropriate message" do
|
350
476
|
ordered_list_regexp = rendered[/<ol.*<\/ol>/m].gsub(/(\n?\s{2,}|\n\s?)/,'\n*\s*')
|
351
477
|
expect {
|
352
478
|
rendered.should have_tag('ol') { with_tag('li'); with_tag('div') }
|
353
|
-
}.
|
479
|
+
}.to raise_spec_error(/expected following:\n#{ordered_list_regexp}\n\s*to have at least 1 element matching "div", found 0/)
|
354
480
|
expect {
|
355
481
|
rendered.should have_tag('ol') { with_tag('li'); with_tag('li', :count => 10) }
|
356
|
-
}.
|
482
|
+
}.to raise_spec_error(/expected following:\n#{ordered_list_regexp}\n\s*to have 10 element\(s\) matching "li", found 3/)
|
357
483
|
expect {
|
358
484
|
rendered.should have_tag('ol') { with_tag('li'); with_tag('li', :text => /SAMPLE text/i) }
|
359
|
-
}.
|
485
|
+
}.to raise_spec_error(/\/SAMPLE text\/i regexp expected within "li" in following template:\n#{ordered_list_regexp}/)
|
360
486
|
end
|
361
487
|
end
|
362
488
|
end
|