capybara 2.9.2 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +10 -1
  3. data/README.md +34 -27
  4. data/lib/capybara.rb +2 -2
  5. data/lib/capybara/node/actions.rb +3 -3
  6. data/lib/capybara/node/base.rb +2 -2
  7. data/lib/capybara/node/element.rb +1 -1
  8. data/lib/capybara/node/finders.rb +37 -32
  9. data/lib/capybara/node/matchers.rb +187 -171
  10. data/lib/capybara/queries/selector_query.rb +11 -14
  11. data/lib/capybara/rack_test/driver.rb +3 -3
  12. data/lib/capybara/rails.rb +1 -1
  13. data/lib/capybara/rspec/features.rb +1 -1
  14. data/lib/capybara/rspec/matchers.rb +31 -22
  15. data/lib/capybara/selector.rb +2 -2
  16. data/lib/capybara/selector/selector.rb +22 -0
  17. data/lib/capybara/session.rb +4 -4
  18. data/lib/capybara/spec/session/accept_alert_spec.rb +4 -4
  19. data/lib/capybara/spec/session/accept_confirm_spec.rb +1 -1
  20. data/lib/capybara/spec/session/accept_prompt_spec.rb +5 -5
  21. data/lib/capybara/spec/session/all_spec.rb +27 -27
  22. data/lib/capybara/spec/session/assert_current_path.rb +2 -2
  23. data/lib/capybara/spec/session/assert_selector.rb +28 -28
  24. data/lib/capybara/spec/session/assert_text.rb +20 -20
  25. data/lib/capybara/spec/session/assert_title.rb +2 -2
  26. data/lib/capybara/spec/session/attach_file_spec.rb +2 -2
  27. data/lib/capybara/spec/session/check_spec.rb +5 -5
  28. data/lib/capybara/spec/session/choose_spec.rb +4 -4
  29. data/lib/capybara/spec/session/click_button_spec.rb +18 -5
  30. data/lib/capybara/spec/session/click_link_or_button_spec.rb +6 -6
  31. data/lib/capybara/spec/session/click_link_spec.rb +13 -13
  32. data/lib/capybara/spec/session/current_url_spec.rb +2 -2
  33. data/lib/capybara/spec/session/dismiss_confirm_spec.rb +1 -1
  34. data/lib/capybara/spec/session/dismiss_prompt_spec.rb +1 -1
  35. data/lib/capybara/spec/session/element/matches_selector_spec.rb +15 -8
  36. data/lib/capybara/spec/session/evaluate_script_spec.rb +1 -1
  37. data/lib/capybara/spec/session/execute_script_spec.rb +2 -2
  38. data/lib/capybara/spec/session/fill_in_spec.rb +30 -30
  39. data/lib/capybara/spec/session/find_button_spec.rb +5 -5
  40. data/lib/capybara/spec/session/find_by_id_spec.rb +2 -2
  41. data/lib/capybara/spec/session/find_field_spec.rb +11 -7
  42. data/lib/capybara/spec/session/find_link_spec.rb +2 -2
  43. data/lib/capybara/spec/session/find_spec.rb +52 -48
  44. data/lib/capybara/spec/session/first_spec.rb +9 -9
  45. data/lib/capybara/spec/session/go_back_spec.rb +1 -1
  46. data/lib/capybara/spec/session/go_forward_spec.rb +1 -1
  47. data/lib/capybara/spec/session/has_button_spec.rb +12 -12
  48. data/lib/capybara/spec/session/has_css_spec.rb +73 -73
  49. data/lib/capybara/spec/session/has_current_path_spec.rb +2 -2
  50. data/lib/capybara/spec/session/has_field_spec.rb +78 -68
  51. data/lib/capybara/spec/session/has_link_spec.rb +8 -8
  52. data/lib/capybara/spec/session/has_select_spec.rb +70 -61
  53. data/lib/capybara/spec/session/has_selector_spec.rb +28 -28
  54. data/lib/capybara/spec/session/has_text_spec.rb +6 -6
  55. data/lib/capybara/spec/session/has_title_spec.rb +2 -2
  56. data/lib/capybara/spec/session/has_xpath_spec.rb +26 -26
  57. data/lib/capybara/spec/session/headers.rb +1 -1
  58. data/lib/capybara/spec/session/html_spec.rb +3 -3
  59. data/lib/capybara/spec/session/node_spec.rb +15 -15
  60. data/lib/capybara/spec/session/reset_session_spec.rb +4 -4
  61. data/lib/capybara/spec/session/response_code.rb +1 -1
  62. data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +3 -3
  63. data/lib/capybara/spec/session/screenshot_spec.rb +1 -1
  64. data/lib/capybara/spec/session/select_spec.rb +30 -30
  65. data/lib/capybara/spec/session/uncheck_spec.rb +2 -2
  66. data/lib/capybara/spec/session/unselect_spec.rb +14 -14
  67. data/lib/capybara/spec/session/visit_spec.rb +2 -2
  68. data/lib/capybara/spec/session/within_frame_spec.rb +2 -2
  69. data/lib/capybara/spec/session/within_spec.rb +6 -6
  70. data/lib/capybara/spec/spec_helper.rb +1 -1
  71. data/lib/capybara/spec/test_app.rb +1 -1
  72. data/lib/capybara/spec/views/form.erb +1 -0
  73. data/lib/capybara/version.rb +1 -1
  74. data/spec/basic_node_spec.rb +5 -5
  75. data/spec/capybara_spec.rb +1 -1
  76. data/spec/dsl_spec.rb +1 -1
  77. data/spec/rack_test_spec.rb +7 -7
  78. data/spec/rspec/matchers_spec.rb +6 -6
  79. data/spec/rspec_spec.rb +1 -1
  80. data/spec/selector_spec.rb +13 -0
  81. data/spec/selenium_firefox_spec.rb +1 -1
  82. data/spec/selenium_spec_chrome.rb +1 -1
  83. data/spec/shared_selenium_session.rb +10 -10
  84. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db09e9654963783c82ada646c4814ddc80c2ddb7
4
- data.tar.gz: 17cd310533f903c6074ab255346e37c40046f3e9
3
+ metadata.gz: 0e04794fbb1724e14269beeff9388b53a6f8603b
4
+ data.tar.gz: 377ee4cf8d61e2c1420ad7bc44b400e1f991ac30
5
5
  SHA512:
6
- metadata.gz: e20f671c5012aa0edcc8b51e9cd75fcac85ef8e8d784131e12cba87a1d89d6464f64d77f529787803b702d628022a48bf114ad37550995c354c409e25bb2f0b8
7
- data.tar.gz: 3257116b6f9eb2584a154aecdc82342a1486a420eff1ebccb9df680ad0816d1f7a15aa1bc5aa8b321dc09471c6c991f035c35aa1c731fa17aa2d6827135a9667
6
+ metadata.gz: afcaeaf6eb1aa0690b74ffa21acbaea6282b2ed0aba4382bc926ec6a6fbdd43bff3facc886e2d5558f7cf9af167a8278ef9ded0e946dbc9052168fc6583e94f4
7
+ data.tar.gz: b6be9f0cd07cc125a46f14c9a322b789547eb875252a10d217b4c1410080bf4be0c146c83361846a17a114b1c648416dca1a3301eefdb26087f215a0fa120872
data/History.md CHANGED
@@ -1,9 +1,18 @@
1
+ #2.10.0
2
+ Release date: 2016-10-05
3
+
4
+ ### Added
5
+ * Select `<button>` elements with descendant images with `alt` attributes matching the locator [Ian Lesperance]
6
+ * Locator string is optional in selector based matchers [Thomas Walpole]
7
+ * Selectors can specify their default visible setting [Thomas Walpole]
8
+ * Selector based finders and matchers can be passed a block to filter the results within the retry behavior [Thomas Walpole]
9
+
1
10
  #Version 2.9.2
2
11
  Release date: 2016-09-29
3
12
 
4
13
  ### Fixed
5
14
  * :label built-in selector finds nested label/control by control id if the label has no 'for' attribute [Thomas Walpole]
6
- * Warning issued if an unknown selector type is specified
15
+ * Warning issued if an unknown selector type is specified [Thomas Walpole]
7
16
 
8
17
  #Version 2.9.1
9
18
  Release date: 2016-09-23
data/README.md CHANGED
@@ -107,8 +107,8 @@ You can use the Capybara DSL in your steps, like so:
107
107
  ```ruby
108
108
  When /I sign in/ do
109
109
  within("#session") do
110
- fill_in 'Email', :with => 'user@example.com'
111
- fill_in 'Password', :with => 'password'
110
+ fill_in 'Email', with: 'user@example.com'
111
+ fill_in 'Password', with: 'password'
112
112
  end
113
113
  click_button 'Sign in'
114
114
  end
@@ -150,14 +150,14 @@ You can now write your specs like so:
150
150
  ```ruby
151
151
  describe "the signin process", :type => :feature do
152
152
  before :each do
153
- User.make(:email => 'user@example.com', :password => 'password')
153
+ User.make(email: 'user@example.com', password: 'password')
154
154
  end
155
155
 
156
156
  it "signs me in" do
157
157
  visit '/sessions/new'
158
158
  within("#session") do
159
- fill_in 'Email', :with => 'user@example.com'
160
- fill_in 'Password', :with => 'password'
159
+ fill_in 'Email', with: 'user@example.com'
160
+ fill_in 'Password', with: 'password'
161
161
  end
162
162
  click_button 'Sign in'
163
163
  expect(page).to have_content 'Success'
@@ -165,12 +165,12 @@ describe "the signin process", :type => :feature do
165
165
  end
166
166
  ```
167
167
 
168
- Use `:js => true` to switch to the `Capybara.javascript_driver`
168
+ Use `js: true` to switch to the `Capybara.javascript_driver`
169
169
  (`:selenium` by default), or provide a `:driver` option to switch
170
170
  to one specific driver. For example:
171
171
 
172
172
  ```ruby
173
- describe 'some stuff which requires js', :js => true do
173
+ describe 'some stuff which requires js', js: true do
174
174
  it 'will use the default js driver'
175
175
  it 'will switch to one specific driver', :driver => :webkit
176
176
  end
@@ -181,26 +181,26 @@ Capybara also comes with a built in DSL for creating descriptive acceptance test
181
181
  ```ruby
182
182
  feature "Signing in" do
183
183
  background do
184
- User.make(:email => 'user@example.com', :password => 'caplin')
184
+ User.make(email: 'user@example.com', password: 'caplin')
185
185
  end
186
186
 
187
187
  scenario "Signing in with correct credentials" do
188
188
  visit '/sessions/new'
189
189
  within("#session") do
190
- fill_in 'Email', :with => 'user@example.com'
191
- fill_in 'Password', :with => 'caplin'
190
+ fill_in 'Email', with: 'user@example.com'
191
+ fill_in 'Password', with: 'caplin'
192
192
  end
193
193
  click_button 'Sign in'
194
194
  expect(page).to have_content 'Success'
195
195
  end
196
196
 
197
- given(:other_user) { User.make(:email => 'other@example.com', :password => 'rous') }
197
+ given(:other_user) { User.make(email: 'other@example.com', password: 'rous') }
198
198
 
199
199
  scenario "Signing in as another user" do
200
200
  visit '/sessions/new'
201
201
  within("#session") do
202
- fill_in 'Email', :with => other_user.email
203
- fill_in 'Password', :with => other_user.password
202
+ fill_in 'Email', with: other_user.email
203
+ fill_in 'Password', with: other_user.password
204
204
  end
205
205
  click_button 'Sign in'
206
206
  expect(page).to have_content 'Invalid email or password'
@@ -308,7 +308,7 @@ Capybara.default_driver = :selenium
308
308
 
309
309
  However, if you are using RSpec or Cucumber, you may instead want to consider
310
310
  leaving the faster `:rack_test` as the __default_driver__, and marking only those
311
- tests that require a JavaScript-capable driver using `:js => true` or
311
+ tests that require a JavaScript-capable driver using `js: true` or
312
312
  `@javascript`, respectively. By default, JavaScript tests are run using the
313
313
  `:selenium` driver. You can change this by setting
314
314
  `Capybara.javascript_driver`.
@@ -344,7 +344,7 @@ RackTest can be configured with a set of headers like this:
344
344
 
345
345
  ```ruby
346
346
  Capybara.register_driver :rack_test do |app|
347
- Capybara::RackTest::Driver.new(app, :headers => { 'HTTP_USER_AGENT' => 'Capybara' })
347
+ Capybara::RackTest::Driver.new(app, headers: { 'HTTP_USER_AGENT' => 'Capybara' })
348
348
  end
349
349
  ```
350
350
 
@@ -448,14 +448,14 @@ click_on('Button Value')
448
448
  There are a number of tools for interacting with form elements:
449
449
 
450
450
  ```ruby
451
- fill_in('First Name', :with => 'John')
452
- fill_in('Password', :with => 'Seekrit')
453
- fill_in('Description', :with => 'Really Long Text...')
451
+ fill_in('First Name', with: 'John')
452
+ fill_in('Password', with: 'Seekrit')
453
+ fill_in('Description', with: 'Really Long Text...')
454
454
  choose('A Radio Button')
455
455
  check('A Checkbox')
456
456
  uncheck('A Checkbox')
457
457
  attach_file('Image', '/path/to/image.jpg')
458
- select('Option', :from => 'Select Box')
458
+ select('Option', from: 'Select Box')
459
459
  ```
460
460
 
461
461
  ### <a name="querying"></a>Querying
@@ -504,6 +504,13 @@ find("#overlay").find("h1").click
504
504
  all('a').each { |a| a[:href] }
505
505
  ```
506
506
 
507
+ If you need to find elements by additional attributes/properties you can also pass a filter block, which will be checked inside the normal waiting behavior.
508
+ If you find yourself needing to use this a lot you may be better off adding a [custom selector](http://www.rubydoc.info/github/jnicklas/capybara/Capybara#add_selector-class_method) or [adding a filter to an existing selector](http://www.rubydoc.info/github/jnicklas/capybara/Capybara#modify_selector-class_method).
509
+
510
+ ```ruby
511
+ find_field('First Name'){ |el| el['data-xyz'] == '123' }
512
+ ````
513
+
507
514
  **Note**: `find` will wait for an element to appear on the page, as explained in the
508
515
  Ajax section. If the element does not appear it will raise an error.
509
516
 
@@ -525,11 +532,11 @@ method. Optionally you can specify which kind of selector to use.
525
532
 
526
533
  ```ruby
527
534
  within("li#employee") do
528
- fill_in 'Name', :with => 'Jimmy'
535
+ fill_in 'Name', with: 'Jimmy'
529
536
  end
530
537
 
531
538
  within(:xpath, "//li[@id='employee']") do
532
- fill_in 'Name', :with => 'Jimmy'
539
+ fill_in 'Name', with: 'Jimmy'
533
540
  end
534
541
  ```
535
542
 
@@ -539,11 +546,11 @@ specific table, identified by either id or text of the table's caption tag.
539
546
 
540
547
  ```ruby
541
548
  within_fieldset('Employee') do
542
- fill_in 'Name', :with => 'Jimmy'
549
+ fill_in 'Name', with: 'Jimmy'
543
550
  end
544
551
 
545
552
  within_table('Employee') do
546
- fill_in 'Name', :with => 'Jimmy'
553
+ fill_in 'Name', with: 'Jimmy'
547
554
  end
548
555
  ```
549
556
 
@@ -782,8 +789,8 @@ module MyModule
782
789
 
783
790
  def login!
784
791
  within(:xpath, "//form[@id='session']") do
785
- fill_in 'Email', :with => 'user@example.com'
786
- fill_in 'Password', :with => 'password'
792
+ fill_in 'Email', with: 'user@example.com'
793
+ fill_in 'Password', with: 'password'
787
794
  end
788
795
  click_button 'Sign in'
789
796
  end
@@ -853,8 +860,8 @@ require 'capybara'
853
860
 
854
861
  session = Capybara::Session.new(:webkit, my_rack_app)
855
862
  session.within("form#session") do
856
- session.fill_in 'Email', :with => 'user@example.com'
857
- session.fill_in 'Password', :with => 'password'
863
+ session.fill_in 'Email', with: 'user@example.com'
864
+ session.fill_in 'Password', with: 'password'
858
865
  end
859
866
  session.click_button 'Sign in'
860
867
  ```
@@ -225,7 +225,7 @@ module Capybara
225
225
  # HTML
226
226
  #
227
227
  # node.find('#projects').text # => 'Projects'
228
- # node.has_selector?('li#home', :text => 'Home')
228
+ # node.has_selector?('li#home', text: 'Home')
229
229
  # node.has_selector?('#projects')
230
230
  # node.find('ul').find('li:first-child').text # => 'Home'
231
231
  #
@@ -475,7 +475,7 @@ end
475
475
 
476
476
  Capybara.register_server :webrick do |app, port, host|
477
477
  require 'rack/handler/webrick'
478
- Rack::Handler::WEBrick.run(app, :Host => host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
478
+ Rack::Handler::WEBrick.run(app, Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log::new(nil, 0))
479
479
  end
480
480
 
481
481
  Capybara.register_server :puma do |app, port, host|
@@ -62,7 +62,7 @@ module Capybara
62
62
  # Locate a text field or text area and fill it in with the given text
63
63
  # The field can be found via its name, id or label text.
64
64
  #
65
- # page.fill_in 'Name', :with => 'Bob'
65
+ # page.fill_in 'Name', with: 'Bob'
66
66
  #
67
67
  #
68
68
  # @overload fill_in([locator], options={})
@@ -206,7 +206,7 @@ module Capybara
206
206
  # one option.
207
207
  # The select box can be found via its name, id or label text. The option can be found by its text.
208
208
  #
209
- # page.select 'March', :from => 'Month'
209
+ # page.select 'March', from: 'Month'
210
210
  #
211
211
  # @macro waiting_behavior
212
212
  #
@@ -228,7 +228,7 @@ module Capybara
228
228
  # box is a multiple select, +unselect+ can be called multiple times to unselect more than
229
229
  # one option. The select box can be found via its name, id or label text.
230
230
  #
231
- # page.unselect 'March', :from => 'Month'
231
+ # page.unselect 'March', from: 'Month'
232
232
  #
233
233
  # @macro waiting_behavior
234
234
  #
@@ -17,9 +17,9 @@ module Capybara
17
17
  #
18
18
  # session = Capybara::Session.new(:rack_test, my_app)
19
19
  # session.visit('/')
20
- # session.fill_in('Foo', :with => 'Bar') # from Capybara::Node::Actions
20
+ # session.fill_in('Foo', with: 'Bar') # from Capybara::Node::Actions
21
21
  # bar = session.find('#bar') # from Capybara::Node::Finders
22
- # bar.select('Baz', :from => 'Quox') # from Capybara::Node::Actions
22
+ # bar.select('Baz', from: 'Quox') # from Capybara::Node::Actions
23
23
  # session.has_css?('#foobar') # from Capybara::Node::Matchers
24
24
  #
25
25
  class Base
@@ -10,7 +10,7 @@ module Capybara
10
10
  # session = Capybara::Session.new(:rack_test, my_app)
11
11
  #
12
12
  # bar = session.find('#bar') # from Capybara::Node::Finders
13
- # bar.select('Baz', :from => 'Quox') # from Capybara::Node::Actions
13
+ # bar.select('Baz', from: 'Quox') # from Capybara::Node::Actions
14
14
  #
15
15
  # {Capybara::Node::Element} also has access to HTML attributes and other properties of the
16
16
  # element:
@@ -19,7 +19,7 @@ module Capybara
19
19
  #
20
20
  # page.find('#foo').find('.bar')
21
21
  # page.find(:xpath, '//div[contains(., "bar")]')
22
- # page.find('li', :text => 'Quox').click_link('Delete')
22
+ # page.find('li', text: 'Quox').click_link('Delete')
23
23
  #
24
24
  # @param (see Capybara::Node::Finders#all)
25
25
  #
@@ -28,8 +28,8 @@ module Capybara
28
28
  # @return [Capybara::Node::Element] The found element
29
29
  # @raise [Capybara::ElementNotFound] If the element can't be found before time expires
30
30
  #
31
- def find(*args)
32
- query = Capybara::Queries::SelectorQuery.new(*args)
31
+ def find(*args, &optional_filter_block)
32
+ query = Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
33
33
  synchronize(query.wait) do
34
34
  if (query.match == :smart or query.match == :prefer_exact) and query.supports_exact?
35
35
  result = query.resolve_for(self, true)
@@ -74,9 +74,9 @@ module Capybara
74
74
  # @return [Capybara::Node::Element] The found element
75
75
  #
76
76
 
77
- def find_field(locator=nil, options={})
77
+ def find_field(locator=nil, options={}, &optional_filter_block)
78
78
  locator, options = nil, locator if locator.is_a? Hash
79
- find(:field, locator, options)
79
+ find(:field, locator, options, &optional_filter_block)
80
80
  end
81
81
  alias_method :field_labeled, :find_field
82
82
 
@@ -96,9 +96,9 @@ module Capybara
96
96
  # @option options [String, Array<String>] class Match links that match the class(es) provided
97
97
  # @return [Capybara::Node::Element] The found element
98
98
  #
99
- def find_link(locator=nil, options={})
99
+ def find_link(locator=nil, options={}, &optional_filter_block)
100
100
  locator, options = nil, locator if locator.is_a? Hash
101
- find(:link, locator, options)
101
+ find(:link, locator, options, &optional_filter_block)
102
102
  end
103
103
 
104
104
  ##
@@ -125,9 +125,9 @@ module Capybara
125
125
  # @option options [String, Array<String>] class Match links that match the class(es) provided
126
126
  # @return [Capybara::Node::Element] The found element
127
127
  #
128
- def find_button(locator=nil, options={})
128
+ def find_button(locator=nil, options={}, &optional_filter_block)
129
129
  locator, options = nil, locator if locator.is_a? Hash
130
- find(:button, locator, options)
130
+ find(:button, locator, options, &optional_filter_block)
131
131
  end
132
132
 
133
133
  ##
@@ -140,11 +140,12 @@ module Capybara
140
140
  #
141
141
  # @return [Capybara::Node::Element] The found element
142
142
  #
143
- def find_by_id(id, options={})
144
- find(:id, id, options)
143
+ def find_by_id(id, options={}, &optional_filter_block)
144
+ find(:id, id, options, &optional_filter_block)
145
145
  end
146
146
 
147
147
  ##
148
+ # @!method all([kind = Capybara.default_selector], locator = nil, options = {})
148
149
  #
149
150
  # Find all elements on the page matching the given selector
150
151
  # and options.
@@ -168,42 +169,45 @@ module Capybara
168
169
  # The set of found elements can further be restricted by specifying
169
170
  # options. It's possible to select elements by their text or visibility:
170
171
  #
171
- # page.all('a', :text => 'Home')
172
- # page.all('#menu li', :visible => true)
172
+ # page.all('a', text: 'Home')
173
+ # page.all('#menu li', visible: true)
173
174
  #
174
175
  # By default if no elements are found, an empty array is returned;
175
176
  # however, expectations can be set on the number of elements to be found which
176
177
  # will trigger Capybara's waiting behavior for the expectations to match.The
177
178
  # expectations can be set using
178
179
  #
179
- # page.assert_selector('p#foo', :count => 4)
180
- # page.assert_selector('p#foo', :maximum => 10)
181
- # page.assert_selector('p#foo', :minimum => 1)
182
- # page.assert_selector('p#foo', :between => 1..10)
180
+ # page.assert_selector('p#foo', count: 4)
181
+ # page.assert_selector('p#foo', maximum: 10)
182
+ # page.assert_selector('p#foo', minimum: 1)
183
+ # page.assert_selector('p#foo', between: 1..10)
183
184
  #
184
185
  # See {Capybara::Helpers#matches_count?} for additional information about
185
186
  # count matching.
186
187
  #
187
- # @overload all([kind], locator, options)
188
- # @param [:css, :xpath] kind The type of selector
189
- # @param [String] locator The selector
190
- # @option options [String, Regexp] text Only find elements which contain this text or match this regexp
191
- # @option options [Boolean, Symbol] visible Only find elements with the specified visibility:
188
+ # @param [Symbol] kind Optional selector type (:css, :xpath, :field, etc.) - Defaults to Capybara.default_selector
189
+ # @param [String] locator The selector
190
+ # @option options [String, Regexp] text Only find elements which contain this text or match this regexp
191
+ # @option options [Boolean, Symbol] visible Only find elements with the specified visibility:
192
192
  # * true - only finds visible elements.
193
193
  # * false - finds invisible _and_ visible elements.
194
194
  # * :all - same as false; finds visible and invisible elements.
195
195
  # * :hidden - only finds invisible elements.
196
196
  # * :visible - same as true; only finds visible elements.
197
- # @option options [Integer] count Exact number of matches that are expected to be found
198
- # @option options [Integer] maximum Maximum number of matches that are expected to be found
199
- # @option options [Integer] minimum Minimum number of matches that are expected to be found
200
- # @option options [Range] between Number of matches found must be within the given range
201
- # @option options [Boolean] exact Control whether `is` expressions in the given XPath match exactly or partially
202
- # @option options [Integer] wait (Capybara.default_max_wait_time) The time to wait for element count expectations to become true
197
+ # @option options [Integer] count Exact number of matches that are expected to be found
198
+ # @option options [Integer] maximum Maximum number of matches that are expected to be found
199
+ # @option options [Integer] minimum Minimum number of matches that are expected to be found
200
+ # @option options [Range] between Number of matches found must be within the given range
201
+ # @option options [Boolean] exact Control whether `is` expressions in the given XPath match exactly or partially
202
+ # @option options [Integer] wait (Capybara.default_max_wait_time) The time to wait for element count expectations to become true
203
+ # @overload all([kind = Capybara.default_selector], locator = nil, options = {})
204
+ # @overload all([kind = Capybara.default_selector], locator = nil, options = {}, &filter_block)
205
+ # @yieldparam element [Capybara::Node::Element] The element being considered for inclusion in the results
206
+ # @yieldreturn [Boolean] Should the element be considered in the results?
203
207
  # @return [Capybara::Result] A collection of found elements
204
208
  #
205
- def all(*args)
206
- query = Capybara::Queries::SelectorQuery.new(*args)
209
+ def all(*args, &optional_filter_block)
210
+ query = Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
207
211
  synchronize(query.wait) do
208
212
  result = query.resolve_for(self)
209
213
  raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count?
@@ -227,15 +231,16 @@ module Capybara
227
231
  # @param [Hash] options Additional options; see {#all}
228
232
  # @return [Capybara::Node::Element] The found element or nil
229
233
  #
230
- def first(*args)
234
+ def first(*args, &optional_filter_block)
231
235
  if Capybara.wait_on_first_by_default
232
236
  options = if args.last.is_a?(Hash) then args.pop.dup else {} end
233
237
  args.push({minimum: 1}.merge(options))
234
238
  end
235
- all(*args).first
239
+ all(*args, &optional_filter_block).first
236
240
  rescue Capybara::ExpectationNotMet
237
241
  nil
238
242
  end
243
+
239
244
  end
240
245
  end
241
246
  end
@@ -14,14 +14,14 @@ module Capybara
14
14
  # By default it will check if the expression occurs at least once,
15
15
  # but a different number can be specified.
16
16
  #
17
- # page.has_selector?('p.foo', :count => 4)
17
+ # page.has_selector?('p.foo', count: 4)
18
18
  #
19
19
  # This will check if the expression occurs exactly 4 times.
20
20
  #
21
21
  # It also accepts all options that {Capybara::Node::Finders#all} accepts,
22
22
  # such as :text and :visible.
23
23
  #
24
- # page.has_selector?('li', :text => 'Horse', :visible => true)
24
+ # page.has_selector?('li', text: 'Horse', visible: true)
25
25
  #
26
26
  # has_selector? can also accept XPath expressions generated by the
27
27
  # XPath gem:
@@ -36,8 +36,8 @@ module Capybara
36
36
  # @option args [Range] :between (nil) Range of times that should contain number of times text occurs
37
37
  # @return [Boolean] If the expression exists
38
38
  #
39
- def has_selector?(*args)
40
- assert_selector(*args)
39
+ def has_selector?(*args, &optional_filter_block)
40
+ assert_selector(*args, &optional_filter_block)
41
41
  rescue Capybara::ExpectationNotMet
42
42
  return false
43
43
  end
@@ -50,83 +50,12 @@ module Capybara
50
50
  # @param (see Capybara::Node::Finders#has_selector?)
51
51
  # @return [Boolean]
52
52
  #
53
- def has_no_selector?(*args)
54
- assert_no_selector(*args)
53
+ def has_no_selector?(*args, &optional_filter_block)
54
+ assert_no_selector(*args, &optional_filter_block)
55
55
  rescue Capybara::ExpectationNotMet
56
56
  return false
57
57
  end
58
58
 
59
- ##
60
- #
61
- # Checks if the current node matches given selector
62
- #
63
- # @param (see Capybara::Node::Finders#has_selector?)
64
- # @return [Boolean]
65
- #
66
- def matches_selector?(*args)
67
- assert_matches_selector(*args)
68
- rescue Capybara::ExpectationNotMet
69
- return false
70
- end
71
-
72
- ##
73
- #
74
- # Checks if the current node matches given XPath expression
75
- #
76
- # @param [String, XPath::Expression] xpath The XPath expression to match against the current code
77
- # @return [Boolean]
78
- #
79
- def matches_xpath?(xpath, options={})
80
- matches_selector?(:xpath, xpath, options)
81
- end
82
-
83
- ##
84
- #
85
- # Checks if the current node matches given CSS selector
86
- #
87
- # @param [String] css The CSS selector to match against the current code
88
- # @return [Boolean]
89
- #
90
- def matches_css?(css, options={})
91
- matches_selector?(:css, css, options)
92
- end
93
-
94
- ##
95
- #
96
- # Checks if the current node does not match given selector
97
- # Usage is identical to Capybara::Node::Matchers#has_selector?
98
- #
99
- # @param (see Capybara::Node::Finders#has_selector?)
100
- # @return [Boolean]
101
- #
102
- def not_matches_selector?(*args)
103
- assert_not_matches_selector(*args)
104
- rescue Capybara::ExpectationNotMet
105
- return false
106
- end
107
-
108
- ##
109
- #
110
- # Checks if the current node does not match given XPath expression
111
- #
112
- # @param [String, XPath::Expression] xpath The XPath expression to match against the current code
113
- # @return [Boolean]
114
- #
115
- def not_matches_xpath?(xpath, options={})
116
- not_matches_selector?(:xpath, xpath, options)
117
- end
118
-
119
- ##
120
- #
121
- # Checks if the current node does not match given CSS selector
122
- #
123
- # @param [String] css The CSS selector to match against the current code
124
- # @return [Boolean]
125
- #
126
- def not_matches_css?(css, options={})
127
- not_matches_selector?(:css, css, options)
128
- end
129
-
130
59
  ##
131
60
  #
132
61
  # Asserts that a given selector is on the page or a descendant of the current node.
@@ -138,7 +67,7 @@ module Capybara
138
67
  # By default it will check if the expression occurs at least once,
139
68
  # but a different number can be specified.
140
69
  #
141
- # page.assert_selector('p#foo', :count => 4)
70
+ # page.assert_selector('p#foo', count: 4)
142
71
  #
143
72
  # This will check if the expression occurs exactly 4 times. See
144
73
  # {Capybara::Node::Finders#all} for other available result size options.
@@ -149,7 +78,7 @@ module Capybara
149
78
  # It also accepts all options that {Capybara::Node::Finders#all} accepts,
150
79
  # such as :text and :visible.
151
80
  #
152
- # page.assert_selector('li', :text => 'Horse', :visible => true)
81
+ # page.assert_selector('li', text: 'Horse', visible: true)
153
82
  #
154
83
  # `assert_selector` can also accept XPath expressions generated by the
155
84
  # XPath gem:
@@ -160,8 +89,8 @@ module Capybara
160
89
  # @option options [Integer] :count (nil) Number of times the expression should occur
161
90
  # @raise [Capybara::ExpectationNotMet] If the selector does not exist
162
91
  #
163
- def assert_selector(*args)
164
- query = Capybara::Queries::SelectorQuery.new(*args)
92
+ def assert_selector(*args, &optional_filter_block)
93
+ query = Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
165
94
  synchronize(query.wait) do
166
95
  result = query.resolve_for(self)
167
96
  unless result.matches_count? && ((!result.empty?) || query.expects_none?)
@@ -180,15 +109,15 @@ module Capybara
180
109
  # considered to be an integral part of the selector. This will return
181
110
  # true, for example, if a page contains 4 anchors but the query expects 5:
182
111
  #
183
- # page.assert_no_selector('a', :minimum => 1) # Found, raises Capybara::ExpectationNotMet
184
- # page.assert_no_selector('a', :count => 4) # Found, raises Capybara::ExpectationNotMet
185
- # page.assert_no_selector('a', :count => 5) # Not Found, returns true
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
186
115
  #
187
116
  # @param (see Capybara::Node::Finders#assert_selector)
188
117
  # @raise [Capybara::ExpectationNotMet] If the selector exists
189
118
  #
190
- def assert_no_selector(*args)
191
- query = Capybara::Queries::SelectorQuery.new(*args)
119
+ def assert_no_selector(*args, &optional_filter_block)
120
+ query = Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
192
121
  synchronize(query.wait) do
193
122
  result = query.resolve_for(self)
194
123
  if result.matches_count? && ((!result.empty?) || query.expects_none?)
@@ -199,45 +128,6 @@ module Capybara
199
128
  end
200
129
  alias_method :refute_selector, :assert_no_selector
201
130
 
202
- ##
203
- #
204
- # Asserts that the current_node matches a given selector
205
- #
206
- # node.assert_matches_selector('p#foo')
207
- # node.assert_matches_selector(:xpath, '//p[@id="foo"]')
208
- # node.assert_matches_selector(:foo)
209
- #
210
- # It also accepts all options that {Capybara::Node::Finders#all} accepts,
211
- # such as :text and :visible.
212
- #
213
- # node.assert_matches_selector('li', :text => 'Horse', :visible => true)
214
- #
215
- # @param (see Capybara::Node::Finders#all)
216
- # @raise [Capybara::ExpectationNotMet] If the selector does not match
217
- #
218
- def assert_matches_selector(*args)
219
- query = Capybara::Queries::MatchQuery.new(*args)
220
- synchronize(query.wait) do
221
- result = query.resolve_for(self.query_scope)
222
- unless result.include? self
223
- raise Capybara::ExpectationNotMet, "Item does not match the provided selector"
224
- end
225
- end
226
- return true
227
- end
228
-
229
- def assert_not_matches_selector(*args)
230
- query = Capybara::Queries::MatchQuery.new(*args)
231
- synchronize(query.wait) do
232
- result = query.resolve_for(self.query_scope)
233
- if result.include? self
234
- raise Capybara::ExpectationNotMet, 'Item matched the provided selector'
235
- end
236
- end
237
- return true
238
- end
239
- alias_method :refute_matches_selector, :assert_not_matches_selector
240
-
241
131
  ##
242
132
  #
243
133
  # Checks if a given XPath expression is on the page or a descendant of the current node.
@@ -247,14 +137,14 @@ module Capybara
247
137
  # By default it will check if the expression occurs at least once,
248
138
  # but a different number can be specified.
249
139
  #
250
- # page.has_xpath?('.//p[@id="foo"]', :count => 4)
140
+ # page.has_xpath?('.//p[@id="foo"]', count: 4)
251
141
  #
252
142
  # This will check if the expression occurs exactly 4 times.
253
143
  #
254
144
  # It also accepts all options that {Capybara::Node::Finders#all} accepts,
255
145
  # such as :text and :visible.
256
146
  #
257
- # page.has_xpath?('.//li', :text => 'Horse', :visible => true)
147
+ # page.has_xpath?('.//li', text: 'Horse', visible: true)
258
148
  #
259
149
  # has_xpath? can also accept XPath expressions generate by the
260
150
  # XPath gem:
@@ -267,8 +157,8 @@ module Capybara
267
157
  # @option options [Integer] :count (nil) Number of times the expression should occur
268
158
  # @return [Boolean] If the expression exists
269
159
  #
270
- def has_xpath?(path, options={})
271
- has_selector?(:xpath, path, options)
160
+ def has_xpath?(path, options={}, &optional_filter_block)
161
+ has_selector?(:xpath, path, options, &optional_filter_block)
272
162
  end
273
163
 
274
164
  ##
@@ -279,8 +169,8 @@ module Capybara
279
169
  # @param (see Capybara::Node::Finders#has_xpath?)
280
170
  # @return [Boolean]
281
171
  #
282
- def has_no_xpath?(path, options={})
283
- has_no_selector?(:xpath, path, options)
172
+ def has_no_xpath?(path, options={}, &optional_filter_block)
173
+ has_no_selector?(:xpath, path, options, &optional_filter_block)
284
174
  end
285
175
 
286
176
  ##
@@ -292,22 +182,22 @@ module Capybara
292
182
  # By default it will check if the selector occurs at least once,
293
183
  # but a different number can be specified.
294
184
  #
295
- # page.has_css?('p#foo', :count => 4)
185
+ # page.has_css?('p#foo', count: 4)
296
186
  #
297
187
  # This will check if the selector occurs exactly 4 times.
298
188
  #
299
189
  # It also accepts all options that {Capybara::Node::Finders#all} accepts,
300
190
  # such as :text and :visible.
301
191
  #
302
- # page.has_css?('li', :text => 'Horse', :visible => true)
192
+ # page.has_css?('li', text: 'Horse', visible: true)
303
193
  #
304
194
  # @param [String] path A CSS selector
305
195
  # @param options (see Capybara::Node::Finders#all)
306
196
  # @option options [Integer] :count (nil) Number of times the selector should occur
307
197
  # @return [Boolean] If the selector exists
308
198
  #
309
- def has_css?(path, options={})
310
- has_selector?(:css, path, options)
199
+ def has_css?(path, options={}, &optional_filter_block)
200
+ has_selector?(:css, path, options, &optional_filter_block)
311
201
  end
312
202
 
313
203
  ##
@@ -318,8 +208,8 @@ module Capybara
318
208
  # @param (see Capybara::Node::Finders#has_css?)
319
209
  # @return [Boolean]
320
210
  #
321
- def has_no_css?(path, options={})
322
- has_no_selector?(:css, path, options)
211
+ def has_no_css?(path, options={}, &optional_filter_block)
212
+ has_no_selector?(:css, path, options, &optional_filter_block)
323
213
  end
324
214
 
325
215
  ##
@@ -332,8 +222,9 @@ module Capybara
332
222
  # @option options [String, Regexp] :href The value the href attribute must be
333
223
  # @return [Boolean] Whether it exists
334
224
  #
335
- def has_link?(locator, options={})
336
- has_selector?(:link, locator, options)
225
+ def has_link?(locator=nil, options={}, &optional_filter_block)
226
+ locator, options = nil, locator if locator.is_a? Hash
227
+ has_selector?(:link, locator, options, &optional_filter_block)
337
228
  end
338
229
 
339
230
  ##
@@ -344,8 +235,9 @@ module Capybara
344
235
  # @param (see Capybara::Node::Finders#has_link?)
345
236
  # @return [Boolean] Whether it doesn't exist
346
237
  #
347
- def has_no_link?(locator, options={})
348
- has_no_selector?(:link, locator, options)
238
+ def has_no_link?(locator=nil, options={}, &optional_filter_block)
239
+ locator, options = nil, locator if locator.is_a? Hash
240
+ has_no_selector?(:link, locator, options, &optional_filter_block)
349
241
  end
350
242
 
351
243
  ##
@@ -356,8 +248,9 @@ module Capybara
356
248
  # @param [String] locator The text, value or id of a button to check for
357
249
  # @return [Boolean] Whether it exists
358
250
  #
359
- def has_button?(locator, options={})
360
- has_selector?(:button, locator, options)
251
+ def has_button?(locator=nil, options={}, &optional_filter_block)
252
+ locator, options = nil, locator if locator.is_a? Hash
253
+ has_selector?(:button, locator, options, &optional_filter_block)
361
254
  end
362
255
 
363
256
  ##
@@ -368,8 +261,9 @@ module Capybara
368
261
  # @param [String] locator The text, value or id of a button to check for
369
262
  # @return [Boolean] Whether it doesn't exist
370
263
  #
371
- def has_no_button?(locator, options={})
372
- has_no_selector?(:button, locator, options)
264
+ def has_no_button?(locator=nil, options={}, &optional_filter_block)
265
+ locator, options = nil, locator if locator.is_a? Hash
266
+ has_no_selector?(:button, locator, options, &optional_filter_block)
373
267
  end
374
268
 
375
269
  ##
@@ -381,11 +275,11 @@ module Capybara
381
275
  # HTML5 email/url/etc. fields, it's possible to specify a :with
382
276
  # option to specify the text the field should contain:
383
277
  #
384
- # page.has_field?('Name', :with => 'Jonas')
278
+ # page.has_field?('Name', with: 'Jonas')
385
279
  #
386
280
  # It is also possible to filter by the field type attribute:
387
281
  #
388
- # page.has_field?('Email', :type => 'email')
282
+ # page.has_field?('Email', type: 'email')
389
283
  #
390
284
  # Note: 'textarea' and 'select' are valid type values, matching the associated tag names.
391
285
  #
@@ -394,8 +288,9 @@ module Capybara
394
288
  # @option options [String] :type The type attribute of the field
395
289
  # @return [Boolean] Whether it exists
396
290
  #
397
- def has_field?(locator, options={})
398
- has_selector?(:field, locator, options)
291
+ def has_field?(locator=nil, options={}, &optional_filter_block)
292
+ locator, options = nil, locator if locator.is_a? Hash
293
+ has_selector?(:field, locator, options, &optional_filter_block)
399
294
  end
400
295
 
401
296
  ##
@@ -408,8 +303,9 @@ module Capybara
408
303
  # @option options [String] :type The type attribute of the field
409
304
  # @return [Boolean] Whether it doesn't exist
410
305
  #
411
- def has_no_field?(locator, options={})
412
- has_no_selector?(:field, locator, options)
306
+ def has_no_field?(locator=nil, options={}, &optional_filter_block)
307
+ locator, options = nil, locator if locator.is_a? Hash
308
+ has_no_selector?(:field, locator, options, &optional_filter_block)
413
309
  end
414
310
 
415
311
  ##
@@ -421,8 +317,9 @@ module Capybara
421
317
  # @param [String] locator The label, name or id of a checked field
422
318
  # @return [Boolean] Whether it exists
423
319
  #
424
- def has_checked_field?(locator, options={})
425
- has_selector?(:field, locator, options.merge(:checked => true))
320
+ def has_checked_field?(locator=nil, options={}, &optional_filter_block)
321
+ locator, options = nil, locator if locator.is_a? Hash
322
+ has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
426
323
  end
427
324
 
428
325
  ##
@@ -434,8 +331,9 @@ module Capybara
434
331
  # @param [String] locator The label, name or id of a checked field
435
332
  # @return [Boolean] Whether it doesn't exist
436
333
  #
437
- def has_no_checked_field?(locator, options={})
438
- has_no_selector?(:field, locator, options.merge(:checked => true))
334
+ def has_no_checked_field?(locator=nil, options={}, &optional_filter_block)
335
+ locator, options = nil, locator if locator.is_a? Hash
336
+ has_no_selector?(:field, locator, options.merge(checked: true))
439
337
  end
440
338
 
441
339
  ##
@@ -447,8 +345,9 @@ module Capybara
447
345
  # @param [String] locator The label, name or id of an unchecked field
448
346
  # @return [Boolean] Whether it exists
449
347
  #
450
- def has_unchecked_field?(locator, options={})
451
- has_selector?(:field, locator, options.merge(:unchecked => true))
348
+ def has_unchecked_field?(locator=nil, options={}, &optional_filter_block)
349
+ locator, options = nil, locator if locator.is_a? Hash
350
+ has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
452
351
  end
453
352
 
454
353
  ##
@@ -460,8 +359,9 @@ module Capybara
460
359
  # @param [String] locator The label, name or id of an unchecked field
461
360
  # @return [Boolean] Whether it doesn't exist
462
361
  #
463
- def has_no_unchecked_field?(locator, options={})
464
- has_no_selector?(:field, locator, options.merge(:unchecked => true))
362
+ def has_no_unchecked_field?(locator=nil, options={}, &optional_filter_block)
363
+ locator, options = nil, locator if locator.is_a? Hash
364
+ has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
465
365
  end
466
366
 
467
367
  ##
@@ -471,20 +371,20 @@ module Capybara
471
371
  #
472
372
  # It can be specified which option should currently be selected:
473
373
  #
474
- # page.has_select?('Language', :selected => 'German')
374
+ # page.has_select?('Language', selected: 'German')
475
375
  #
476
376
  # For multiple select boxes, several options may be specified:
477
377
  #
478
- # page.has_select?('Language', :selected => ['English', 'German'])
378
+ # page.has_select?('Language', selected: ['English', 'German'])
479
379
  #
480
380
  # It's also possible to check if the exact set of options exists for
481
381
  # this select box:
482
382
  #
483
- # page.has_select?('Language', :options => ['English', 'German', 'Spanish'])
383
+ # page.has_select?('Language', options: ['English', 'German', 'Spanish'])
484
384
  #
485
385
  # You can also check for a partial set of options:
486
386
  #
487
- # page.has_select?('Language', :with_options => ['English', 'German'])
387
+ # page.has_select?('Language', with_options: ['English', 'German'])
488
388
  #
489
389
  # @param [String] locator The label, name or id of a select box
490
390
  # @option options [Array] :options Options which should be contained in this select box
@@ -492,8 +392,9 @@ module Capybara
492
392
  # @option options [String, Array] :selected Options which should be selected
493
393
  # @return [Boolean] Whether it exists
494
394
  #
495
- def has_select?(locator, options={})
496
- has_selector?(:select, locator, options)
395
+ def has_select?(locator=nil, options={}, &optional_filter_block)
396
+ locator, options = nil, locator if locator.is_a? Hash
397
+ has_selector?(:select, locator, options, &optional_filter_block)
497
398
  end
498
399
 
499
400
  ##
@@ -504,8 +405,9 @@ module Capybara
504
405
  # @param (see Capybara::Node::Matchers#has_select?)
505
406
  # @return [Boolean] Whether it doesn't exist
506
407
  #
507
- def has_no_select?(locator, options={})
508
- has_no_selector?(:select, locator, options)
408
+ def has_no_select?(locator=nil, options={}, &optional_filter_block)
409
+ locator, options = nil, locator if locator.is_a? Hash
410
+ has_no_selector?(:select, locator, options, &optional_filter_block)
509
411
  end
510
412
 
511
413
  ##
@@ -518,8 +420,9 @@ module Capybara
518
420
  # @param [String] locator The id or caption of a table
519
421
  # @return [Boolean] Whether it exist
520
422
  #
521
- def has_table?(locator, options={})
522
- has_selector?(:table, locator, options)
423
+ def has_table?(locator=nil, options={}, &optional_filter_block)
424
+ locator, options = nil, locator if locator.is_a? Hash
425
+ has_selector?(:table, locator, options, &optional_filter_block)
523
426
  end
524
427
 
525
428
  ##
@@ -530,10 +433,122 @@ module Capybara
530
433
  # @param (see Capybara::Node::Matchers#has_table?)
531
434
  # @return [Boolean] Whether it doesn't exist
532
435
  #
533
- def has_no_table?(locator, options={})
534
- has_no_selector?(:table, locator, options)
436
+ def has_no_table?(locator=nil, options={}, &optional_filter_block)
437
+ locator, options = nil, locator if locator.is_a? Hash
438
+ has_no_selector?(:table, locator, options, &optional_filter_block)
439
+ end
440
+
441
+ ##
442
+ #
443
+ # Asserts that the current_node matches a given selector
444
+ #
445
+ # node.assert_matches_selector('p#foo')
446
+ # node.assert_matches_selector(:xpath, '//p[@id="foo"]')
447
+ # node.assert_matches_selector(:foo)
448
+ #
449
+ # It also accepts all options that {Capybara::Node::Finders#all} accepts,
450
+ # such as :text and :visible.
451
+ #
452
+ # node.assert_matches_selector('li', text: 'Horse', visible: true)
453
+ #
454
+ # @param (see Capybara::Node::Finders#all)
455
+ # @raise [Capybara::ExpectationNotMet] If the selector does not match
456
+ #
457
+ def assert_matches_selector(*args, &optional_filter_block)
458
+ query = Capybara::Queries::MatchQuery.new(*args, &optional_filter_block)
459
+ synchronize(query.wait) do
460
+ result = query.resolve_for(self.query_scope)
461
+ unless result.include? self
462
+ raise Capybara::ExpectationNotMet, "Item does not match the provided selector"
463
+ end
464
+ end
465
+ return true
466
+ end
467
+
468
+ def assert_not_matches_selector(*args, &optional_filter_block)
469
+ query = Capybara::Queries::MatchQuery.new(*args, &optional_filter_block)
470
+ synchronize(query.wait) do
471
+ result = query.resolve_for(self.query_scope)
472
+ if result.include? self
473
+ raise Capybara::ExpectationNotMet, 'Item matched the provided selector'
474
+ end
475
+ end
476
+ return true
477
+ end
478
+ alias_method :refute_matches_selector, :assert_not_matches_selector
479
+
480
+ ##
481
+ #
482
+ # Checks if the current node matches given selector
483
+ #
484
+ # @param (see Capybara::Node::Finders#has_selector?)
485
+ # @return [Boolean]
486
+ #
487
+ def matches_selector?(*args, &optional_filter_block)
488
+ assert_matches_selector(*args, &optional_filter_block)
489
+ rescue Capybara::ExpectationNotMet
490
+ return false
491
+ end
492
+
493
+ ##
494
+ #
495
+ # Checks if the current node matches given XPath expression
496
+ #
497
+ # @param [String, XPath::Expression] xpath The XPath expression to match against the current code
498
+ # @return [Boolean]
499
+ #
500
+ def matches_xpath?(xpath, options={}, &optional_filter_block)
501
+ matches_selector?(:xpath, xpath, options, &optional_filter_block)
502
+ end
503
+
504
+ ##
505
+ #
506
+ # Checks if the current node matches given CSS selector
507
+ #
508
+ # @param [String] css The CSS selector to match against the current code
509
+ # @return [Boolean]
510
+ #
511
+ def matches_css?(css, options={}, &optional_filter_block)
512
+ matches_selector?(:css, css, options, &optional_filter_block)
535
513
  end
536
514
 
515
+ ##
516
+ #
517
+ # Checks if the current node does not match given selector
518
+ # Usage is identical to Capybara::Node::Matchers#has_selector?
519
+ #
520
+ # @param (see Capybara::Node::Finders#has_selector?)
521
+ # @return [Boolean]
522
+ #
523
+ def not_matches_selector?(*args, &optional_filter_block)
524
+ assert_not_matches_selector(*args, &optional_filter_block)
525
+ rescue Capybara::ExpectationNotMet
526
+ return false
527
+ end
528
+
529
+ ##
530
+ #
531
+ # Checks if the current node does not match given XPath expression
532
+ #
533
+ # @param [String, XPath::Expression] xpath The XPath expression to match against the current code
534
+ # @return [Boolean]
535
+ #
536
+ def not_matches_xpath?(xpath, options={}, &optional_filter_block)
537
+ not_matches_selector?(:xpath, xpath, options, &optional_filter_block)
538
+ end
539
+
540
+ ##
541
+ #
542
+ # Checks if the current node does not match given CSS selector
543
+ #
544
+ # @param [String] css The CSS selector to match against the current code
545
+ # @return [Boolean]
546
+ #
547
+ def not_matches_css?(css, options={}, &optional_filter_block)
548
+ not_matches_selector?(:css, css, options, &optional_filter_block)
549
+ end
550
+
551
+
537
552
  ##
538
553
  # Asserts that the page or current node has the given text content,
539
554
  # ignoring any HTML tags.
@@ -629,6 +644,7 @@ module Capybara
629
644
  def ==(other)
630
645
  self.eql?(other) || (other.respond_to?(:base) && base == other.base)
631
646
  end
647
+
632
648
  end
633
649
  end
634
650
  end