1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

predicates should be boolean

This commit is contained in:
Thomas Walpole 2016-02-01 10:54:51 -08:00
parent 3f5c36f1a4
commit 0c7ea1b4dc
3 changed files with 44 additions and 3 deletions

View file

@ -115,7 +115,7 @@ module Capybara
# @return [Boolean] Whether the element is checked
#
def checked?
native[:checked]
native.has_attribute?('checked')
end
##
@ -124,7 +124,7 @@ module Capybara
#
# @return [Boolean] Whether the element is disabled
def disabled?
native[:disabled]
native.has_attribute?('disabled')
end
##
@ -134,7 +134,7 @@ module Capybara
# @return [Boolean] Whether the element is selected
#
def selected?
native[:selected]
native.has_attribute?('selected')
end
def synchronize(seconds=nil)

View file

@ -159,6 +159,13 @@ Capybara::SpecHelper.spec "node" do
expect(@session.find('//select[@id="form_disabled_select"]/option')).to be_disabled
expect(@session.find('//select[@id="form_title"]/option[1]')).not_to be_disabled
end
it "should be boolean" do
@session.visit('/form')
expect(@session.find('//select[@id="form_disabled_select"]/option').disabled?).to be true
expect(@session.find('//select[@id="form_disabled_select2"]/option').disabled?).to be true
expect(@session.find('//select[@id="form_title"]/option[1]').disabled?).to be false
end
end
describe "#visible?" do
@ -171,6 +178,12 @@ Capybara::SpecHelper.spec "node" do
expect(@session.find('//div[@id="hidden_attr"]')).not_to be_visible
expect(@session.find('//a[@id="hidden_attr_via_ancestor"]')).not_to be_visible
end
it "should be boolean" do
Capybara.ignore_hidden_elements = false
expect(@session.first('//a').visible?).to be true
expect(@session.find('//div[@id="hidden"]').visible?).to be false
end
end
describe "#checked?" do
@ -180,6 +193,13 @@ Capybara::SpecHelper.spec "node" do
expect(@session.find('//input[@id="gender_male"]')).not_to be_checked
expect(@session.first('//h1')).not_to be_checked
end
it "should be boolean" do
@session.visit('/form')
expect(@session.find('//input[@id="gender_female"]').checked?).to be true
expect(@session.find('//input[@id="gender_male"]').checked?).to be false
expect(@session.find('//input[@id="no_attr_value_checked"]').checked?).to be true
end
end
describe "#selected?" do
@ -189,6 +209,13 @@ Capybara::SpecHelper.spec "node" do
expect(@session.find('//option[@value="sv"]')).not_to be_selected
expect(@session.first('//h1')).not_to be_selected
end
it "should be boolean" do
@session.visit('/form')
expect(@session.find('//option[@value="en"]').selected?).to be true
expect(@session.find('//option[@value="sv"]').selected?).to be false
expect(@session.first('//h1').selected?).to be false
end
end
describe "#==" do

View file

@ -153,6 +153,10 @@ New line after and before textarea tag
<label for="gender_both">Both</label>
</p>
<p>
<input type="checkbox" id="no_attr_value_checked" value="1" checked/>
</p>
<p>
<input type="checkbox" value="dog" name="form[pets][]" id="form_pets_dog" checked="checked"/>
<label for="form_pets_dog">Dog</label>
@ -292,6 +296,16 @@ New line after and before textarea tag
</label>
</p>
<p>
<label for="form_disabled_select2">
Disabled Select 2
<select name="form[disabled_select2]" id="form_disabled_select2" disabled>
<option value="Should not see me" selected="selected">Should not see me</option>
</select>
</label>
</p>
<p>
<label for="form_disabled_file">
Disabled File