Skip to content

Commit

Permalink
matches_selector? should allow all of the selectors filters
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Sep 23, 2016
1 parent 09d350e commit 109cfab
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Release date: unreleased

### Fixed
* allow_label_click option did not work in some cases with Poltergeist - Issue #1762 [Thomas Walpole]
* matches_selector? should have access to all of a selectors filters [Thomas Walpole]

#Version 2.9.0
Release date: 2016-09-19
Expand Down
4 changes: 1 addition & 3 deletions lib/capybara/queries/match_query.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Capybara
module Queries
class MatchQuery < Capybara::Queries::SelectorQuery
VALID_KEYS = [:text, :visible, :exact, :wait]

def visible
if options.has_key?(:visible)
super
Expand All @@ -14,7 +12,7 @@ def visible
private

def valid_keys
VALID_KEYS + @selector.custom_filters.keys
super - COUNT_KEYS
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/capybara/spec/session/element/matches_selector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
expect(@element.matches_xpath?("//span", text: '42')).to be true
expect(@element.matches_xpath?("//span", text: 'Nope')).to be false
end

it 'should accept selector filters' do
@session.visit('/form')
cbox = @session.find(:css, '#form_pets_dog')
expect(cbox.matches_selector?(:checkbox, id: 'form_pets_dog', option: 'dog', name: 'form[pets][]', checked: true)).to be true
end
end

Capybara::SpecHelper.spec '#not_matches_selector?' do
Expand Down
4 changes: 2 additions & 2 deletions spec/selector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
end
end

context "with :id option", twtw: true do
context "with :id option" do
it "works with compound css selectors" do
expect(string.all(:custom_css_selector, "div, h1", id: 'page').size).to eq 1
expect(string.all(:custom_css_selector, "h1, div", id: 'page').size).to eq 1
Expand All @@ -109,7 +109,7 @@
end
end

context "with :class option", twtw: true do
context "with :class option" do
it "works with compound css selectors" do
expect(string.all(:custom_css_selector, "div, h1", class: 'a').size).to eq 2
expect(string.all(:custom_css_selector, "h1, div", class: 'a').size).to eq 2
Expand Down

0 comments on commit 109cfab

Please sign in to comment.