mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Added :between, :maximum, and :minimum conditions to has_css? and
has_no_css? matcher methods.
This commit is contained in:
parent
8229d13d45
commit
45b55b138d
3 changed files with 141 additions and 7 deletions
|
@ -37,11 +37,21 @@ module Capybara
|
|||
wait_conditionally_until do
|
||||
results = all(*args)
|
||||
|
||||
if options[:count]
|
||||
results.size == options[:count]
|
||||
return false if results.empty?
|
||||
|
||||
case
|
||||
when options[:between]
|
||||
options[:between] === results.size
|
||||
when options[:count]
|
||||
options[:count] == results.size
|
||||
when options[:maximum]
|
||||
options[:maximum] >= results.size
|
||||
when options[:minimum]
|
||||
options[:minimum] <= results.size
|
||||
else
|
||||
results.size > 0
|
||||
end
|
||||
|
||||
end
|
||||
rescue Capybara::TimeoutError
|
||||
return false
|
||||
|
@ -60,11 +70,21 @@ module Capybara
|
|||
wait_conditionally_until do
|
||||
results = all(*args)
|
||||
|
||||
if options[:count]
|
||||
results.size != options[:count]
|
||||
return true if results.empty?
|
||||
|
||||
case
|
||||
when options[:between]
|
||||
not(options[:between] === results.size)
|
||||
when options[:count]
|
||||
not(options[:count] == results.size)
|
||||
when options[:maximum]
|
||||
not(options[:maximum] >= results.size)
|
||||
when options[:minimum]
|
||||
not(options[:minimum] <= results.size)
|
||||
else
|
||||
results.empty?
|
||||
end
|
||||
|
||||
end
|
||||
rescue Capybara::TimeoutError
|
||||
return false
|
||||
|
|
|
@ -22,13 +22,30 @@ shared_examples_for "has_css" do
|
|||
end
|
||||
end
|
||||
|
||||
context "with between" do
|
||||
it "should be true if the content occurs within the range given" do
|
||||
@session.should have_css("p", :between => 1..4)
|
||||
@session.should have_css("p a#foo", :between => 1..3)
|
||||
end
|
||||
|
||||
it "should be false if the content occurs more or fewer times than range" do
|
||||
@session.should_not have_css("p", :between => 6..11 )
|
||||
@session.should_not have_css("p a#foo", :between => 4..7)
|
||||
end
|
||||
|
||||
it "should be false if the content isn't on the page at all" do
|
||||
@session.should_not have_css("abbr", :between => 1..8)
|
||||
@session.should_not have_css("p a.doesnotexist", :between => 3..8)
|
||||
end
|
||||
end
|
||||
|
||||
context "with count" do
|
||||
it "should be true if the content is on the page the given number of times" do
|
||||
@session.should have_css("p", :count => 3)
|
||||
@session.should have_css("p a#foo", :count => 1)
|
||||
end
|
||||
|
||||
it "should be false if the content is on the page the given number of times" do
|
||||
it "should be false if the content occurs the given number of times" do
|
||||
@session.should_not have_css("p", :count => 6)
|
||||
@session.should_not have_css("p a#foo", :count => 2)
|
||||
end
|
||||
|
@ -39,6 +56,42 @@ shared_examples_for "has_css" do
|
|||
end
|
||||
end
|
||||
|
||||
context "with maximum" do
|
||||
it "should be true when content occurs same or fewer times than given" do
|
||||
@session.should have_css("h2.head", :maximum => 5) # edge case
|
||||
@session.should have_css("h2", :maximum => 10)
|
||||
end
|
||||
|
||||
it "should be false when content occurs more times than given" do
|
||||
@session.should_not have_css("h2.head", :maximum => 4) # edge case
|
||||
@session.should_not have_css("h2", :maximum => 6)
|
||||
@session.should_not have_css("p", :maximum => 1)
|
||||
end
|
||||
|
||||
it "should be false if the content isn't on the page at all" do
|
||||
@session.should_not have_css("abbr", :maximum => 2)
|
||||
@session.should_not have_css("p a.doesnotexist", :maximum => 1)
|
||||
end
|
||||
end
|
||||
|
||||
context "with minimum" do
|
||||
it "should be true when content occurs same or more times than given" do
|
||||
@session.should have_css("h2.head", :minimum => 5) # edge case
|
||||
@session.should have_css("h2", :minimum => 3)
|
||||
end
|
||||
|
||||
it "should be false when content occurs fewer times than given" do
|
||||
@session.should_not have_css("h2.head", :minimum => 6) # edge case
|
||||
@session.should_not have_css("h2", :minimum => 8)
|
||||
@session.should_not have_css("p", :minimum => 10)
|
||||
end
|
||||
|
||||
it "should be false if the content isn't on the page at all" do
|
||||
@session.should_not have_css("abbr", :minimum => 2)
|
||||
@session.should_not have_css("p a.doesnotexist", :minimum => 7)
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is not contained" do
|
||||
@session.should have_css("p a", :text => "Redirect", :count => 1)
|
||||
|
@ -75,6 +128,23 @@ shared_examples_for "has_css" do
|
|||
end
|
||||
end
|
||||
|
||||
context "with between" do
|
||||
it "should be false if the content occurs within the range given" do
|
||||
@session.should_not have_no_css("p", :between => 1..4)
|
||||
@session.should_not have_no_css("p a#foo", :between => 1..3)
|
||||
end
|
||||
|
||||
it "should be true if the content occurs more or fewer times than range" do
|
||||
@session.should have_no_css("p", :between => 6..11 )
|
||||
@session.should have_no_css("p a#foo", :between => 4..7)
|
||||
end
|
||||
|
||||
it "should be true if the content isn't on the page at all" do
|
||||
@session.should have_no_css("abbr", :between => 1..8)
|
||||
@session.should have_no_css("p a.doesnotexist", :between => 3..8)
|
||||
end
|
||||
end
|
||||
|
||||
context "with count" do
|
||||
it "should be false if the content is on the page the given number of times" do
|
||||
@session.should_not have_no_css("p", :count => 3)
|
||||
|
@ -92,6 +162,42 @@ shared_examples_for "has_css" do
|
|||
end
|
||||
end
|
||||
|
||||
context "with maximum" do
|
||||
it "should be false when content occurs same or fewer times than given" do
|
||||
@session.should_not have_no_css("h2.head", :maximum => 5) # edge case
|
||||
@session.should_not have_no_css("h2", :maximum => 10)
|
||||
end
|
||||
|
||||
it "should be true when content occurs more times than given" do
|
||||
@session.should have_no_css("h2.head", :maximum => 4) # edge case
|
||||
@session.should have_no_css("h2", :maximum => 6)
|
||||
@session.should have_no_css("p", :maximum => 1)
|
||||
end
|
||||
|
||||
it "should be true if the content isn't on the page at all" do
|
||||
@session.should have_no_css("abbr", :maximum => 5)
|
||||
@session.should have_no_css("p a.doesnotexist", :maximum => 10)
|
||||
end
|
||||
end
|
||||
|
||||
context "with minimum" do
|
||||
it "should be false when content occurs more times than given" do
|
||||
@session.should_not have_no_css("h2.head", :minimum => 4) # edge case
|
||||
@session.should_not have_no_css("h2", :minimum => 3)
|
||||
end
|
||||
|
||||
it "should be true when content occurs fewer times than given" do
|
||||
@session.should have_no_css("h2.head", :minimum => 6) # edge case
|
||||
@session.should have_no_css("h2", :minimum => 8)
|
||||
@session.should have_no_css("p", :minimum => 15)
|
||||
end
|
||||
|
||||
it "should be true if the content isn't on the page at all" do
|
||||
@session.should have_no_css("abbr", :minimum => 5)
|
||||
@session.should have_no_css("p a.doesnotexist", :minimum => 10)
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is not contained" do
|
||||
@session.should_not have_no_css("p a", :text => "Redirect", :count => 1)
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
<h1>This is a test</h1>
|
||||
|
||||
<p id="first">
|
||||
<h2 class="no text"></h2>
|
||||
<h2 class="no text"></h2>
|
||||
<h2 class="head" id="h2one">Header Class Test One</h2>
|
||||
<h2 class="head" id="h2two">Header Class Test Two</h2>
|
||||
<h2 class="head">Header Class Test Three</h2>
|
||||
<h2 class="head">Header Class Test Four</h2>
|
||||
<h2 class="head">Header Class Test Five</h2>
|
||||
|
||||
<p class="para" id="first">
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
||||
tempor incididunt ut <a href="/with_simple_html" title="awesome title" class="simple">labore</a>
|
||||
et dolore magna aliqua. Ut enim ad minim veniam,
|
||||
|
@ -9,7 +17,7 @@
|
|||
<a href="/with_simple_html"><img src="http://www.foobar.sun/dummy_image.jpg" width="20" height="20" alt="awesome image" /></a>
|
||||
</p>
|
||||
|
||||
<p id="second">
|
||||
<p class="para" id="second">
|
||||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
|
||||
dolore eu fugiat <a href="/redirect" id="red">Redirect</a> pariatur. Excepteur sint occaecat cupidatat non proident,
|
||||
sunt in culpa qui officia
|
||||
|
|
Loading…
Reference in a new issue