capybara 2.10.2 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +15 -0
  3. data/README.md +48 -29
  4. data/lib/capybara.rb +8 -9
  5. data/lib/capybara/node/actions.rb +39 -48
  6. data/lib/capybara/node/document.rb +4 -0
  7. data/lib/capybara/node/document_matchers.rb +13 -14
  8. data/lib/capybara/node/element.rb +21 -0
  9. data/lib/capybara/node/finders.rb +3 -3
  10. data/lib/capybara/node/matchers.rb +38 -31
  11. data/lib/capybara/node/simple.rb +3 -0
  12. data/lib/capybara/queries/selector_query.rb +4 -2
  13. data/lib/capybara/rack_test/node.rb +1 -1
  14. data/lib/capybara/result.rb +3 -1
  15. data/lib/capybara/rspec/matchers.rb +53 -95
  16. data/lib/capybara/selector.rb +7 -7
  17. data/lib/capybara/selector/selector.rb +10 -5
  18. data/lib/capybara/selenium/driver.rb +34 -7
  19. data/lib/capybara/selenium/node.rb +5 -1
  20. data/lib/capybara/session.rb +22 -27
  21. data/lib/capybara/session/matchers.rb +12 -14
  22. data/lib/capybara/spec/public/test.js +4 -0
  23. data/lib/capybara/spec/session/accept_alert_spec.rb +1 -1
  24. data/lib/capybara/spec/session/attach_file_spec.rb +1 -1
  25. data/lib/capybara/spec/session/check_spec.rb +8 -0
  26. data/lib/capybara/spec/session/choose_spec.rb +5 -0
  27. data/lib/capybara/spec/session/click_link_or_button_spec.rb +5 -0
  28. data/lib/capybara/spec/session/click_link_spec.rb +5 -0
  29. data/lib/capybara/spec/session/element/assert_match_selector.rb +5 -0
  30. data/lib/capybara/spec/session/element/match_css_spec.rb +6 -0
  31. data/lib/capybara/spec/session/element/matches_selector_spec.rb +2 -0
  32. data/lib/capybara/spec/session/fill_in_spec.rb +5 -0
  33. data/lib/capybara/spec/session/find_spec.rb +1 -1
  34. data/lib/capybara/spec/session/first_spec.rb +10 -0
  35. data/lib/capybara/spec/session/has_selector_spec.rb +11 -0
  36. data/lib/capybara/spec/session/node_spec.rb +3 -3
  37. data/lib/capybara/spec/session/text_spec.rb +3 -4
  38. data/lib/capybara/spec/views/with_js.erb +3 -1
  39. data/lib/capybara/version.rb +1 -1
  40. data/lib/capybara/window.rb +18 -2
  41. data/spec/basic_node_spec.rb +1 -1
  42. data/spec/capybara_spec.rb +4 -1
  43. data/spec/fixtures/selenium_driver_rspec_failure.rb +4 -1
  44. data/spec/fixtures/selenium_driver_rspec_success.rb +4 -1
  45. data/spec/result_spec.rb +28 -2
  46. data/spec/rspec/{matchers_spec.rb → shared_spec_matchers.rb} +4 -3
  47. data/spec/selector_spec.rb +1 -1
  48. data/spec/selenium_spec_chrome.rb +36 -5
  49. data/spec/selenium_spec_firefox.rb +67 -0
  50. data/spec/selenium_spec_marionette.rb +114 -0
  51. data/spec/shared_selenium_session.rb +6 -4
  52. metadata +13 -6
  53. data/spec/selenium_firefox_spec.rb +0 -44
@@ -24,6 +24,10 @@ module Capybara
24
24
  find(:xpath, '/html').text(type)
25
25
  end
26
26
 
27
+ ##
28
+ #
29
+ # @return [String] The title of the document
30
+ #
27
31
  def title
28
32
  session.driver.title
29
33
  end
@@ -15,13 +15,7 @@ module Capybara
15
15
  # @return [true]
16
16
  #
17
17
  def assert_title(title, options = {})
18
- query = Capybara::Queries::TitleQuery.new(title, options)
19
- synchronize(query.wait) do
20
- unless query.resolves_for?(self)
21
- raise Capybara::ExpectationNotMet, query.failure_message
22
- end
23
- end
24
- return true
18
+ _verify_title(title,options) { |query| raise Capybara::ExpectationNotMet, query.failure_message unless query.resolves_for?(self) }
25
19
  end
26
20
 
27
21
  ##
@@ -32,13 +26,7 @@ module Capybara
32
26
  # @return [true]
33
27
  #
34
28
  def assert_no_title(title, options = {})
35
- query = Capybara::Queries::TitleQuery.new(title, options)
36
- synchronize(query.wait) do
37
- if query.resolves_for?(self)
38
- raise Capybara::ExpectationNotMet, query.negative_failure_message
39
- end
40
- end
41
- return true
29
+ _verify_title(title,options) { |query| raise Capybara::ExpectationNotMet, query.negative_failure_message if query.resolves_for?(self) }
42
30
  end
43
31
 
44
32
  ##
@@ -64,6 +52,17 @@ module Capybara
64
52
  rescue Capybara::ExpectationNotMet
65
53
  return false
66
54
  end
55
+
56
+ private
57
+
58
+ def _verify_title(title, options)
59
+ query = Capybara::Queries::TitleQuery.new(title, options)
60
+ synchronize(query.wait) do
61
+ yield(query)
62
+ end
63
+ return true
64
+ end
65
+
67
66
  end
68
67
  end
69
68
  end
@@ -27,6 +27,7 @@ module Capybara
27
27
  super(session, base)
28
28
  @query_scope = query_scope
29
29
  @query = query
30
+ @allow_reload = false
30
31
  end
31
32
 
32
33
  def allow_reload!
@@ -92,6 +93,7 @@ module Capybara
92
93
  # @param [String] value The new value
93
94
  # @param [Hash{}] options Driver specific options for how to set the value
94
95
  #
96
+ # @return [Capybara::Node::Element] The element
95
97
  def set(value, options={})
96
98
  options ||= {}
97
99
 
@@ -108,47 +110,58 @@ module Capybara
108
110
  base.set(value)
109
111
  end
110
112
  end
113
+ return self
111
114
  end
112
115
 
113
116
  ##
114
117
  #
115
118
  # Select this node if is an option element inside a select tag
116
119
  #
120
+ # @return [Capybara::Node::Element] The element
117
121
  def select_option
118
122
  warn "Attempt to select disabled option: #{value || text}" if disabled?
119
123
  synchronize { base.select_option }
124
+ return self
120
125
  end
121
126
 
122
127
  ##
123
128
  #
124
129
  # Unselect this node if is an option element inside a multiple select tag
125
130
  #
131
+ # @return [Capybara::Node::Element] The element
126
132
  def unselect_option
127
133
  synchronize { base.unselect_option }
134
+ return self
128
135
  end
129
136
 
130
137
  ##
131
138
  #
132
139
  # Click the Element
133
140
  #
141
+ # @return [Capybara::Node::Element] The element
134
142
  def click
135
143
  synchronize { base.click }
144
+ return self
136
145
  end
137
146
 
138
147
  ##
139
148
  #
140
149
  # Right Click the Element
141
150
  #
151
+ # @return [Capybara::Node::Element] The element
142
152
  def right_click
143
153
  synchronize { base.right_click }
154
+ return self
144
155
  end
145
156
 
146
157
  ##
147
158
  #
148
159
  # Double Click the Element
149
160
  #
161
+ # @return [Capybara::Node::Element] The element
150
162
  def double_click
151
163
  synchronize { base.double_click }
164
+ return self
152
165
  end
153
166
 
154
167
  ##
@@ -221,16 +234,20 @@ module Capybara
221
234
  # :meta
222
235
  # :command - alias of :meta
223
236
  #
237
+ # @return [Capybara::Node::Element] The element
224
238
  def send_keys(*args)
225
239
  synchronize { base.send_keys(*args) }
240
+ return self
226
241
  end
227
242
 
228
243
  ##
229
244
  #
230
245
  # Hover on the Element
231
246
  #
247
+ # @return [Capybara::Node::Element] The element
232
248
  def hover
233
249
  synchronize { base.hover }
250
+ return self
234
251
  end
235
252
 
236
253
  ##
@@ -319,8 +336,10 @@ module Capybara
319
336
  #
320
337
  # @param [String] event The name of the event to trigger
321
338
  #
339
+ # @return [Capybara::Node::Element] The element
322
340
  def trigger(event)
323
341
  synchronize { base.trigger(event) }
342
+ return self
324
343
  end
325
344
 
326
345
  ##
@@ -333,8 +352,10 @@ module Capybara
333
352
  #
334
353
  # @param [Capybara::Node::Element] node The element to drag to
335
354
  #
355
+ # @return [Capybara::Node::Element] The element
336
356
  def drag_to(node)
337
357
  synchronize { base.drag_to(node.base) }
358
+ return self
338
359
  end
339
360
 
340
361
  def reload
@@ -18,7 +18,7 @@ module Capybara
18
18
  # +find+ takes the same options as +all+.
19
19
  #
20
20
  # page.find('#foo').find('.bar')
21
- # page.find(:xpath, '//div[contains(., "bar")]')
21
+ # page.find(:xpath, './/div[contains(., "bar")]')
22
22
  # page.find('li', text: 'Quox').click_link('Delete')
23
23
  #
24
24
  # @param (see Capybara::Node::Finders#all)
@@ -155,7 +155,7 @@ module Capybara
155
155
  # following statements are equivalent:
156
156
  #
157
157
  # page.all(:css, 'a#person_123')
158
- # page.all(:xpath, '//a[@id="person_123"]')
158
+ # page.all(:xpath, './/a[@id="person_123"]')
159
159
  #
160
160
  #
161
161
  # If the type of selector is left out, Capybara uses
@@ -164,7 +164,7 @@ module Capybara
164
164
  # page.all("a#person_123")
165
165
  #
166
166
  # Capybara.default_selector = :xpath
167
- # page.all('//a[@id="person_123"]')
167
+ # page.all('.//a[@id="person_123"]')
168
168
  #
169
169
  # The set of found elements can further be restricted by specifying
170
170
  # options. It's possible to select elements by their text or visibility:
@@ -90,14 +90,11 @@ module Capybara
90
90
  # @raise [Capybara::ExpectationNotMet] If the selector does not exist
91
91
  #
92
92
  def assert_selector(*args, &optional_filter_block)
93
- query = Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
94
- synchronize(query.wait) do
95
- result = query.resolve_for(self)
93
+ _verify_selector_result(args, optional_filter_block) do |result, query|
96
94
  unless result.matches_count? && ((!result.empty?) || query.expects_none?)
97
95
  raise Capybara::ExpectationNotMet, result.failure_message
98
96
  end
99
97
  end
100
- return true
101
98
  end
102
99
 
103
100
  ##
@@ -117,14 +114,11 @@ module Capybara
117
114
  # @raise [Capybara::ExpectationNotMet] If the selector exists
118
115
  #
119
116
  def assert_no_selector(*args, &optional_filter_block)
120
- query = Capybara::Queries::SelectorQuery.new(*args, &optional_filter_block)
121
- synchronize(query.wait) do
122
- result = query.resolve_for(self)
117
+ _verify_selector_result(args, optional_filter_block) do |result, query|
123
118
  if result.matches_count? && ((!result.empty?) || query.expects_none?)
124
119
  raise Capybara::ExpectationNotMet, result.negative_failure_message
125
120
  end
126
121
  end
127
- return true
128
122
  end
129
123
  alias_method :refute_selector, :assert_no_selector
130
124
 
@@ -333,7 +327,7 @@ module Capybara
333
327
  #
334
328
  def has_no_checked_field?(locator=nil, options={}, &optional_filter_block)
335
329
  locator, options = nil, locator if locator.is_a? Hash
336
- has_no_selector?(:field, locator, options.merge(checked: true))
330
+ has_no_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
337
331
  end
338
332
 
339
333
  ##
@@ -455,25 +449,15 @@ module Capybara
455
449
  # @raise [Capybara::ExpectationNotMet] If the selector does not match
456
450
  #
457
451
  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
452
+ _verify_match_result(args, optional_filter_block) do |result|
453
+ raise Capybara::ExpectationNotMet, "Item does not match the provided selector" unless result.include? self
464
454
  end
465
- return true
466
455
  end
467
456
 
468
457
  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
458
+ _verify_match_result(args, optional_filter_block) do |result|
459
+ raise Capybara::ExpectationNotMet, 'Item matched the provided selector' if result.include? self
475
460
  end
476
- return true
477
461
  end
478
462
  alias_method :refute_matches_selector, :assert_not_matches_selector
479
463
 
@@ -573,14 +557,11 @@ module Capybara
573
557
  # @return [true]
574
558
  #
575
559
  def assert_text(*args)
576
- query = Capybara::Queries::TextQuery.new(*args)
577
- synchronize(query.wait) do
578
- count = query.resolve_for(self)
560
+ _verify_text(args) do |count, query|
579
561
  unless query.matches_count?(count) && ((count > 0) || query.expects_none?)
580
562
  raise Capybara::ExpectationNotMet, query.failure_message
581
563
  end
582
564
  end
583
- return true
584
565
  end
585
566
 
586
567
  ##
@@ -592,14 +573,11 @@ module Capybara
592
573
  # @return [true]
593
574
  #
594
575
  def assert_no_text(*args)
595
- query = Capybara::Queries::TextQuery.new(*args)
596
- synchronize(query.wait) do
597
- count = query.resolve_for(self)
576
+ _verify_text(args) do |count, query|
598
577
  if query.matches_count?(count) && ((count > 0) || query.expects_none?)
599
578
  raise Capybara::ExpectationNotMet, query.negative_failure_message
600
579
  end
601
580
  end
602
- return true
603
581
  end
604
582
 
605
583
  ##
@@ -645,6 +623,35 @@ module Capybara
645
623
  self.eql?(other) || (other.respond_to?(:base) && base == other.base)
646
624
  end
647
625
 
626
+ private
627
+
628
+ def _verify_selector_result(query_args, optional_filter_block, &result_block)
629
+ query = Capybara::Queries::SelectorQuery.new(*query_args, &optional_filter_block)
630
+ synchronize(query.wait) do
631
+ result = query.resolve_for(self)
632
+ result_block.call(result, query)
633
+ end
634
+ return true
635
+ end
636
+
637
+ def _verify_match_result(query_args, optional_filter_block, &result_block)
638
+ query = Capybara::Queries::MatchQuery.new(*query_args, &optional_filter_block)
639
+ synchronize(query.wait) do
640
+ result = query.resolve_for(self.query_scope)
641
+ result_block.call(result)
642
+ end
643
+ return true
644
+ end
645
+
646
+ def _verify_text(query_args)
647
+ query = Capybara::Queries::TextQuery.new(*query_args)
648
+ synchronize(query.wait) do
649
+ count = query.resolve_for(self)
650
+ yield(count, query)
651
+ end
652
+ return true
653
+ end
654
+
648
655
  end
649
656
  end
650
657
  end
@@ -148,6 +148,9 @@ module Capybara
148
148
  # no op
149
149
  end
150
150
 
151
+ ##
152
+ #
153
+ # @return [String] The title of the document
151
154
  def title
152
155
  if native.respond_to? :title
153
156
  native.title
@@ -53,7 +53,9 @@ module Capybara
53
53
  def matches_filters?(node)
54
54
  if options[:text]
55
55
  regexp = options[:text].is_a?(Regexp) ? options[:text] : Regexp.escape(options[:text].to_s)
56
- return false if not node.text(visible).match(regexp)
56
+ text_visible = visible
57
+ text_visible = :all if text_visible == :hidden
58
+ return false if not node.text(text_visible).match(regexp)
57
59
  end
58
60
 
59
61
  case visible
@@ -71,7 +73,7 @@ module Capybara
71
73
  end
72
74
  end
73
75
 
74
- res &&= @filter_block.call(node) unless @filter_block.nil?
76
+ res &&= Capybara.using_wait_time(0){ @filter_block.call(node)} unless @filter_block.nil?
75
77
  res
76
78
  end
77
79
 
@@ -152,7 +152,7 @@ private
152
152
  end
153
153
  end
154
154
 
155
- def set_radio(value)
155
+ def set_radio(_value)
156
156
  other_radios_xpath = XPath.generate { |x| x.anywhere(:input)[x.attr(:name).equals(self[:name])] }.to_s
157
157
  driver.dom.xpath(other_radios_xpath).each { |node| node.remove_attribute("checked") }
158
158
  native['checked'] = 'checked'
@@ -40,6 +40,8 @@ module Capybara
40
40
  alias :index :find_index
41
41
 
42
42
  def each(&block)
43
+ return enum_for(:each) unless block_given?
44
+
43
45
  @result_cache.each(&block)
44
46
  loop do
45
47
  next_result = @results_enum.next
@@ -137,7 +139,7 @@ module Capybara
137
139
 
138
140
  def lazy_select_elements(&block)
139
141
  if @elements.respond_to? :lazy #Ruby 2.0+
140
- @elements.lazy.select &block
142
+ @elements.lazy.select(&block)
141
143
  else
142
144
  Enumerator.new do |yielder|
143
145
  @elements.each do |val|
@@ -4,6 +4,8 @@ module Capybara
4
4
  class Matcher
5
5
  include ::RSpec::Matchers::Composable if defined?(::RSpec::Expectations::Version) && (Gem::Version.new(RSpec::Expectations::Version::STRING) >= Gem::Version.new('3.0'))
6
6
 
7
+ attr_reader :failure_message, :failure_message_when_negated
8
+
7
9
  def wrap(actual)
8
10
  if actual.respond_to?("has_selector?")
9
11
  actual
@@ -11,10 +13,29 @@ module Capybara
11
13
  Capybara.string(actual.to_s)
12
14
  end
13
15
  end
16
+
17
+ # RSpec 2 compatibility:
18
+ def failure_message_for_should; failure_message end
19
+ def failure_message_for_should_not; failure_message_when_negated end
20
+
21
+ private
22
+
23
+ def wrap_matches?(actual)
24
+ yield(wrap(actual))
25
+ rescue Capybara::ExpectationNotMet => e
26
+ @failure_message = e.message
27
+ return false
28
+ end
29
+
30
+ def wrap_does_not_match?(actual)
31
+ yield(wrap(actual))
32
+ rescue Capybara::ExpectationNotMet => e
33
+ @failure_message_when_negated = e.message
34
+ return false
35
+ end
14
36
  end
15
37
 
16
38
  class HaveSelector < Matcher
17
- attr_reader :failure_message, :failure_message_when_negated
18
39
 
19
40
  def initialize(*args, &filter_block)
20
41
  @args = args
@@ -22,17 +43,11 @@ module Capybara
22
43
  end
23
44
 
24
45
  def matches?(actual)
25
- wrap(actual).assert_selector(*@args)
26
- rescue Capybara::ExpectationNotMet => e
27
- @failure_message = e.message
28
- return false
46
+ wrap_matches?(actual){ |el| el.assert_selector(*@args, &@filter_block) }
29
47
  end
30
48
 
31
49
  def does_not_match?(actual)
32
- wrap(actual).assert_no_selector(*@args)
33
- rescue Capybara::ExpectationNotMet => e
34
- @failure_message_when_negated = e.message
35
- return false
50
+ wrap_does_not_match?(actual){ |el| el.assert_no_selector(*@args, &@filter_block) }
36
51
  end
37
52
 
38
53
  def description
@@ -42,17 +57,29 @@ module Capybara
42
57
  def query
43
58
  @query ||= Capybara::Queries::SelectorQuery.new(*@args, &@filter_block)
44
59
  end
60
+ end
45
61
 
46
- # RSpec 2 compatibility:
47
- alias_method :failure_message_for_should, :failure_message
48
- alias_method :failure_message_for_should_not, :failure_message_when_negated
62
+ class MatchSelector < HaveSelector
63
+ def matches?(actual)
64
+ wrap_matches?(actual) { |el| el.assert_matches_selector(*@args, &@filter_block) }
65
+ end
66
+
67
+ def does_not_match?(actual)
68
+ wrap_does_not_match?(actual) { |el| el.assert_not_matches_selector(*@args, &@filter_block) }
69
+ end
70
+
71
+ def description
72
+ "match #{query.description}"
73
+ end
74
+
75
+ def query
76
+ @query ||= Capybara::Queries::MatchQuery.new(*@args)
77
+ end
49
78
  end
50
79
 
51
80
  class HaveText < Matcher
52
81
  attr_reader :type, :content, :options
53
82
 
54
- attr_reader :failure_message, :failure_message_when_negated
55
-
56
83
  def initialize(*args)
57
84
  @args = args.dup
58
85
 
@@ -63,17 +90,11 @@ module Capybara
63
90
  end
64
91
 
65
92
  def matches?(actual)
66
- wrap(actual).assert_text(*@args)
67
- rescue Capybara::ExpectationNotMet => e
68
- @failure_message = e.message
69
- return false
93
+ wrap_matches?(actual) { |el| el.assert_text(*@args) }
70
94
  end
71
95
 
72
96
  def does_not_match?(actual)
73
- wrap(actual).assert_no_text(*@args)
74
- rescue Capybara::ExpectationNotMet => e
75
- @failure_message_when_negated = e.message
76
- return false
97
+ wrap_does_not_match?(actual) { |el| el.assert_no_text(*@args) }
77
98
  end
78
99
 
79
100
  def description
@@ -84,17 +105,11 @@ module Capybara
84
105
  content = Capybara::Helpers.normalize_whitespace(content) unless content.is_a? Regexp
85
106
  content.inspect
86
107
  end
87
-
88
- # RSpec 2 compatibility:
89
- alias_method :failure_message_for_should, :failure_message
90
- alias_method :failure_message_for_should_not, :failure_message_when_negated
91
108
  end
92
109
 
93
110
  class HaveTitle < Matcher
94
111
  attr_reader :title
95
112
 
96
- attr_reader :failure_message, :failure_message_when_negated
97
-
98
113
  def initialize(*args)
99
114
  @args = args
100
115
 
@@ -103,33 +118,21 @@ module Capybara
103
118
  end
104
119
 
105
120
  def matches?(actual)
106
- wrap(actual).assert_title(*@args)
107
- rescue Capybara::ExpectationNotMet => e
108
- @failure_message = e.message
109
- return false
121
+ wrap_matches?(actual) { |el| el.assert_title(*@args) }
110
122
  end
111
123
 
112
124
  def does_not_match?(actual)
113
- wrap(actual).assert_no_title(*@args)
114
- rescue Capybara::ExpectationNotMet => e
115
- @failure_message_when_negated = e.message
116
- return false
125
+ wrap_does_not_match?(actual) { |el| el.assert_no_title(*@args) }
117
126
  end
118
127
 
119
128
  def description
120
129
  "have title #{title.inspect}"
121
130
  end
122
-
123
- # RSpec 2 compatibility:
124
- alias_method :failure_message_for_should, :failure_message
125
- alias_method :failure_message_for_should_not, :failure_message_when_negated
126
131
  end
127
132
 
128
133
  class HaveCurrentPath < Matcher
129
134
  attr_reader :current_path
130
135
 
131
- attr_reader :failure_message, :failure_message_when_negated
132
-
133
136
  def initialize(*args)
134
137
  @args = args
135
138
 
@@ -138,26 +141,16 @@ module Capybara
138
141
  end
139
142
 
140
143
  def matches?(actual)
141
- wrap(actual).assert_current_path(*@args)
142
- rescue Capybara::ExpectationNotMet => e
143
- @failure_message = e.message
144
- return false
144
+ wrap_matches?(actual) { |el| el.assert_current_path(*@args) }
145
145
  end
146
146
 
147
147
  def does_not_match?(actual)
148
- wrap(actual).assert_no_current_path(*@args)
149
- rescue Capybara::ExpectationNotMet => e
150
- @failure_message_when_negated = e.message
151
- return false
148
+ wrap_does_not_match?(actual) { |el| el.assert_no_current_path(*@args) }
152
149
  end
153
150
 
154
151
  def description
155
152
  "have current path #{current_path.inspect}"
156
153
  end
157
-
158
- # RSpec 2 compatibility:
159
- alias_method :failure_message_for_should, :failure_message
160
- alias_method :failure_message_for_should_not, :failure_message_when_negated
161
154
  end
162
155
 
163
156
  class BecomeClosed
@@ -188,46 +181,12 @@ module Capybara
188
181
  alias_method :failure_message_for_should_not, :failure_message_when_negated
189
182
  end
190
183
 
191
- class MatchSelector < Matcher
192
- attr_reader :failure_message, :failure_message_when_negated
193
-
194
- def initialize(*args)
195
- @args = args
196
- end
197
-
198
- def matches?(actual)
199
- actual.assert_matches_selector(*@args)
200
- rescue Capybara::ExpectationNotMet => e
201
- @failure_message = e.message
202
- return false
203
- end
204
-
205
- def does_not_match?(actual)
206
- actual.assert_not_matches_selector(*@args)
207
- rescue Capybara::ExpectationNotMet => e
208
- @failure_message_when_negated = e.message
209
- return false
210
- end
211
-
212
- def description
213
- "match #{query.description}"
214
- end
215
-
216
- def query
217
- @query ||= Capybara::Queries::MatchQuery.new(*@args)
218
- end
219
-
220
- # RSpec 2 compatibility:
221
- alias_method :failure_message_for_should, :failure_message
222
- alias_method :failure_message_for_should_not, :failure_message_when_negated
223
- end
224
-
225
184
  def have_selector(*args, &optional_filter_block)
226
185
  HaveSelector.new(*args, &optional_filter_block)
227
186
  end
228
187
 
229
- def match_selector(*args)
230
- MatchSelector.new(*args)
188
+ def match_selector(*args, &optional_filter_block)
189
+ MatchSelector.new(*args, &optional_filter_block)
231
190
  end
232
191
  # defined_negated_matcher was added in RSpec 3.1 - it's syntactic sugar only since a user can do
233
192
  # expect(page).not_to match_selector, so not sure we really need to support not_match_selector for prior to RSpec 3.1
@@ -238,16 +197,16 @@ module Capybara
238
197
  HaveSelector.new(:xpath, xpath, options, &optional_filter_block)
239
198
  end
240
199
 
241
- def match_xpath(xpath, options={})
242
- MatchSelector.new(:xpath, xpath, options)
200
+ def match_xpath(xpath, options={}, &optional_filter_block)
201
+ MatchSelector.new(:xpath, xpath, options, &optional_filter_block)
243
202
  end
244
203
 
245
204
  def have_css(css, options={}, &optional_filter_block)
246
205
  HaveSelector.new(:css, css, options, &optional_filter_block)
247
206
  end
248
207
 
249
- def match_css(css, options={})
250
- MatchSelector.new(:css, css, options)
208
+ def match_css(css, options={}, &optional_filter_block)
209
+ MatchSelector.new(:css, css, options, &optional_filter_block)
251
210
  end
252
211
 
253
212
  def have_text(*args)
@@ -307,6 +266,5 @@ module Capybara
307
266
  def become_closed(options = {})
308
267
  BecomeClosed.new(options)
309
268
  end
310
-
311
269
  end
312
270
  end