Skip to content

Commit 14b3aab

Browse files
committed
metaprogram the rack_test stale check
1 parent b3d8ddb commit 14b3aab

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

lib/capybara/rack_test/node.rb

+12-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
66
BLOCK_ELEMENTS = %w[p h1 h2 h3 h4 h5 h6 ol ul pre address blockquote dl div fieldset form hr noscript table].freeze
77

88
def all_text
9-
stale_check
109
native.text
1110
.gsub(/[\u200b\u200e\u200f]/, '')
1211
.gsub(/[\ \n\f\t\v\u2028\u2029]+/, ' ')
@@ -16,7 +15,6 @@ def all_text
1615
end
1716

1817
def visible_text
19-
stale_check
2018
displayed_text.gsub(/\ +/, ' ')
2119
.gsub(/[\ \n]*\n[\ \n]*/, "\n")
2220
.gsub(/\A[[:space:]&&[^\u00a0]]+/, '')
@@ -25,7 +23,6 @@ def visible_text
2523
end
2624

2725
def [](name)
28-
stale_check
2926
string_node[name]
3027
end
3128

@@ -34,12 +31,10 @@ def style(_styles)
3431
end
3532

3633
def value
37-
stale_check
3834
string_node.value
3935
end
4036

4137
def set(value, **options)
42-
stale_check
4338
return if disabled? || readonly?
4439

4540
warn "Options passed to Node#set but the RackTest driver doesn't support any - ignoring" unless options.empty?
@@ -56,15 +51,13 @@ def set(value, **options)
5651
end
5752

5853
def select_option
59-
stale_check
6054
return if disabled?
6155

6256
deselect_options unless select_node.multiple?
6357
native['selected'] = 'selected'
6458
end
6559

6660
def unselect_option
67-
stale_check
6861
raise Capybara::UnselectNotAllowed, 'Cannot unselect option from single select box.' unless select_node.multiple?
6962

7063
native.remove_attribute('selected')
@@ -73,8 +66,6 @@ def unselect_option
7366
def click(keys = [], **offset)
7467
raise ArgumentError, 'The RackTest driver does not support click options' unless keys.empty? && offset.empty?
7568

76-
stale_check
77-
7869
if link?
7970
follow_link
8071
elsif submits?
@@ -88,27 +79,22 @@ def click(keys = [], **offset)
8879
end
8980

9081
def tag_name
91-
stale_check
9282
native.node_name
9383
end
9484

9585
def visible?
96-
stale_check
9786
string_node.visible?
9887
end
9988

10089
def checked?
101-
stale_check
10290
string_node.checked?
10391
end
10492

10593
def selected?
106-
stale_check
10794
string_node.selected?
10895
end
10996

11097
def disabled?
111-
stale_check
11298
return true if string_node.disabled?
11399

114100
if %w[option optgroup].include? tag_name
@@ -122,20 +108,27 @@ def path
122108
native.path
123109
end
124110

125-
def find_xpath(locator)
126-
stale_check
111+
def find_xpath(locator, **_hints)
127112
native.xpath(locator).map { |el| self.class.new(driver, el) }
128113
end
129114

130-
def find_css(locator)
131-
stale_check
115+
def find_css(locator, **_hints)
132116
native.css(locator, Capybara::RackTest::CSSHandlers.new).map { |el| self.class.new(driver, el) }
133117
end
134118

119+
self.public_instance_methods(false).each do |meth_name|
120+
alias_method "unchecked_#{meth_name}", meth_name
121+
private "unchecked_#{meth_name}"
122+
define_method meth_name do |*args|
123+
stale_check
124+
send("unchecked_#{meth_name}", *args)
125+
end
126+
end
127+
135128
def ==(other)
136129
native == other.native
137130
end
138-
131+
139132
protected
140133

141134
# @api private

0 commit comments

Comments
 (0)