From 109cfaba2e3ffc20b8ac4b56d006525fd6139a78 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Fri, 23 Sep 2016 09:56:07 -0700 Subject: [PATCH] matches_selector? should allow all of the selectors filters --- History.md | 1 + lib/capybara/queries/match_query.rb | 4 +--- lib/capybara/spec/session/element/matches_selector_spec.rb | 6 ++++++ spec/selector_spec.rb | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/History.md b/History.md index 96c9ed51..b05544ca 100644 --- a/History.md +++ b/History.md @@ -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 diff --git a/lib/capybara/queries/match_query.rb b/lib/capybara/queries/match_query.rb index 682ac920..3df28d84 100644 --- a/lib/capybara/queries/match_query.rb +++ b/lib/capybara/queries/match_query.rb @@ -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 @@ -14,7 +12,7 @@ module Capybara private def valid_keys - VALID_KEYS + @selector.custom_filters.keys + super - COUNT_KEYS end end end diff --git a/lib/capybara/spec/session/element/matches_selector_spec.rb b/lib/capybara/spec/session/element/matches_selector_spec.rb index 76433fb7..10f7e737 100644 --- a/lib/capybara/spec/session/element/matches_selector_spec.rb +++ b/lib/capybara/spec/session/element/matches_selector_spec.rb @@ -42,6 +42,12 @@ Capybara::SpecHelper.spec '#match_selector?' do 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 diff --git a/spec/selector_spec.rb b/spec/selector_spec.rb index 103d7f5f..7c3a3799 100644 --- a/spec/selector_spec.rb +++ b/spec/selector_spec.rb @@ -96,7 +96,7 @@ RSpec.describe Capybara do 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 @@ -109,7 +109,7 @@ RSpec.describe Capybara do 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