Skip to content
This repository
Newer
Older
100644 527 lines (500 sloc) 20.628 kb
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
1 module Capybara
d223d542 »
2010-11-21 Move more of node functionality into subfolder
2 module Node
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
3 module Matchers
a4ed172f »
2010-08-24 Added some documentation for matchers
4
5 ##
6 #
520a42ab »
2010-10-12 Added has_selector? method
7 # Checks if a given selector is on the page or current node.
a4ed172f »
2010-08-24 Added some documentation for matchers
8 #
520a42ab »
2010-10-12 Added has_selector? method
9 # page.has_selector?('p#foo')
10 # page.has_selector?(:xpath, './/p[@id="foo"]')
11 # page.has_selector?(:foo)
a4ed172f »
2010-08-24 Added some documentation for matchers
12 #
13 # By default it will check if the expression occurs at least once,
14 # but a different number can be specified.
15 #
48badb97 » kanerogers
2013-02-09 Update lib/capybara/node/matchers.rb
16 # page.has_selector?('p.foo', :count => 4)
a4ed172f »
2010-08-24 Added some documentation for matchers
17 #
18 # This will check if the expression occurs exactly 4 times.
19 #
20 # It also accepts all options that {Capybara::Node::Finders#all} accepts,
21 # such as :text and :visible.
22 #
520a42ab »
2010-10-12 Added has_selector? method
23 # page.has_selector?('li', :text => 'Horse', :visible => true)
a4ed172f »
2010-08-24 Added some documentation for matchers
24 #
520a42ab »
2010-10-12 Added has_selector? method
25 # has_selector? can also accept XPath expressions generated by the
a4ed172f »
2010-08-24 Added some documentation for matchers
26 # XPath gem:
27 #
fd81c0d2 »
2012-07-13 Document assert_selector and assert_no_selector
28 # page.has_selector?(:xpath, XPath.descendant(:p))
a4ed172f »
2010-08-24 Added some documentation for matchers
29 #
520a42ab »
2010-10-12 Added has_selector? method
30 # @param (see Capybara::Node::Finders#all)
30d5ccc5 » tricknotes
2013-03-29 Fix method comments
31 # @param args
32 # @option args [Integer] :count (nil) Number of times the text should occur
33 # @option args [Integer] :minimum (nil) Minimum number of times the text should occur
34 # @option args [Integer] :maximum (nil) Maximum number of times the text should occur
35 # @option args [Range] :between (nil) Range of times that should contain number of times text occurs
36 # @return [Boolean] If the expression exists
a4ed172f »
2010-08-24 Added some documentation for matchers
37 #
520a42ab »
2010-10-12 Added has_selector? method
38 def has_selector?(*args)
bd69a66a »
2012-07-09 Should not bang!
39 assert_selector(*args)
ad8e0a4c »
2011-08-12 Fix matchers to work with new async stuff
40 rescue Capybara::ExpectationNotMet
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
41 return false
42 end
43
fd81c0d2 »
2012-07-13 Document assert_selector and assert_no_selector
44 ##
45 #
29475f02 »
2012-07-13 Change order of methods
46 # Checks if a given selector is not on the page or current node.
47 # Usage is identical to Capybara::Node::Matchers#has_selector?
48 #
49 # @param (see Capybara::Node::Finders#has_selector?)
50 # @return [Boolean]
51 #
52 def has_no_selector?(*args)
53 assert_no_selector(*args)
54 rescue Capybara::ExpectationNotMet
55 return false
56 end
57
58 ##
59 #
fd81c0d2 »
2012-07-13 Document assert_selector and assert_no_selector
60 # Asserts that a given selector is on the page or current node.
61 #
62 # page.assert_selector('p#foo')
63 # page.assert_selector(:xpath, './/p[@id="foo"]')
64 # page.assert_selector(:foo)
65 #
66 # By default it will check if the expression occurs at least once,
67 # but a different number can be specified.
68 #
69 # page.assert_selector('p#foo', :count => 4)
70 #
828bc2e8 » tmertens
2014-01-17 Allow expectations on element count in Finders#all().
71 # This will check if the expression occurs exactly 4 times. See
72 # {Capybara::Node::Finders#all} for other available result size options.
73 #
74 # If a :count of 0 is specified, it will behave like {#assert_no_selector};
75 # however, use of that method is preferred over this one.
fd81c0d2 »
2012-07-13 Document assert_selector and assert_no_selector
76 #
77 # It also accepts all options that {Capybara::Node::Finders#all} accepts,
78 # such as :text and :visible.
79 #
80 # page.assert_selector('li', :text => 'Horse', :visible => true)
81 #
f3f8f9c1 » abotalov
2013-03-05 add tests, fixes according to review comments
82 # `assert_selector` can also accept XPath expressions generated by the
fd81c0d2 »
2012-07-13 Document assert_selector and assert_no_selector
83 # XPath gem:
84 #
85 # page.assert_selector(:xpath, XPath.descendant(:p))
86 #
87 # @param (see Capybara::Node::Finders#all)
88 # @option options [Integer] :count (nil) Number of times the expression should occur
89 # @raise [Capybara::ExpectationNotMet] If the selector does not exist
90 #
bd69a66a »
2012-07-09 Should not bang!
91 def assert_selector(*args)
04b99e16 » nashby
2013-07-03 support :wait option in `assert_selector` and `has_text?` matcher
92 query = Capybara::Query.new(*args)
93 synchronize(query.wait) do
06c4955e » abotalov
2014-02-16 Use diffferent queries for searching
94 result = query.resolve_for(self)
95 matches_count = Capybara::Helpers.matches_count?(result.size, query.options)
96 unless matches_count && ((result.size > 0) || Capybara::Helpers.expects_none?(query.options))
97 raise Capybara::ExpectationNotMet, result.failure_message
98 end
66b6aed8 » Jonas Nicklas and Nicklas Ramhöj
2012-06-08 Move failure message generatio to result class
99 end
100 return true
101 end
102
a4ed172f »
2010-08-24 Added some documentation for matchers
103 ##
104 #
fd81c0d2 »
2012-07-13 Document assert_selector and assert_no_selector
105 # Asserts that a given selector is not on the page or current node.
106 # Usage is identical to Capybara::Node::Matchers#assert_selector
107 #
828bc2e8 » tmertens
2014-01-17 Allow expectations on element count in Finders#all().
108 # Query options such as :count, :minimum, :maximum, and :between are
109 # considered to be an integral part of the selector. This will return
110 # true, for example, if a page contains 4 anchors but the query expects 5:
111 #
112 # page.assert_no_selector('a', :minimum => 1) # Found, raises Capybara::ExpectationNotMet
113 # page.assert_no_selector('a', :count => 4) # Found, raises Capybara::ExpectationNotMet
114 # page.assert_no_selector('a', :count => 5) # Not Found, returns true
115 #
fd81c0d2 »
2012-07-13 Document assert_selector and assert_no_selector
116 # @param (see Capybara::Node::Finders#assert_selector)
117 # @raise [Capybara::ExpectationNotMet] If the selector exists
118 #
bd69a66a »
2012-07-09 Should not bang!
119 def assert_no_selector(*args)
04b99e16 » nashby
2013-07-03 support :wait option in `assert_selector` and `has_text?` matcher
120 query = Capybara::Query.new(*args)
121 synchronize(query.wait) do
06c4955e » abotalov
2014-02-16 Use diffferent queries for searching
122 result = query.resolve_for(self)
123 matches_count = Capybara::Helpers.matches_count?(result.size, query.options)
124 if matches_count && ((result.size > 0) || Capybara::Helpers.expects_none?(query.options))
125 raise Capybara::ExpectationNotMet, result.negative_failure_message
828bc2e8 » tmertens
2014-01-17 Allow expectations on element count in Finders#all().
126 end
66b6aed8 » Jonas Nicklas and Nicklas Ramhöj
2012-06-08 Move failure message generatio to result class
127 end
128 return true
129 end
316286d0 » gregmolnar
2014-01-29 add refute_selector as alias of assert_no_selector
130 alias_method :refute_selector, :assert_no_selector
131
a4ed172f »
2010-08-24 Added some documentation for matchers
132 ##
133 #
520a42ab »
2010-10-12 Added has_selector? method
134 # Checks if a given XPath expression is on the page or current node.
135 #
136 # page.has_xpath?('.//p[@id="foo"]')
137 #
138 # By default it will check if the expression occurs at least once,
139 # but a different number can be specified.
140 #
141 # page.has_xpath?('.//p[@id="foo"]', :count => 4)
142 #
143 # This will check if the expression occurs exactly 4 times.
144 #
145 # It also accepts all options that {Capybara::Node::Finders#all} accepts,
146 # such as :text and :visible.
147 #
148 # page.has_xpath?('.//li', :text => 'Horse', :visible => true)
149 #
150 # has_xpath? can also accept XPath expressions generate by the
151 # XPath gem:
152 #
153 # xpath = XPath.generate { |x| x.descendant(:p) }
154 # page.has_xpath?(xpath)
155 #
156 # @param [String] path An XPath expression
157 # @param options (see Capybara::Node::Finders#all)
158 # @option options [Integer] :count (nil) Number of times the expression should occur
159 # @return [Boolean] If the expression exists
160 #
161 def has_xpath?(path, options={})
162 has_selector?(:xpath, path, options)
163 end
164
165 ##
166 #
167 # Checks if a given XPath expression is not on the page or current node.
168 # Usage is identical to Capybara::Node::Matchers#has_xpath?
169 #
170 # @param (see Capybara::Node::Finders#has_xpath?)
171 # @return [Boolean]
172 #
173 def has_no_xpath?(path, options={})
174 has_no_selector?(:xpath, path, options)
175 end
176
177 ##
178 #
a4ed172f »
2010-08-24 Added some documentation for matchers
179 # Checks if a given CSS selector is on the page or current node.
180 #
181 # page.has_css?('p#foo')
182 #
183 # By default it will check if the selector occurs at least once,
184 # but a different number can be specified.
185 #
186 # page.has_css?('p#foo', :count => 4)
187 #
188 # This will check if the selector occurs exactly 4 times.
189 #
190 # It also accepts all options that {Capybara::Node::Finders#all} accepts,
191 # such as :text and :visible.
192 #
193 # page.has_css?('li', :text => 'Horse', :visible => true)
194 #
195 # @param [String] path A CSS selector
196 # @param options (see Capybara::Node::Finders#all)
197 # @option options [Integer] :count (nil) Number of times the selector should occur
198 # @return [Boolean] If the selector exists
199 #
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
200 def has_css?(path, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
201 has_selector?(:css, path, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
202 end
203
a4ed172f »
2010-08-24 Added some documentation for matchers
204 ##
205 #
206 # Checks if a given CSS selector is not on the page or current node.
207 # Usage is identical to Capybara::Node::Matchers#has_css?
208 #
209 # @param (see Capybara::Node::Finders#has_css?)
210 # @return [Boolean]
211 #
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
212 def has_no_css?(path, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
213 has_no_selector?(:css, path, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
214 end
215
a4ed172f »
2010-08-24 Added some documentation for matchers
216 ##
217 #
218 # Checks if the page or current node has a link with the given
219 # text or id.
220 #
b38a4991 » dnd
2010-11-18 #has_link? support for checking the href attribute
221 # @param [String] locator The text or id of a link to check for
222 # @param options
223 # @option options [String] :href The value the href attribute must be
224 # @return [Boolean] Whether it exists
a4ed172f »
2010-08-24 Added some documentation for matchers
225 #
b38a4991 » dnd
2010-11-18 #has_link? support for checking the href attribute
226 def has_link?(locator, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
227 has_selector?(:link, locator, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
228 end
229
a4ed172f »
2010-08-24 Added some documentation for matchers
230 ##
231 #
232 # Checks if the page or current node has no link with the given
233 # text or id.
234 #
b38a4991 » dnd
2010-11-18 #has_link? support for checking the href attribute
235 # @param (see Capybara::Node::Finders#has_link?)
a4ed172f »
2010-08-24 Added some documentation for matchers
236 # @return [Boolean] Whether it doesn't exist
237 #
b38a4991 » dnd
2010-11-18 #has_link? support for checking the href attribute
238 def has_no_link?(locator, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
239 has_no_selector?(:link, locator, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
240 end
241
a4ed172f »
2010-08-24 Added some documentation for matchers
242 ##
243 #
244 # Checks if the page or current node has a button with the given
245 # text, value or id.
246 #
247 # @param [String] locator The text, value or id of a button to check for
248 # @return [Boolean] Whether it exists
249 #
e7b72c72 » carols10cents
2013-08-08 Allows passing options through has_button? to has_selector?
250 def has_button?(locator, options={})
251 has_selector?(:button, locator, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
252 end
253
a4ed172f »
2010-08-24 Added some documentation for matchers
254 ##
255 #
256 # Checks if the page or current node has no button with the given
257 # text, value or id.
258 #
259 # @param [String] locator The text, value or id of a button to check for
260 # @return [Boolean] Whether it doesn't exist
261 #
e7b72c72 » carols10cents
2013-08-08 Allows passing options through has_button? to has_selector?
262 def has_no_button?(locator, options={})
263 has_no_selector?(:button, locator, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
264 end
265
a4ed172f »
2010-08-24 Added some documentation for matchers
266 ##
267 #
268 # Checks if the page or current node has a form field with the given
269 # label, name or id.
270 #
271 # For text fields and other textual fields, such as textareas and
272 # HTML5 email/url/etc. fields, it's possible to specify a :with
273 # option to specify the text the field should contain:
274 #
275 # page.has_field?('Name', :with => 'Jonas')
276 #
77c2f30c » grzuy
2012-03-01 Support :type option for #has_field? matcher
277 # It is also possible to filter by the field type attribute:
278 #
279 # page.has_field?('Email', :type => 'email')
280 #
03884431 » yannp
2013-03-07 Possibility to use 'textarea' and 'select' as a :type in Rspec matche…
281 # Note: 'textarea' and 'select' are valid type values, matching the associated tag names.
282 #
a4ed172f »
2010-08-24 Added some documentation for matchers
283 # @param [String] locator The label, name or id of a field to check for
284 # @option options [String] :with The text content of the field
77c2f30c » grzuy
2012-03-01 Support :type option for #has_field? matcher
285 # @option options [String] :type The type attribute of the field
a4ed172f »
2010-08-24 Added some documentation for matchers
286 # @return [Boolean] Whether it exists
287 #
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
288 def has_field?(locator, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
289 has_selector?(:field, locator, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
290 end
291
a4ed172f »
2010-08-24 Added some documentation for matchers
292 ##
293 #
294 # Checks if the page or current node has no form field with the given
295 # label, name or id. See {Capybara::Node::Matchers#has_field?}.
296 #
297 # @param [String] locator The label, name or id of a field to check for
298 # @option options [String] :with The text content of the field
77c2f30c » grzuy
2012-03-01 Support :type option for #has_field? matcher
299 # @option options [String] :type The type attribute of the field
a4ed172f »
2010-08-24 Added some documentation for matchers
300 # @return [Boolean] Whether it doesn't exist
301 #
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
302 def has_no_field?(locator, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
303 has_no_selector?(:field, locator, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
304 end
305
a4ed172f »
2010-08-24 Added some documentation for matchers
306 ##
307 #
308 # Checks if the page or current node has a radio button or
309 # checkbox with the given label, value or id, that is currently
310 # checked.
311 #
312 # @param [String] locator The label, name or id of a checked field
313 # @return [Boolean] Whether it exists
314 #
c6687efb » carols10cents
2013-08-08 Allows passing options through has_checked_field? and has_unchecked_f…
315 def has_checked_field?(locator, options={})
316 has_selector?(:field, locator, options.merge(:checked => true))
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
317 end
318
a4ed172f »
2010-08-24 Added some documentation for matchers
319 ##
320 #
6920eae1 »
2011-03-25 Added have_link, have_checked_field and have_unchecked_field matchers
321 # Checks if the page or current node has no radio button or
322 # checkbox with the given label, value or id, that is currently
323 # checked.
324 #
325 # @param [String] locator The label, name or id of a checked field
18adcd66 » dguzzo
2013-07-23 update documentation grammar typo
326 # @return [Boolean] Whether it doesn't exist
6920eae1 »
2011-03-25 Added have_link, have_checked_field and have_unchecked_field matchers
327 #
c6687efb » carols10cents
2013-08-08 Allows passing options through has_checked_field? and has_unchecked_f…
328 def has_no_checked_field?(locator, options={})
329 has_no_selector?(:field, locator, options.merge(:checked => true))
6920eae1 »
2011-03-25 Added have_link, have_checked_field and have_unchecked_field matchers
330 end
331
332 ##
333 #
a4ed172f »
2010-08-24 Added some documentation for matchers
334 # Checks if the page or current node has a radio button or
335 # checkbox with the given label, value or id, that is currently
336 # unchecked.
337 #
338 # @param [String] locator The label, name or id of an unchecked field
339 # @return [Boolean] Whether it exists
340 #
c6687efb » carols10cents
2013-08-08 Allows passing options through has_checked_field? and has_unchecked_f…
341 def has_unchecked_field?(locator, options={})
342 has_selector?(:field, locator, options.merge(:unchecked => true))
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
343 end
344
a4ed172f »
2010-08-24 Added some documentation for matchers
345 ##
346 #
6920eae1 »
2011-03-25 Added have_link, have_checked_field and have_unchecked_field matchers
347 # Checks if the page or current node has no radio button or
348 # checkbox with the given label, value or id, that is currently
349 # unchecked.
350 #
351 # @param [String] locator The label, name or id of an unchecked field
18adcd66 » dguzzo
2013-07-23 update documentation grammar typo
352 # @return [Boolean] Whether it doesn't exist
6920eae1 »
2011-03-25 Added have_link, have_checked_field and have_unchecked_field matchers
353 #
c6687efb » carols10cents
2013-08-08 Allows passing options through has_checked_field? and has_unchecked_f…
354 def has_no_unchecked_field?(locator, options={})
355 has_no_selector?(:field, locator, options.merge(:unchecked => true))
6920eae1 »
2011-03-25 Added have_link, have_checked_field and have_unchecked_field matchers
356 end
357
358 ##
359 #
a4ed172f »
2010-08-24 Added some documentation for matchers
360 # Checks if the page or current node has a select field with the
361 # given label, name or id.
362 #
363 # It can be specified which option should currently be selected:
364 #
365 # page.has_select?('Language', :selected => 'German')
366 #
367 # For multiple select boxes, several options may be specified:
368 #
369 # page.has_select?('Language', :selected => ['English', 'German'])
370 #
bcdd23d4 » grzuy
2012-03-16 has_select? :options filter matches only exact options
371 # It's also possible to check if the exact set of options exists for
a4ed172f »
2010-08-24 Added some documentation for matchers
372 # this select box:
373 #
6089acc3 » grzuy
2012-03-22 has_select? supports matching a partial options set
374 # page.has_select?('Language', :options => ['English', 'German', 'Spanish'])
375 #
376 # You can also check for a partial set of options:
377 #
378 # page.has_select?('Language', :with_options => ['English', 'German'])
a4ed172f »
2010-08-24 Added some documentation for matchers
379 #
380 # @param [String] locator The label, name or id of a select box
381 # @option options [Array] :options Options which should be contained in this select box
6089acc3 » grzuy
2012-03-22 has_select? supports matching a partial options set
382 # @option options [Array] :with_options Partial set of options which should be contained in this select box
a4ed172f »
2010-08-24 Added some documentation for matchers
383 # @option options [String, Array] :selected Options which should be selected
384 # @return [Boolean] Whether it exists
385 #
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
386 def has_select?(locator, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
387 has_selector?(:select, locator, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
388 end
389
a4ed172f »
2010-08-24 Added some documentation for matchers
390 ##
391 #
392 # Checks if the page or current node has no select field with the
393 # given label, name or id. See {Capybara::Node::Matchers#has_select?}.
394 #
395 # @param (see Capybara::Node::Matchers#has_select?)
396 # @return [Boolean] Whether it doesn't exist
397 #
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
398 def has_no_select?(locator, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
399 has_no_selector?(:select, locator, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
400 end
401
a4ed172f »
2010-08-24 Added some documentation for matchers
402 ##
403 #
404 # Checks if the page or current node has a table with the given id
770adc26 » abotalov
2012-12-23 Update docs according to History.md
405 # or caption:
a4ed172f »
2010-08-24 Added some documentation for matchers
406 #
770adc26 » abotalov
2012-12-23 Update docs according to History.md
407 # page.has_table?('People')
a4ed172f »
2010-08-24 Added some documentation for matchers
408 #
409 # @param [String] locator The id or caption of a table
410 # @return [Boolean] Whether it exist
411 #
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
412 def has_table?(locator, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
413 has_selector?(:table, locator, options)
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
414 end
415
a4ed172f »
2010-08-24 Added some documentation for matchers
416 ##
417 #
418 # Checks if the page or current node has no table with the given id
668eeeed »
2010-08-27 Some documentation touch-ups
419 # or caption. See {Capybara::Node::Matchers#has_table?}.
a4ed172f »
2010-08-24 Added some documentation for matchers
420 #
421 # @param (see Capybara::Node::Matchers#has_table?)
422 # @return [Boolean] Whether it doesn't exist
423 #
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
424 def has_no_table?(locator, options={})
fd7cf4a4 » Adam McCrea
2011-08-27 Use custom selectors in matchers
425 has_no_selector?(:table, locator, options)
9d6aebde » jfirebaugh
2010-12-23 Ensure that matchers work correctly after actions, closes #171
426 end
9fb05c9c » mkdynamic
2011-10-16 add has_text matcher based on Element#text
427
06c4955e » abotalov
2014-02-16 Use diffferent queries for searching
428 ##
429 # Asserts that the page or current node has the given text content,
430 # ignoring any HTML tags.
431 #
432 # @!macro text_query_params
433 # @overload $0(type, text, options = {})
434 # @param [:all, :visible] type Whether to check for only visible or all text
435 # @param [String, Regexp] text The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it.
436 # @option options [Integer] :count (nil) Number of times the text is expected to occur
437 # @option options [Integer] :minimum (nil) Minimum number of times the text is expected to occur
438 # @option options [Integer] :maximum (nil) Maximum number of times the text is expected to occur
439 # @option options [Range] :between (nil) Range of times that is expected to contain number of times text occurs
440 # @option options [Numeric] :wait (Capybara.default_wait_time) Time that Capybara will wait for text to eq/match given string/regexp argument
441 # @overload $0(text, options = {})
442 # @param [String, Regexp] text The string/regexp to check for. If it's a string, text is expected to include it. If it's a regexp, text is expected to match it.
443 # @option options [Integer] :count (nil) Number of times the text is expected to occur
444 # @option options [Integer] :minimum (nil) Minimum number of times the text is expected to occur
445 # @option options [Integer] :maximum (nil) Maximum number of times the text is expected to occur
446 # @option options [Range] :between (nil) Range of times that is expected to contain number of times text occurs
447 # @option options [Numeric] :wait (Capybara.default_wait_time) Time that Capybara will wait for text to eq/match given string/regexp argument
448 # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
449 # @return [true]
450 #
451 def assert_text(*args)
452 query = Capybara::Queries::TextQuery.new(*args)
453 synchronize(query.wait) do
454 count = query.resolve_for(self)
455 matches_count = Capybara::Helpers.matches_count?(count, query.options)
456 unless matches_count && ((count > 0) || Capybara::Helpers.expects_none?(query.options))
457 raise Capybara::ExpectationNotMet, query.failure_message
458 end
459 end
460 return true
d791d5d7 »
2012-07-12 Preserve notion of equality for nodes. closes #542
461 end
462
06c4955e » abotalov
2014-02-16 Use diffferent queries for searching
463 ##
464 # Asserts that the page or current node doesn't have the given text content,
465 # ignoring any HTML tags.
466 #
467 # @macro text_query_params
468 # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
469 # @return [true]
470 #
471 def assert_no_text(*args)
472 query = Capybara::Queries::TextQuery.new(*args)
473 synchronize(query.wait) do
474 count = query.resolve_for(self)
475 matches_count = Capybara::Helpers.matches_count?(count, query.options)
476 if matches_count && ((count > 0) || Capybara::Helpers.expects_none?(query.options))
477 raise Capybara::ExpectationNotMet, query.negative_failure_message
478 end
479 end
480 return true
481 end
6de89c10 »
2012-01-02 rows option has been removed in xpath gem
482
06c4955e » abotalov
2014-02-16 Use diffferent queries for searching
483 ##
484 # Checks if the page or current node has the given text content,
485 # ignoring any HTML tags.
486 #
487 # Whitespaces are normalized in both node's text and passed text parameter.
488 # Note that whitespace isn't normalized in passed regexp as normalizing whitespace
489 # in regexp isn't easy and doesn't seem to be worth it.
490 #
491 # By default it will check if the text occurs at least once,
492 # but a different number can be specified.
493 #
494 # page.has_text?('lorem ipsum', between: 2..4)
495 #
496 # This will check if the text occurs from 2 to 4 times.
497 #
498 # @macro text_query_params
499 # @return [Boolean] Whether it exists
500 #
501 def has_text?(*args)
502 assert_text(*args)
503 rescue Capybara::ExpectationNotMet
504 return false
505 end
506 alias_method :has_content?, :has_text?
415e2db7 »
2013-03-17 Refactor and document
507
06c4955e » abotalov
2014-02-16 Use diffferent queries for searching
508 ##
509 # Checks if the page or current node does not have the given text
510 # content, ignoring any HTML tags and normalizing whitespace.
511 #
512 # @macro text_query_params
513 # @return [Boolean] Whether it doesn't exist
514 #
515 def has_no_text?(*args)
516 assert_no_text(*args)
517 rescue Capybara::ExpectationNotMet
518 return false
519 end
520 alias_method :has_no_content?, :has_no_text?
521
522 def ==(other)
523 self.eql?(other) || (other.respond_to?(:base) && base == other.base)
3783237c » abotalov
2013-03-04 Add count options to has_text
524 end
8bf63ee8 »
2010-07-10 Split node class into finders, matchers and actions
525 end
526 end
527 end
Something went wrong with that request. Please try again.