rspec-html-matchers 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +87 -0
- data/Gemfile +2 -0
- data/README.md +109 -0
- data/Rakefile +27 -0
- data/assets/form.html +139 -0
- data/assets/ordered_list.html +9 -0
- data/assets/paragraphs.html +3 -0
- data/assets/quotes.html +24 -0
- data/assets/search_and_submit.html +9 -0
- data/assets/special.html +22 -0
- data/lib/rspec-html-matchers.rb +486 -0
- data/mikhalok.jpg +0 -0
- data/rspec-html-matchers.gemspec +28 -0
- data/script/assets.rb +38 -0
- data/script/console +9 -0
- data/spec/matchers/form_matchers_spec.rb +310 -0
- data/spec/matchers/have_tag_spec.rb +346 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/helpers.rb +11 -0
- metadata +123 -0
data/mikhalok.jpg
ADDED
Binary file
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "rspec-html-matchers"
|
6
|
+
s.version = '0.2.2'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["kucaahbe"]
|
9
|
+
s.email = ["kucaahbe@ukr.net"]
|
10
|
+
s.homepage = "http://github.com/kucaahbe/rspec-html-matchers"
|
11
|
+
s.summary = %q{Nokogiri based 'have_tag' and 'with_tag' matchers for rspec 2.x.x}
|
12
|
+
s.description = <<DESC
|
13
|
+
#{s.summary}. Does not depend on assert_select matcher, provides useful error messages.
|
14
|
+
DESC
|
15
|
+
|
16
|
+
s.rubyforge_project = "rspec-html-matchers"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_dependency 'rspec', '>= 2.0.0'
|
24
|
+
s.add_dependency 'nokogiri', '>= 1.4.4'
|
25
|
+
|
26
|
+
s.add_development_dependency 'simplecov'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
end
|
data/script/assets.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
class Asset
|
2
|
+
@@assets = {}
|
3
|
+
|
4
|
+
PATH = File.expand_path(File.join(File.dirname(__FILE__),'..','assets','*.html'))
|
5
|
+
|
6
|
+
def self.[] name
|
7
|
+
@@assets[name.to_s]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.<< asset
|
11
|
+
@@assets.merge! asset.name => asset
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.list
|
15
|
+
@@assets.keys
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :name
|
19
|
+
|
20
|
+
def initialize name, path
|
21
|
+
@name = name
|
22
|
+
@path = path
|
23
|
+
end
|
24
|
+
|
25
|
+
def content
|
26
|
+
@content ||= IO.read(@path)
|
27
|
+
puts @content
|
28
|
+
return @content
|
29
|
+
end
|
30
|
+
alias_method :c, :content
|
31
|
+
end
|
32
|
+
|
33
|
+
puts 'assets list:'
|
34
|
+
Dir[Asset::PATH].each do |asset_path|
|
35
|
+
asset_name = File.basename(asset_path,'.html')
|
36
|
+
puts asset_name
|
37
|
+
Asset << Asset.new(asset_name,asset_path)
|
38
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,310 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "have_form" do
|
4
|
+
let(:rendered) { IO.read(File.dirname(__FILE__)+"/../../assets/form.html") }
|
5
|
+
|
6
|
+
context "without &block" do
|
7
|
+
it "should find form" do
|
8
|
+
rendered.should have_form("/books", :post)
|
9
|
+
self.should_receive(:have_tag).with("form#new_book", :with => { :method => "post", :action => "/books", :class => %w(book formtastic) })
|
10
|
+
rendered.should have_form("/books", "post", :with => { :id => "new_book", :class => %w(book formtastic) })
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not find form" do
|
14
|
+
rendered.should_not have_form("/some_url", :post)
|
15
|
+
rendered.should_not have_form("/books", :get)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "with &block" do
|
20
|
+
context "with_select" do
|
21
|
+
it "should find select" do
|
22
|
+
rendered.should have_form("/books", :post) do
|
23
|
+
with_select("book[publisher_id]", :with => { :id => "book_publisher_id" })
|
24
|
+
self.should_receive(:have_tag).with("select#book_publisher_id", :with => { :name => "book[publisher_id]" })
|
25
|
+
with_select("book[publisher_id]", :with => { :id => "book_publisher_id" })
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not find select" do
|
30
|
+
rendered.should have_form("/books", :post) do
|
31
|
+
without_select("book[publisher_id]", :with => { :id => "other_id" })
|
32
|
+
self.should_receive(:have_tag).with("select#book_publisher_id", :with => { :name => "koob[publisher_id]" })
|
33
|
+
without_select("koob[publisher_id]", :with => { :id => "book_publisher_id" })
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with_option" do
|
38
|
+
it "should find options" do
|
39
|
+
rendered.should have_form("/books", :post) do
|
40
|
+
with_select("book[publisher_id]") do
|
41
|
+
with_option(nil)
|
42
|
+
with_option("The Pragmatic Bookshelf", :selected => true)
|
43
|
+
with_option(/sitepoint/,2)
|
44
|
+
self.should_receive(:have_tag).with('option', :with => { :value => '3' }, :text => "O'Reilly")
|
45
|
+
with_option("O'Reilly", 3, :selected => false)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should not find options" do
|
51
|
+
rendered.should have_form("/books", :post) do
|
52
|
+
with_select("book[publisher_id]") do
|
53
|
+
without_option("blah blah")
|
54
|
+
without_option("O'Reilly", 3, :selected => true)
|
55
|
+
without_option("O'Reilly", 100500)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "with_button" do
|
62
|
+
it "should find button" do
|
63
|
+
rendered.should have_form("/books", :post) do
|
64
|
+
self.should_receive(:have_tag).with('button', :with => {}, :text => "Cancel Book")
|
65
|
+
with_button("Cancel Book")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should not find button" do
|
70
|
+
rendered.should have_form("/books", :post) do
|
71
|
+
without_button("Cancel Book")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with_hidden_field" do
|
78
|
+
it "should find hidden field" do
|
79
|
+
rendered.should have_form("/books", :post) do
|
80
|
+
with_hidden_field("authenticity_token")
|
81
|
+
self.should_receive(:have_tag).with('input', :with => {
|
82
|
+
:name => 'authenticity_token',
|
83
|
+
:type => 'hidden',
|
84
|
+
:value => '718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE='
|
85
|
+
})
|
86
|
+
with_hidden_field("authenticity_token", '718WaH76RAbIVhDlnOidgew62ikn8IUCOyWLEqjw1GE=')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should not find hidden field" do
|
91
|
+
rendered.should have_form("/books", :post) do
|
92
|
+
without_hidden_field('user_id')
|
93
|
+
without_hidden_field('authenticity_token', 'blabla')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "with_text_field" do
|
99
|
+
it "should find text field" do
|
100
|
+
rendered.should have_form("/books", :post) do
|
101
|
+
with_text_field('book[title]')
|
102
|
+
with_text_field('book[title]',nil)
|
103
|
+
with_text_field('book[author]','Authorname')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not find text field" do
|
108
|
+
rendered.should have_form("/books", :post) do
|
109
|
+
without_text_field('book[title]','title does not exist')
|
110
|
+
without_text_field('book[authoRR]')
|
111
|
+
without_text_field('book[blabla]')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "with_email_field" do
|
117
|
+
it "should find email field" do
|
118
|
+
rendered.should have_form("/books", :post) do
|
119
|
+
with_email_field('user[email]')
|
120
|
+
with_email_field('user[email]', 'email@example.com')
|
121
|
+
with_email_field('user[email_confirmation]', nil)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should not find email field" do
|
126
|
+
rendered.should have_form("/books", :post) do
|
127
|
+
without_email_field('book[author]','Authorname')
|
128
|
+
without_email_field('user[emaiL]')
|
129
|
+
without_email_field('user[apocalyptiq]')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "with_url_field" do
|
135
|
+
it "should find url field" do
|
136
|
+
rendered.should have_form("/books", :post) do
|
137
|
+
with_url_field('user[url]')
|
138
|
+
with_url_field('user[url]', 'http://user.com')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should not find url field" do
|
143
|
+
rendered.should have_form("/books", :post) do
|
144
|
+
without_url_field('user[url]','Authorname')
|
145
|
+
without_url_field('user[emaiL]')
|
146
|
+
without_url_field('user[apocalyptiq]')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context "with_number_field" do
|
152
|
+
it "should find number field" do
|
153
|
+
rendered.should have_form("/books", :post) do
|
154
|
+
with_number_field('number')
|
155
|
+
with_number_field('number_defined', 3)
|
156
|
+
with_number_field('number_defined', '3')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should not find number field" do
|
161
|
+
rendered.should have_form("/books", :post) do
|
162
|
+
without_number_field('number',400)
|
163
|
+
without_number_field('number','400')
|
164
|
+
without_number_field('user[emaiL]')
|
165
|
+
without_number_field('user[apocalyptiq]')
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "with_range_field" do
|
171
|
+
it "should find range field" do
|
172
|
+
rendered.should have_form("/books", :post) do
|
173
|
+
with_range_field('range1', 1, 3)
|
174
|
+
with_range_field('range1','1','3')
|
175
|
+
with_range_field('range2', 1, 3, :with => { :value => 2 } )
|
176
|
+
with_range_field('range2', 1, 3, :with => { :value => '2' } )
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should not find range field" do
|
181
|
+
rendered.should have_form("/books", :post) do
|
182
|
+
without_range_field('number')
|
183
|
+
without_range_field('range1', 1, 5)
|
184
|
+
without_range_field('range2', 1, 3, :with => { :value => 5 } )
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "with_date_field" do
|
190
|
+
it "should find date field" do
|
191
|
+
rendered.should have_form("/books", :post) do
|
192
|
+
with_date_field(:date)
|
193
|
+
with_date_field(:date, 'book_date')
|
194
|
+
with_date_field(:month, 'book_month', :with => { :value => 5 })
|
195
|
+
with_date_field(:week,'book_week')
|
196
|
+
with_date_field(:time, 'book_time')
|
197
|
+
with_date_field(:datetime, 'book_datetime')
|
198
|
+
with_date_field('datetime-local', 'book_datetime_local')
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should not find date field" do
|
203
|
+
rendered.should have_form("/books", :post) do
|
204
|
+
without_date_field(:date, 'book_something')
|
205
|
+
without_date_field(:month, 'book_month', :with => { :value => 100500 })
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should raise exception if wrong date field type specified" do
|
210
|
+
expect do
|
211
|
+
rendered.should have_form("/books", :post) do
|
212
|
+
without_date_field(:unknown, 'book_something')
|
213
|
+
end
|
214
|
+
end.to raise_error('unknown type `unknown` for date picker')
|
215
|
+
expect do
|
216
|
+
rendered.should have_form("/books", :post) do
|
217
|
+
with_date_field(:unknown, 'book_something')
|
218
|
+
end
|
219
|
+
end.to raise_error('unknown type `unknown` for date picker')
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "with_password_field" do
|
224
|
+
it "should find password field" do
|
225
|
+
rendered.should have_form("/books", :post) do
|
226
|
+
with_password_field('user[password]')
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should not find password field" do
|
231
|
+
rendered.should have_form("/books", :post) do
|
232
|
+
without_password_field('account[password]')
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "with_file_field" do
|
238
|
+
it "should find file field" do
|
239
|
+
rendered.should have_form("/books", :post) do
|
240
|
+
with_file_field('form[file]')
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should not find file field" do
|
245
|
+
rendered.should have_form("/books", :post) do
|
246
|
+
without_file_field('user[file]')
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context "with_text_area" do
|
252
|
+
it "should find text area" do
|
253
|
+
rendered.should have_form("/books", :post) do
|
254
|
+
with_text_area('book[description]')
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
it "should not find text area" do
|
259
|
+
rendered.should have_form("/books", :post) do
|
260
|
+
without_text_area('user[bio]')
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "with_check_box" do
|
266
|
+
it "should find check box" do
|
267
|
+
rendered.should have_form("/books", :post) do
|
268
|
+
with_checkbox("book[still_in_print]")
|
269
|
+
with_checkbox("book[still_in_print]","1")
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should not find check box" do
|
274
|
+
rendered.should have_form("/books", :post) do
|
275
|
+
without_checkbox("book[book]")
|
276
|
+
without_checkbox("book[still_in_print]","500")
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context "with_radio_button" do
|
282
|
+
it "should find radio button" do
|
283
|
+
rendered.should have_form("/books", :post) do
|
284
|
+
with_radio_button("form[name]","true")
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
it "should not find radio button" do
|
289
|
+
rendered.should have_form("/books", :post) do
|
290
|
+
without_radio_button("form[name]","100500")
|
291
|
+
without_radio_button("form[item]","false")
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
context "with_submit" do
|
297
|
+
it "should find submit" do
|
298
|
+
rendered.should have_form("/books", :post) do
|
299
|
+
with_submit("Create Book")
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should not find submit" do
|
304
|
+
rendered.should have_form("/books", :post) do
|
305
|
+
without_submit("Destroy Book")
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
@@ -0,0 +1,346 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'have_tag' do
|
4
|
+
context "through css selector" do
|
5
|
+
let(:rendered) { asset('search_and_submit') }
|
6
|
+
|
7
|
+
it "should find tags" do
|
8
|
+
rendered.should have_tag('div')
|
9
|
+
rendered.should have_tag(:div)
|
10
|
+
rendered.should have_tag('div#div')
|
11
|
+
rendered.should have_tag('p.paragraph')
|
12
|
+
rendered.should have_tag('div p strong')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should not find tags" do
|
16
|
+
rendered.should_not have_tag('span')
|
17
|
+
rendered.should_not have_tag(:span)
|
18
|
+
rendered.should_not have_tag('span#id')
|
19
|
+
rendered.should_not have_tag('span#class')
|
20
|
+
rendered.should_not have_tag('div div span')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not find tags and display appropriate message" do
|
24
|
+
expect { rendered.should have_tag('span') }.should raise_spec_error(
|
25
|
+
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "span", found 0.}
|
26
|
+
)
|
27
|
+
expect { rendered.should have_tag('span#some_id') }.should raise_spec_error(
|
28
|
+
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "span#some_id", found 0.}
|
29
|
+
)
|
30
|
+
expect { rendered.should have_tag('span.some_class') }.should raise_spec_error(
|
31
|
+
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "span.some_class", found 0.}
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should find unexpected tags and display appropriate message" do
|
36
|
+
expect { rendered.should_not have_tag('div') }.should raise_spec_error(
|
37
|
+
%Q{expected following:\n#{rendered}\nto NOT have element matching "div", found 2.}
|
38
|
+
)
|
39
|
+
expect { rendered.should_not have_tag('div#div') }.should raise_spec_error(
|
40
|
+
%Q{expected following:\n#{rendered}\nto NOT have element matching "div#div", found 1.}
|
41
|
+
)
|
42
|
+
expect { rendered.should_not have_tag('p.paragraph') }.should raise_spec_error(
|
43
|
+
%Q{expected following:\n#{rendered}\nto NOT have element matching "p.paragraph", found 1.}
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with additional HTML attributes(:with option)" do
|
48
|
+
it "should find tags" do
|
49
|
+
rendered.should have_tag('input#search',:with => {:type => "text"})
|
50
|
+
rendered.should have_tag(:input ,:with => {:type => "submit", :value => "Save"})
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should find tags that have classes specified via array(or string)" do
|
54
|
+
rendered.should have_tag('div',:with => {:class => %w(class-one class-two)})
|
55
|
+
rendered.should have_tag('div',:with => {:class => 'class-two class-one'})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not find tags that have classes specified via array" do
|
59
|
+
rendered.should_not have_tag('div',:with => {:class => %w(class-other class-two)})
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not find tags that have classes specified via array and display appropriate message" do
|
63
|
+
expect do
|
64
|
+
rendered.should have_tag('div',:with => {:class => %w(class-other class-two)})
|
65
|
+
end.should raise_spec_error(
|
66
|
+
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
|
67
|
+
)
|
68
|
+
expect do
|
69
|
+
rendered.should have_tag('div',:with => {:class => 'class-other class-two'})
|
70
|
+
end.should raise_spec_error(
|
71
|
+
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "div.class-other.class-two", found 0.}
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should not find tags" do
|
76
|
+
rendered.should_not have_tag('input#search',:with => {:type => "some_other_type"})
|
77
|
+
rendered.should_not have_tag(:input, :with => {:type => "some_other_type"})
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not find tags and display appropriate message" do
|
81
|
+
expect { rendered.should have_tag('input#search',:with => {:type => "some_other_type"}) }.should raise_spec_error(
|
82
|
+
%Q{expected following:\n#{rendered}\nto have at least 1 element matching "input#search[type='some_other_type']", found 0.}
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should find unexpected tags and display appropriate message" do
|
87
|
+
expect { rendered.should_not have_tag('input#search',:with => {:type => "text"}) }.should raise_spec_error(
|
88
|
+
%Q{expected following:\n#{rendered}\nto NOT have element matching "input#search[type='text']", found 1.}
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
context "by count" do
|
97
|
+
let(:rendered) { asset('paragraphs') }
|
98
|
+
|
99
|
+
it "should find tags" do
|
100
|
+
rendered.should have_tag('p', :count => 3)
|
101
|
+
rendered.should have_tag('p', :count => 2..3)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should find tags when :minimum specified" do
|
105
|
+
rendered.should have_tag('p', :min => 3)
|
106
|
+
rendered.should have_tag('p', :minimum => 2)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should find tags when :maximum specified" do
|
110
|
+
rendered.should have_tag('p', :max => 4)
|
111
|
+
rendered.should have_tag('p', :maximum => 3)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should not find tags(with :count, :minimum or :maximum specified)" do
|
115
|
+
rendered.should_not have_tag('p', :count => 10)
|
116
|
+
rendered.should_not have_tag('p', :count => 4..8)
|
117
|
+
rendered.should_not have_tag('p', :min => 11)
|
118
|
+
rendered.should_not have_tag('p', :minimum => 10)
|
119
|
+
rendered.should_not have_tag('p', :max => 2)
|
120
|
+
rendered.should_not have_tag('p', :maximum => 2)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should not find tags and display appropriate message(with :count)" do
|
124
|
+
expect { rendered.should have_tag('p', :count => 10) }.should raise_spec_error(
|
125
|
+
%Q{expected following:\n#{rendered}\nto have 10 element(s) matching "p", found 3.}
|
126
|
+
)
|
127
|
+
|
128
|
+
expect { rendered.should have_tag('p', :count => 4..8) }.should raise_spec_error(
|
129
|
+
%Q{expected following:\n#{rendered}\nto have at least 4 and at most 8 element(s) matching "p", found 3.}
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should find unexpected tags and display appropriate message(with :count)" do
|
134
|
+
expect { rendered.should_not have_tag('p', :count => 3) }.should raise_spec_error(
|
135
|
+
%Q{expected following:\n#{rendered}\nto NOT have 3 element(s) matching "p", but found.}
|
136
|
+
)
|
137
|
+
|
138
|
+
expect { rendered.should_not have_tag('p', :count => 1..3) }.should raise_spec_error(
|
139
|
+
%Q{expected following:\n#{rendered}\nto NOT have at least 1 and at most 3 element(s) matching "p", but found 3.}
|
140
|
+
)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should not find tags and display appropriate message(with :minimum)" do
|
144
|
+
expect { rendered.should have_tag('p', :min => 100) }.should raise_spec_error(
|
145
|
+
%Q{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
|
146
|
+
)
|
147
|
+
expect { rendered.should have_tag('p', :minimum => 100) }.should raise_spec_error(
|
148
|
+
%Q{expected following:\n#{rendered}\nto have at least 100 element(s) matching "p", found 3.}
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should find unexpected tags and display appropriate message(with :minimum)" do
|
153
|
+
expect { rendered.should_not have_tag('p', :min => 2) }.should raise_spec_error(
|
154
|
+
%Q{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
|
155
|
+
)
|
156
|
+
expect { rendered.should_not have_tag('p', :minimum => 2) }.should raise_spec_error(
|
157
|
+
%Q{expected following:\n#{rendered}\nto NOT have at least 2 element(s) matching "p", but found 3.}
|
158
|
+
)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should not find tags and display appropriate message(with :maximum)" do
|
162
|
+
expect { rendered.should have_tag('p', :max => 2) }.should raise_spec_error(
|
163
|
+
%Q{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
|
164
|
+
)
|
165
|
+
expect { rendered.should have_tag('p', :maximum => 2) }.should raise_spec_error(
|
166
|
+
%Q{expected following:\n#{rendered}\nto have at most 2 element(s) matching "p", found 3.}
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should find unexpected tags and display appropriate message(with :maximum)" do
|
171
|
+
expect { rendered.should_not have_tag('p', :max => 5) }.should raise_spec_error(
|
172
|
+
%Q{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
|
173
|
+
)
|
174
|
+
expect { rendered.should_not have_tag('p', :maximum => 5) }.should raise_spec_error(
|
175
|
+
%Q{expected following:\n#{rendered}\nto NOT have at most 5 element(s) matching "p", but found 3.}
|
176
|
+
)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should raise error when wrong params specified" do
|
180
|
+
expect { rendered.should have_tag('div', :count => 'string') }.should raise_error(/wrong :count/)
|
181
|
+
wrong_params_error_msg_1 = ':count with :minimum or :maximum has no sence!'
|
182
|
+
expect { rendered.should have_tag('div', :count => 2, :minimum => 1) }.should raise_error(wrong_params_error_msg_1)
|
183
|
+
expect { rendered.should have_tag('div', :count => 2, :min => 1) }.should raise_error(wrong_params_error_msg_1)
|
184
|
+
expect { rendered.should have_tag('div', :count => 2, :maximum => 1) }.should raise_error(wrong_params_error_msg_1)
|
185
|
+
expect { rendered.should have_tag('div', :count => 2, :max => 1) }.should raise_error(wrong_params_error_msg_1)
|
186
|
+
wrong_params_error_msg_2 = ':minimum shold be less than :maximum!'
|
187
|
+
expect { rendered.should have_tag('div', :minimum => 2, :maximum => 1) }.should raise_error(wrong_params_error_msg_2)
|
188
|
+
[ 4..1, -2..6, 'a'..'z', 3..-9 ].each do |range|
|
189
|
+
expect { rendered.should have_tag('div', :count => range ) }.should raise_error("Your :count range(#{range.to_s}) has no sence!")
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context "with content specified" do
|
195
|
+
let(:rendered) { asset('quotes') }
|
196
|
+
|
197
|
+
it "should find tags" do
|
198
|
+
rendered.should have_tag('div', :text => 'sample text')
|
199
|
+
rendered.should have_tag('p', :text => 'one')
|
200
|
+
rendered.should have_tag('div', :text => /SAMPLE/i)
|
201
|
+
rendered.should have_tag('span', :text => "sample with 'single' quotes")
|
202
|
+
rendered.should have_tag('span', :text => %Q{sample with 'single' and "double" quotes})
|
203
|
+
|
204
|
+
rendered.should have_tag('p', :text => 'content with ignored spaces around')
|
205
|
+
rendered.should have_tag('p', :text => 'content with ignored spaces in')
|
206
|
+
rendered.should have_tag('p', :text => 'content with nbsp')
|
207
|
+
rendered.should have_tag('p', :text => 'content with nbsp and spaces around')
|
208
|
+
rendered.should have_tag('pre', :text => " 1. bla \n 2. bla ")
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should map a string argument to :text => string" do
|
212
|
+
rendered.should have_tag('div', 'sample text')
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should not find tags" do
|
216
|
+
rendered.should_not have_tag('p', :text => 'text does not present')
|
217
|
+
rendered.should_not have_tag('strong', :text => 'text does not present')
|
218
|
+
rendered.should_not have_tag('p', :text => /text does not present/)
|
219
|
+
rendered.should_not have_tag('strong', :text => /text does not present/)
|
220
|
+
|
221
|
+
rendered.should_not have_tag('p', :text => 'content with ignoredspaces around')
|
222
|
+
rendered.should_not have_tag('p', :text => 'content with ignored spaces around')
|
223
|
+
rendered.should_not have_tag('p', :text => 'content withignored spaces in')
|
224
|
+
rendered.should_not have_tag('p', :text => 'contentwith nbsp')
|
225
|
+
rendered.should_not have_tag('p', :text => 'content with nbsp and spaces around')
|
226
|
+
rendered.should_not have_tag('pre', :text => "1. bla\n2. bla")
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should invoke #to_s method for :text" do
|
230
|
+
expect {
|
231
|
+
rendered.should_not have_tag('p', :text => 100500 )
|
232
|
+
rendered.should have_tag('p', :text => 315 )
|
233
|
+
}.to_not raise_exception
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should not find tags and display appropriate message" do
|
237
|
+
# TODO make diffable,maybe...
|
238
|
+
expect { rendered.should have_tag('div', :text => 'SAMPLE text') }.should raise_spec_error(
|
239
|
+
%Q{"SAMPLE text" expected within "div" in following template:\n#{rendered}}
|
240
|
+
)
|
241
|
+
expect { rendered.should have_tag('div', :text => /SAMPLE tekzt/i) }.should raise_spec_error(
|
242
|
+
%Q{/SAMPLE tekzt/i regexp expected within "div" in following template:\n#{rendered}}
|
243
|
+
)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should find unexpected tags and display appropriate message" do
|
247
|
+
expect { rendered.should_not have_tag('div', :text => 'sample text') }.should raise_spec_error(
|
248
|
+
%Q{"sample text" unexpected within "div" in following template:\n#{rendered}\nbut was found.}
|
249
|
+
)
|
250
|
+
expect { rendered.should_not have_tag('div', :text => /SAMPLE text/i) }.should raise_spec_error(
|
251
|
+
%Q{/SAMPLE text/i regexp unexpected within "div" in following template:\n#{rendered}\nbut was found.}
|
252
|
+
)
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
context "mixed matching" do
|
258
|
+
let(:rendered) { asset('special') }
|
259
|
+
|
260
|
+
it "should find tags by count and exact content" do
|
261
|
+
rendered.should have_tag("td", :text => 'a', :count => 3)
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should find tags by count and rough content(regexp)" do
|
265
|
+
rendered.should have_tag("td", :text => /user/, :count => 3)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "should find tags with exact content and additional attributes" do
|
269
|
+
rendered.should have_tag("td", :text => 'a', :with => { :id => "special" })
|
270
|
+
rendered.should_not have_tag("td", :text => 'a', :with => { :id => "other-special" })
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should find tags with rough content and additional attributes" do
|
274
|
+
rendered.should have_tag("td", :text => /user/, :with => { :id => "other-special" })
|
275
|
+
rendered.should_not have_tag("td", :text => /user/, :with => { :id => "special" })
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should find tags with count and additional attributes" do
|
279
|
+
rendered.should have_tag("div", :with => { :class => "one" }, :count => 6)
|
280
|
+
rendered.should have_tag("div", :with => { :class => "two" }, :count => 3)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should find tags with count, exact text and additional attributes" do
|
284
|
+
rendered.should have_tag("div", :with => { :class => "one" }, :count => 3, :text => 'text')
|
285
|
+
rendered.should_not have_tag("div", :with => { :class => "one" }, :count => 5, :text => 'text')
|
286
|
+
rendered.should_not have_tag("div", :with => { :class => "one" }, :count => 3, :text => 'other text')
|
287
|
+
rendered.should_not have_tag("div", :with => { :class => "two" }, :count => 3, :text => 'text')
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should find tags with count, regexp text and additional attributes" do
|
291
|
+
rendered.should have_tag("div", :with => { :class => "one" }, :count => 2, :text => /bla/)
|
292
|
+
rendered.should have_tag("div", :with => { :class => "two" }, :count => 1, :text => /bla/)
|
293
|
+
rendered.should_not have_tag("div", :with => { :class => "one" }, :count => 5, :text => /bla/)
|
294
|
+
rendered.should_not have_tag("div", :with => { :class => "one" }, :count => 6, :text => /other bla/)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
context "nested matching:" do
|
299
|
+
let(:rendered) { asset('ordered_list') }
|
300
|
+
|
301
|
+
it "should find tags" do
|
302
|
+
rendered.should have_tag('ol') {
|
303
|
+
with_tag('li', :text => 'list item 1')
|
304
|
+
with_tag('li', :text => 'list item 2')
|
305
|
+
with_tag('li', :text => 'list item 3')
|
306
|
+
with_tag('li', :count => 3)
|
307
|
+
with_tag('li', :count => 2..3)
|
308
|
+
with_tag('li', :min => 2)
|
309
|
+
with_tag('li', :max => 6)
|
310
|
+
}
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should not find tags" do
|
314
|
+
rendered.should have_tag('ol') {
|
315
|
+
without_tag('div')
|
316
|
+
without_tag('li', :count => 2)
|
317
|
+
without_tag('li', :count => 4..8)
|
318
|
+
without_tag('li', :min => 100)
|
319
|
+
without_tag('li', :max => 2)
|
320
|
+
without_tag('li', :text => 'blabla')
|
321
|
+
without_tag('li', :text => /list item (?!\d)/)
|
322
|
+
}
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should handle do; end" do
|
326
|
+
expect do
|
327
|
+
rendered.should have_tag('ol') do
|
328
|
+
with_tag('div')
|
329
|
+
end
|
330
|
+
end.should raise_spec_error(/have at least 1 element matching "div", found 0/)
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should not find tags and display appropriate message" do
|
334
|
+
ordered_list_regexp = rendered[/<ol.*<\/ol>/m].gsub(/(\n?\s{2,}|\n\s?)/,'\n*\s*')
|
335
|
+
expect {
|
336
|
+
rendered.should have_tag('ol') { with_tag('li'); with_tag('div') }
|
337
|
+
}.should raise_spec_error(/expected following:\n#{ordered_list_regexp}\n\s*to have at least 1 element matching "div", found 0/)
|
338
|
+
expect {
|
339
|
+
rendered.should have_tag('ol') { with_tag('li'); with_tag('li', :count => 10) }
|
340
|
+
}.should raise_spec_error(/expected following:\n#{ordered_list_regexp}\n\s*to have 10 element\(s\) matching "li", found 3/)
|
341
|
+
expect {
|
342
|
+
rendered.should have_tag('ol') { with_tag('li'); with_tag('li', :text => /SAMPLE text/i) }
|
343
|
+
}.should raise_spec_error(/\/SAMPLE text\/i regexp expected within "li" in following template:\n#{ordered_list_regexp}/)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|