# frozen_string_literal: trueCapybara::SpecHelper.spec'#match_selector?'dobeforedo@session.visit('/with_html')@element=@session.find('//span',text: '42')endit'should be true if the element matches the given selector'doexpect(@element).tomatch_selector(:xpath,'//span')expect(@element).tomatch_selector(:css,'span.number')expect(@element.matches_selector?(:css,'span.number')).tobetrueendit'should be false if the element does not match the given selector'doexpect(@element).not_tomatch_selector(:xpath,'//div')expect(@element).not_tomatch_selector(:css,'span.not_a_number')expect(@element.matches_selector?(:css,'span.not_a_number')).tobefalseendit'should use default selector'doCapybara.default_selector=:cssexpect(@element).not_tomatch_selector('span.not_a_number')expect(@element).tomatch_selector('span.number')endit'should work with elements located via a sibling selector'dosibling=@element.sibling(:css,'span',text: 'Other span')expect(sibling).tomatch_selector(:xpath,'//span')expect(sibling).tomatch_selector(:css,'span')endit'should work with the html element'dohtml=@session.find('/html')expect(html).tomatch_selector(:css,'html')endcontext'with text'doit'should discard all matches where the given string is not contained'doexpect(@element).tomatch_selector('//span',text: '42')expect(@element).not_tomatch_selector('//span',text: 'Doesnotexist')endendit'should have css sugar'doexpect(@element.matches_css?('span.number')).tobetrueexpect(@element.matches_css?('span.not_a_number')).tobefalseexpect(@element.matches_css?('span.number',text: '42')).tobetrueexpect(@element.matches_css?('span.number',text: 'Nope')).tobefalseendit'should have xpath sugar'doexpect(@element.matches_xpath?('//span')).tobetrueexpect(@element.matches_xpath?('//div')).tobefalseexpect(@element.matches_xpath?('//span',text: '42')).tobetrueexpect(@element.matches_xpath?('//span',text: 'Nope')).tobefalseendit'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)).tobetrueendit'should accept a custom filter block'do@session.visit('/form')cbox=@session.find(:css,'#form_pets_dog')expect(cbox).tomatch_selector(:checkbox){|node|node[:id]=='form_pets_dog'}expect(cbox).not_tomatch_selector(:checkbox){|node|node[:id]!='form_pets_dog'}expect(cbox.matches_selector?(:checkbox){|node|node[:id]=='form_pets_dog'}).tobetrueexpect(cbox.matches_selector?(:checkbox){|node|node[:id]!='form_pets_dog'}).tobefalseendendCapybara::SpecHelper.spec'#not_matches_selector?'dobeforedo@session.visit('/with_html')@element=@session.find(:css,'span',text: 42)endit'should be false if the given selector matches the element'doexpect(@element).not_tonot_match_selector(:xpath,'//span')expect(@element).not_tonot_match_selector(:css,'span.number')expect(@element.not_matches_selector?(:css,'span.number')).tobefalseendit'should be true if the given selector does not match the element'doexpect(@element).tonot_match_selector(:xpath,'//abbr')expect(@element).tonot_match_selector(:css,'p a#doesnotexist')expect(@element.not_matches_selector?(:css,'p a#doesnotexist')).tobetrueendit'should use default selector'doCapybara.default_selector=:cssexpect(@element).tonot_match_selector('p a#doesnotexist')expect(@element).not_tonot_match_selector('span.number')endcontext'with text'doit'should discard all matches where the given string is contained'doexpect(@element).not_tonot_match_selector(:css,'span.number',text: '42')expect(@element).tonot_match_selector(:css,'span.number',text: 'Doesnotexist')endendit'should have CSS sugar'doexpect(@element.not_matches_css?('span.number')).tobefalseexpect(@element.not_matches_css?('p a#doesnotexist')).tobetrueexpect(@element.not_matches_css?('span.number',text: '42')).tobefalseexpect(@element.not_matches_css?('span.number',text: 'Doesnotexist')).tobetrueendit'should have xpath sugar'doexpect(@element.not_matches_xpath?('//span')).tobefalseexpect(@element.not_matches_xpath?('//div')).tobetrueexpect(@element.not_matches_xpath?('//span',text: '42')).tobefalseexpect(@element.not_matches_xpath?('//span',text: 'Doesnotexist')).tobetrueendend