Skip to content

Commit

Permalink
Merge pull request #2131 from teamcapybara/link_or_button_expression
Browse files Browse the repository at this point in the history
Fix :button selector evaluating :link_or_button expression filters
  • Loading branch information
twalpole authored Nov 16, 2018
2 parents 48b14e3 + 99790eb commit 2635eff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/capybara/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,9 @@
image_btn_xpath = image_btn_xpath[alt_matches]
end

res_xpath = input_btn_xpath.union(btn_xpath).union(image_btn_xpath)

res_xpath = expression_filters.keys.inject(res_xpath) { |memo, ef| memo[find_by_attr(ef, options[ef])] }

res_xpath
%i[value title type].inject(input_btn_xpath.union(btn_xpath).union(image_btn_xpath)) do |memo, ef|
memo[find_by_attr(ef, options[ef])]
end
end

node_filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| !(value ^ node.disabled?) }
Expand Down
16 changes: 16 additions & 0 deletions spec/selector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,22 @@
expect(string.find(:element, 'input', title: XPath.contains_word('button 1'))[:type]).to eq 'button'
end
end

describe ':link_or_button selector' do
around(:all) do |example|
Capybara.modify_selector(:link_or_button) do
expression_filter(:random) { |xpath, _| xpath } # do nothing filter
end
example.run
Capybara::Selector.all[:link_or_button].expression_filters.delete(:random)
end

context 'when modified' do
it 'should still work' do
expect(string.find(:link_or_button, 'click me', random: 'blah').value).to eq 'click me'
end
end
end
end
end
end

0 comments on commit 2635eff

Please sign in to comment.