mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Fix negated class selector option - Issue #2103
This commit is contained in:
parent
a42054fafc
commit
31afeef047
3 changed files with 25 additions and 18 deletions
|
@ -1,3 +1,10 @@
|
|||
# Version 3.8.2
|
||||
Release date: unreleased
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed negated class selector option - Issue #2103
|
||||
|
||||
# Version 3.8.1
|
||||
Release date: 2018-09-22
|
||||
|
||||
|
|
|
@ -256,7 +256,7 @@ module Capybara
|
|||
|
||||
classes = Array(options[:class]).group_by { |cl| cl.start_with? '!' }
|
||||
(classes[false].to_a.map { |cl| ".#{Capybara::Selector::CSS.escape(cl)}" } +
|
||||
classes[true].to_a.map { |cl| ":not(.#{Capybara::Selector::CSS.escape(cl.slice(1))})" }).join
|
||||
classes[true].to_a.map { |cl| ":not(.#{Capybara::Selector::CSS.escape(cl.slice(1..-1))})" }).join
|
||||
end
|
||||
|
||||
def css_from_id
|
||||
|
@ -272,7 +272,7 @@ module Capybara
|
|||
|
||||
Array(options[:class]).map do |klass|
|
||||
if klass.start_with?('!')
|
||||
!XPath.attr(:class).contains_word(klass.slice(1))
|
||||
!XPath.attr(:class).contains_word(klass.slice(1..-1))
|
||||
else
|
||||
XPath.attr(:class).contains_word(klass)
|
||||
end
|
||||
|
|
|
@ -11,13 +11,13 @@ RSpec.describe Capybara do
|
|||
<title>selectors</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="a" id="page">
|
||||
<div class="b" id="content">
|
||||
<h1 class="a">Totally awesome</h1>
|
||||
<div class="aa" id="page">
|
||||
<div class="bb" id="content">
|
||||
<h1 class="aa">Totally awesome</h1>
|
||||
<p>Yes it is</p>
|
||||
</div>
|
||||
<p class="b c">Some Content</p>
|
||||
<p class="b d"></p>
|
||||
<p class="bb cc">Some Content</p>
|
||||
<p class="bb dd"></p>
|
||||
</div>
|
||||
<div id="#special">
|
||||
</div>
|
||||
|
@ -84,12 +84,12 @@ RSpec.describe Capybara do
|
|||
|
||||
describe 'modify_selector' do
|
||||
it 'allows modifying a selector' do
|
||||
el = string.find(:custom_selector, 'a')
|
||||
el = string.find(:custom_selector, 'aa')
|
||||
expect(el.tag_name).to eq 'div'
|
||||
Capybara.modify_selector :custom_selector do
|
||||
css { |css_class| "h1.#{css_class}" }
|
||||
end
|
||||
el = string.find(:custom_selector, 'a')
|
||||
el = string.find(:custom_selector, 'aa')
|
||||
expect(el.tag_name).to eq 'h1'
|
||||
end
|
||||
|
||||
|
@ -97,9 +97,9 @@ RSpec.describe Capybara do
|
|||
Capybara.modify_selector :custom_selector do
|
||||
css { |css_class| "p.#{css_class}" }
|
||||
end
|
||||
expect(string).to have_selector(:custom_selector, 'b', count: 1)
|
||||
expect(string).to have_selector(:custom_selector, 'b', not_empty: false, count: 1)
|
||||
expect(string).to have_selector(:custom_selector, 'b', not_empty: :all, count: 2)
|
||||
expect(string).to have_selector(:custom_selector, 'bb', count: 1)
|
||||
expect(string).to have_selector(:custom_selector, 'bb', not_empty: false, count: 1)
|
||||
expect(string).to have_selector(:custom_selector, 'bb', not_empty: :all, count: 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -151,15 +151,15 @@ RSpec.describe Capybara 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
|
||||
expect(string.all(:custom_css_selector, 'div, h1', class: 'aa').size).to eq 2
|
||||
expect(string.all(:custom_css_selector, 'h1, div', class: 'aa').size).to eq 2
|
||||
end
|
||||
|
||||
it 'handles negated classes' do
|
||||
expect(string.all(:custom_css_selector, 'div, p', class: ['b', '!c']).size).to eq 2
|
||||
expect(string.all(:custom_css_selector, 'div, p', class: ['!c', '!d', 'b']).size).to eq 1
|
||||
expect(string.all(:custom_xpath_selector, XPath.descendant(:div, :p), class: ['b', '!c']).size).to eq 2
|
||||
expect(string.all(:custom_xpath_selector, XPath.descendant(:div, :p), class: ['!c', '!d', 'b']).size).to eq 1
|
||||
expect(string.all(:custom_css_selector, 'div, p', class: ['bb', '!cc']).size).to eq 2
|
||||
expect(string.all(:custom_css_selector, 'div, p', class: ['!cc', '!dd', 'bb']).size).to eq 1
|
||||
expect(string.all(:custom_xpath_selector, XPath.descendant(:div, :p), class: ['bb', '!cc']).size).to eq 2
|
||||
expect(string.all(:custom_xpath_selector, XPath.descendant(:div, :p), class: ['!cc', '!dd', 'bb']).size).to eq 1
|
||||
end
|
||||
|
||||
it "works with 'special' characters" do
|
||||
|
|
Loading…
Add table
Reference in a new issue