2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2018-02-28 19:11:41 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#has_css?' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be true if the given selector is on the page' do
|
|
|
|
expect(@session).to have_css('p')
|
|
|
|
expect(@session).to have_css('p a#foo')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
2019-05-20 12:39:50 -04:00
|
|
|
it 'should warn when passed a symbol' do
|
2018-09-03 23:38:41 -04:00
|
|
|
# This was never a specifically accepted format but it has worked for a
|
2019-05-20 12:39:50 -04:00
|
|
|
# lot of versions.
|
|
|
|
# TODO: Remove in 4.0
|
2020-09-06 15:21:53 -04:00
|
|
|
allow(Capybara::Helpers).to receive(:warn).and_return(nil)
|
2018-09-03 23:38:41 -04:00
|
|
|
expect(@session).to have_css(:p)
|
2020-09-06 15:21:53 -04:00
|
|
|
expect(Capybara::Helpers).to have_received(:warn)
|
2018-09-03 23:38:41 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be false if the given selector is not on the page' do
|
|
|
|
expect(@session).not_to have_css('abbr')
|
|
|
|
expect(@session).not_to have_css('p a#doesnotexist')
|
|
|
|
expect(@session).not_to have_css('p.nosuchclass')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
2018-10-01 16:15:00 -04:00
|
|
|
it 'should support :id option' do
|
|
|
|
expect(@session).to have_css('h2', id: 'h2one')
|
|
|
|
expect(@session).to have_css('h2')
|
|
|
|
expect(@session).to have_css('h2', id: /h2o/)
|
2018-11-27 17:08:40 -05:00
|
|
|
expect(@session).to have_css('li', id: /john|paul/)
|
2018-10-01 16:15:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should support :class option' do
|
|
|
|
expect(@session).to have_css('li', class: 'guitarist')
|
|
|
|
expect(@session).to have_css('li', class: /guitar/)
|
2018-11-27 17:08:40 -05:00
|
|
|
expect(@session).to have_css('li', class: /guitar|drummer/)
|
|
|
|
expect(@session).to have_css('li', class: %w[beatle guitarist])
|
|
|
|
expect(@session).to have_css('li', class: /.*/)
|
2018-10-01 16:15:00 -04:00
|
|
|
end
|
|
|
|
|
2018-12-02 19:07:40 -05:00
|
|
|
context ':style option' do
|
|
|
|
it 'should support String' do
|
|
|
|
expect(@session).to have_css('p', style: 'line-height: 25px;')
|
2018-12-06 16:46:53 -05:00
|
|
|
|
|
|
|
expect do
|
|
|
|
expect(@session).to have_css('p', style: 'display: not_valid')
|
|
|
|
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /style attribute "display: not_valid"/)
|
2018-12-02 19:07:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should support Regexp' do
|
|
|
|
expect(@session).to have_css('p', style: /-height: 2/)
|
2018-12-06 16:46:53 -05:00
|
|
|
|
|
|
|
expect do
|
|
|
|
expect(@session).to have_css('p', style: /not_valid/)
|
|
|
|
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, %r{style attribute matching /not_valid/})
|
2018-12-02 19:07:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should support Hash', requires: [:css] do
|
|
|
|
expect(@session).to have_css('p', style: { 'line-height': '25px' })
|
2018-12-06 16:46:53 -05:00
|
|
|
|
|
|
|
expect do
|
|
|
|
expect(@session).to have_css('p', style: { 'line-height': '30px' })
|
|
|
|
end.to raise_error(RSpec::Expectations::ExpectationNotMetError, /with styles \{:"line-height"=>"30px"\}/)
|
2018-12-02 19:07:40 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-01 16:15:00 -04:00
|
|
|
it 'should support case insensitive :class and :id options' do
|
|
|
|
expect(@session).to have_css('li', class: /UiTaRI/i)
|
|
|
|
expect(@session).to have_css('h2', id: /2ON/i)
|
|
|
|
end
|
|
|
|
|
2018-10-29 13:16:29 -04:00
|
|
|
context 'when scoped' do
|
|
|
|
it 'should look in the scope' do
|
|
|
|
@session.within "//p[@id='first']" do
|
|
|
|
expect(@session).to have_css('a#foo')
|
|
|
|
expect(@session).not_to have_css('a#red')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-01 14:43:30 -04:00
|
|
|
it 'should be able to generate an error message if the scope is a sibling' do
|
2018-10-29 13:16:29 -04:00
|
|
|
el = @session.find(:css, '#first')
|
|
|
|
@session.within el.sibling(:css, '#second') do
|
2018-11-02 14:38:58 -04:00
|
|
|
expect do
|
2018-10-29 13:16:29 -04:00
|
|
|
expect(@session).to have_css('a#not_on_page')
|
2018-11-02 14:38:58 -04:00
|
|
|
end.to raise_error(/there were no matches/)
|
2018-10-29 13:16:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-01 14:43:30 -04:00
|
|
|
it 'should be able to generate an error message if the scope is a sibling from XPath' do
|
2018-10-29 13:16:29 -04:00
|
|
|
el = @session.find(:css, '#first').find(:xpath, './following-sibling::*[1]') do
|
2018-11-02 14:38:58 -04:00
|
|
|
expect do
|
2018-10-29 13:16:29 -04:00
|
|
|
expect(el).to have_css('a#not_on_page')
|
2018-11-02 14:38:58 -04:00
|
|
|
end.to raise_error(/there were no matches/)
|
2018-10-29 13:16:29 -04:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should wait for content to appear', requires: [:js] do
|
2018-07-05 21:08:59 -04:00
|
|
|
Capybara.default_max_wait_time = 2
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Click me')
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session).to have_css("input[type='submit'][value='New Here']")
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
2018-07-23 17:57:22 -04:00
|
|
|
context 'with predicates_wait == true' do
|
|
|
|
it 'should wait for content to appear', requires: [:js] do
|
|
|
|
Capybara.predicates_wait = true
|
|
|
|
Capybara.default_max_wait_time = 2
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Click me')
|
|
|
|
expect(@session.has_css?("input[type='submit'][value='New Here']")).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with predicates_wait == false' do
|
2019-03-26 20:21:41 -04:00
|
|
|
before do
|
2018-07-23 17:57:22 -04:00
|
|
|
Capybara.predicates_wait = false
|
2019-03-26 20:21:41 -04:00
|
|
|
Capybara.default_max_wait_time = 5
|
2018-07-23 17:57:22 -04:00
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Click me')
|
2019-03-26 20:21:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not wait for content to appear', requires: [:js] do
|
2018-07-23 17:57:22 -04:00
|
|
|
expect(@session.has_css?("input[type='submit'][value='New Here']")).to be false
|
|
|
|
end
|
2019-03-26 20:21:41 -04:00
|
|
|
|
2019-03-27 13:43:43 -04:00
|
|
|
it 'should should the default wait time if true is passed for :wait', requires: [:js] do
|
2019-03-26 20:21:41 -04:00
|
|
|
expect(@session.has_css?("input[type='submit'][value='New Here']", wait: true)).to be true
|
|
|
|
end
|
2018-07-23 17:57:22 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with between' do
|
|
|
|
it 'should be true if the content occurs within the range given' do
|
|
|
|
expect(@session).to have_css('p', between: 1..4)
|
|
|
|
expect(@session).to have_css('p a#foo', between: 1..3)
|
|
|
|
expect(@session).to have_css('p a.doesnotexist', between: 0..8)
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be false if the content occurs more or fewer times than range' do
|
|
|
|
expect(@session).not_to have_css('p', between: 6..11)
|
|
|
|
expect(@session).not_to have_css('p a#foo', between: 4..7)
|
|
|
|
expect(@session).not_to have_css('p a.doesnotexist', between: 3..8)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with count' do
|
|
|
|
it 'should be true if the content occurs the given number of times' do
|
|
|
|
expect(@session).to have_css('p', count: 3)
|
2019-05-07 19:56:02 -04:00
|
|
|
expect(@session).to have_css('p').exactly(3).times
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).to have_css('p a#foo', count: 1)
|
2019-05-07 19:56:02 -04:00
|
|
|
expect(@session).to have_css('p a#foo').once
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).to have_css('p a.doesnotexist', count: 0)
|
2018-11-27 17:08:40 -05:00
|
|
|
expect(@session).to have_css('li', class: /guitar|drummer/, count: 4)
|
|
|
|
expect(@session).to have_css('li', id: /john|paul/, class: /guitar|drummer/, count: 2)
|
|
|
|
expect(@session).to have_css('li', class: %w[beatle guitarist], count: 2)
|
2018-12-02 19:07:40 -05:00
|
|
|
expect(@session).to have_css('p', style: 'line-height: 25px;', count: 1)
|
|
|
|
expect(@session).to have_css('p', style: /-height: 2/, count: 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be true if the content occurs the given number of times in CSS processing drivers', requires: [:css] do
|
|
|
|
expect(@session).to have_css('p', style: { 'line-height': '25px' }, count: 1)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be false if the content occurs a different number of times than the given' do
|
|
|
|
expect(@session).not_to have_css('p', count: 6)
|
2019-05-07 19:56:02 -04:00
|
|
|
expect(@session).not_to have_css('p').exactly(5).times
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).not_to have_css('p a#foo', count: 2)
|
|
|
|
expect(@session).not_to have_css('p a.doesnotexist', count: 1)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should coerce count to an integer' do
|
|
|
|
expect(@session).to have_css('p', count: '3')
|
|
|
|
expect(@session).to have_css('p a#foo', count: '1')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with maximum' do
|
|
|
|
it 'should be true when content occurs same or fewer times than given' do
|
|
|
|
expect(@session).to have_css('h2.head', maximum: 5) # edge case
|
|
|
|
expect(@session).to have_css('h2', maximum: 10)
|
2019-05-07 19:56:02 -04:00
|
|
|
expect(@session).to have_css('h2').at_most(10).times
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).to have_css('p a.doesnotexist', maximum: 1)
|
|
|
|
expect(@session).to have_css('p a.doesnotexist', maximum: 0)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2011-02-20 19:45:53 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be false when content occurs more times than given' do
|
2019-12-27 21:28:23 -05:00
|
|
|
# expect(@session).not_to have_css('h2.head', maximum: 4) # edge case
|
|
|
|
# expect(@session).not_to have_css('h2', maximum: 3)
|
2019-05-07 19:56:02 -04:00
|
|
|
expect(@session).not_to have_css('h2').at_most(3).times
|
2019-12-27 21:28:23 -05:00
|
|
|
# expect(@session).not_to have_css('p', maximum: 1)
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should coerce maximum to an integer' do
|
|
|
|
expect(@session).to have_css('h2.head', maximum: '5') # edge case
|
|
|
|
expect(@session).to have_css('h2', maximum: '10')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with minimum' do
|
|
|
|
it 'should be true when content occurs same or more times than given' do
|
|
|
|
expect(@session).to have_css('h2.head', minimum: 5) # edge case
|
|
|
|
expect(@session).to have_css('h2', minimum: 3)
|
2019-05-07 19:56:02 -04:00
|
|
|
expect(@session).to have_css('h2').at_least(2).times
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).to have_css('p a.doesnotexist', minimum: 0)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2011-02-20 19:45:53 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be false when content occurs fewer times than given' do
|
|
|
|
expect(@session).not_to have_css('h2.head', minimum: 6) # edge case
|
|
|
|
expect(@session).not_to have_css('h2', minimum: 8)
|
2019-05-07 19:56:02 -04:00
|
|
|
expect(@session).not_to have_css('h2').at_least(8).times
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).not_to have_css('p', minimum: 10)
|
|
|
|
expect(@session).not_to have_css('p a.doesnotexist', minimum: 1)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should coerce minimum to an integer' do
|
|
|
|
expect(@session).to have_css('h2.head', minimum: '5') # edge case
|
|
|
|
expect(@session).to have_css('h2', minimum: '3')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with text' do
|
|
|
|
it 'should discard all matches where the given string is not contained' do
|
|
|
|
expect(@session).to have_css('p a', text: 'Redirect', count: 1)
|
|
|
|
expect(@session).not_to have_css('p a', text: 'Doesnotexist')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2011-02-20 19:45:53 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should discard all matches where the given regexp is not matched' do
|
|
|
|
expect(@session).to have_css('p a', text: /re[dab]i/i, count: 1)
|
|
|
|
expect(@session).not_to have_css('p a', text: /Red$/)
|
2010-10-29 12:02:43 -04:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2017-05-23 12:45:51 -04:00
|
|
|
|
2019-08-07 17:14:28 -04:00
|
|
|
context 'with spatial requirements', requires: [:spatial] do
|
|
|
|
before do
|
|
|
|
@session.visit('/spatial')
|
2020-02-17 14:49:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
let :center do
|
|
|
|
@session.find(:css, '.center')
|
2019-08-07 17:14:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'accepts spatial options' do
|
2020-02-17 14:49:12 -05:00
|
|
|
expect(@session).to have_css('div', above: center).thrice
|
|
|
|
expect(@session).to have_css('div', above: center, right_of: center).once
|
2019-08-07 17:14:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports spatial sugar' do
|
2020-02-17 14:49:12 -05:00
|
|
|
expect(@session).to have_css('div').left_of(center).thrice
|
|
|
|
expect(@session).to have_css('div').below(center).right_of(center).once
|
|
|
|
expect(@session).to have_css('div').near(center).exactly(8).times
|
2019-08-07 17:14:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should allow escapes in the CSS selector' do
|
2017-05-23 12:45:51 -04:00
|
|
|
expect(@session).to have_css('p[data-random="abc\\\\def"]')
|
|
|
|
expect(@session).to have_css("p[data-random='#{Capybara::Selector::CSS.escape('abc\def')}']")
|
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#has_no_css?' do
|
|
|
|
before do
|
|
|
|
@session.visit('/with_html')
|
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be false if the given selector is on the page' do
|
|
|
|
expect(@session).not_to have_no_css('p')
|
|
|
|
expect(@session).not_to have_no_css('p a#foo')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be true if the given selector is not on the page' do
|
|
|
|
expect(@session).to have_no_css('abbr')
|
|
|
|
expect(@session).to have_no_css('p a#doesnotexist')
|
|
|
|
expect(@session).to have_no_css('p.nosuchclass')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2011-02-20 19:45:53 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should respect scopes' do
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.within "//p[@id='first']" do
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).not_to have_no_css('a#foo')
|
|
|
|
expect(@session).to have_no_css('a#red')
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2009-12-30 11:37:56 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should wait for content to disappear', requires: [:js] do
|
2018-07-05 21:08:59 -04:00
|
|
|
Capybara.default_max_wait_time = 2
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Click me')
|
2018-07-10 17:18:39 -04:00
|
|
|
expect(@session).to have_no_css('p#change')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with between' do
|
|
|
|
it 'should be false if the content occurs within the range given' do
|
|
|
|
expect(@session).not_to have_no_css('p', between: 1..4)
|
|
|
|
expect(@session).not_to have_no_css('p a#foo', between: 1..3)
|
|
|
|
expect(@session).not_to have_no_css('p a.doesnotexist', between: 0..2)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be true if the content occurs more or fewer times than range' do
|
|
|
|
expect(@session).to have_no_css('p', between: 6..11)
|
|
|
|
expect(@session).to have_no_css('p a#foo', between: 4..7)
|
|
|
|
expect(@session).to have_no_css('p a.doesnotexist', between: 3..8)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with count' do
|
|
|
|
it 'should be false if the content is on the page the given number of times' do
|
|
|
|
expect(@session).not_to have_no_css('p', count: 3)
|
|
|
|
expect(@session).not_to have_no_css('p a#foo', count: 1)
|
|
|
|
expect(@session).not_to have_no_css('p a.doesnotexist', count: 0)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be true if the content is on the page the given number of times' do
|
|
|
|
expect(@session).to have_no_css('p', count: 6)
|
|
|
|
expect(@session).to have_no_css('p a#foo', count: 2)
|
|
|
|
expect(@session).to have_no_css('p a.doesnotexist', count: 1)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should coerce count to an integer' do
|
|
|
|
expect(@session).not_to have_no_css('p', count: '3')
|
|
|
|
expect(@session).not_to have_no_css('p a#foo', count: '1')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2011-02-20 19:45:53 -05:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with maximum' do
|
|
|
|
it 'should be false when content occurs same or fewer times than given' do
|
|
|
|
expect(@session).not_to have_no_css('h2.head', maximum: 5) # edge case
|
|
|
|
expect(@session).not_to have_no_css('h2', maximum: 10)
|
|
|
|
expect(@session).not_to have_no_css('p a.doesnotexist', maximum: 0)
|
2010-10-29 12:02:43 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be true when content occurs more times than given' do
|
|
|
|
expect(@session).to have_no_css('h2.head', maximum: 4) # edge case
|
|
|
|
expect(@session).to have_no_css('h2', maximum: 3)
|
|
|
|
expect(@session).to have_no_css('p', maximum: 1)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should coerce maximum to an integer' do
|
|
|
|
expect(@session).not_to have_no_css('h2.head', maximum: '5') # edge case
|
|
|
|
expect(@session).not_to have_no_css('h2', maximum: '10')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with minimum' do
|
|
|
|
it 'should be false when content occurs same or more times than given' do
|
|
|
|
expect(@session).not_to have_no_css('h2.head', minimum: 5) # edge case
|
|
|
|
expect(@session).not_to have_no_css('h2', minimum: 3)
|
|
|
|
expect(@session).not_to have_no_css('p a.doesnotexist', minimum: 0)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should be true when content occurs fewer times than given' do
|
|
|
|
expect(@session).to have_no_css('h2.head', minimum: 6) # edge case
|
|
|
|
expect(@session).to have_no_css('h2', minimum: 8)
|
|
|
|
expect(@session).to have_no_css('p', minimum: 15)
|
|
|
|
expect(@session).to have_no_css('p a.doesnotexist', minimum: 1)
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should coerce minimum to an integer' do
|
|
|
|
expect(@session).not_to have_no_css('h2.head', minimum: '4') # edge case
|
|
|
|
expect(@session).not_to have_no_css('h2', minimum: '3')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
context 'with text' do
|
|
|
|
it 'should discard all matches where the given string is not contained' do
|
|
|
|
expect(@session).not_to have_no_css('p a', text: 'Redirect', count: 1)
|
|
|
|
expect(@session).to have_no_css('p a', text: 'Doesnotexist')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-10-29 12:02:43 -04:00
|
|
|
|
2018-07-10 17:18:39 -04:00
|
|
|
it 'should discard all matches where the given regexp is not matched' do
|
|
|
|
expect(@session).not_to have_no_css('p a', text: /re[dab]i/i, count: 1)
|
|
|
|
expect(@session).to have_no_css('p a', text: /Red$/)
|
2009-12-30 11:37:56 -05:00
|
|
|
end
|
2009-12-15 14:58:51 -05:00
|
|
|
end
|
2010-01-18 14:33:22 -05:00
|
|
|
end
|