2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#has_field' do
|
|
|
|
before { @session.visit('/form') }
|
|
|
|
|
|
|
|
it "should be true if the field is on the page" do
|
|
|
|
@session.should have_field('Dog')
|
|
|
|
@session.should have_field('form_description')
|
|
|
|
@session.should have_field('Region')
|
2012-09-06 03:33:43 -04:00
|
|
|
@session.should have_field(:'Region')
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should be false if the field is not on the page" do
|
|
|
|
@session.should_not have_field('Monkey')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with value' do
|
|
|
|
it "should be true if a field with the given value is on the page" do
|
|
|
|
@session.should have_field('First Name', :with => 'John')
|
|
|
|
@session.should have_field('Phone', :with => '+1 555 7021')
|
|
|
|
@session.should have_field('Street', :with => 'Sesame street 66')
|
|
|
|
@session.should have_field('Description', :with => 'Descriptive text goes here')
|
2010-01-18 15:28:06 -05:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false if the given field is not on the page" do
|
|
|
|
@session.should_not have_field('First Name', :with => 'Peter')
|
|
|
|
@session.should_not have_field('Wrong Name', :with => 'John')
|
|
|
|
@session.should_not have_field('Description', :with => 'Monkey')
|
2010-01-18 15:28:06 -05:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true after the field has been filled in with the given value" do
|
|
|
|
@session.fill_in('First Name', :with => 'Jonas')
|
|
|
|
@session.should have_field('First Name', :with => 'Jonas')
|
2010-01-18 15:28:06 -05:00
|
|
|
end
|
2012-02-29 21:57:05 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false after the field has been filled in with a different value" do
|
|
|
|
@session.fill_in('First Name', :with => 'Jonas')
|
|
|
|
@session.should_not have_field('First Name', :with => 'John')
|
2012-02-29 21:57:05 -05:00
|
|
|
end
|
2010-01-18 15:28:06 -05:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context 'with type' do
|
|
|
|
it "should be true if a field with the given type is on the page" do
|
|
|
|
@session.should have_field('First Name', :type => 'text')
|
|
|
|
@session.should have_field('Html5 Email', :type => 'email')
|
|
|
|
@session.should have_field('Html5 Tel', :type => 'tel')
|
2013-03-07 12:59:16 -05:00
|
|
|
@session.should have_field('Description', :type => 'textarea')
|
|
|
|
@session.should have_field('Languages', :type => 'select')
|
2010-01-18 15:28:06 -05:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false if the given field is not on the page" do
|
2013-03-07 12:59:16 -05:00
|
|
|
@session.should_not have_field('First Name', :type => 'textarea')
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.should_not have_field('Html5 Email', :type => 'tel')
|
|
|
|
@session.should_not have_field('Description', :type => '')
|
2013-03-07 12:59:16 -05:00
|
|
|
@session.should_not have_field('Description', :type => 'email')
|
|
|
|
@session.should_not have_field('Languages', :type => 'textarea')
|
2010-01-18 15:28:06 -05:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2010-01-18 15:28:06 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#has_no_field' do
|
|
|
|
before { @session.visit('/form') }
|
2012-02-29 21:57:05 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false if the field is on the page" do
|
|
|
|
@session.should_not have_no_field('Dog')
|
|
|
|
@session.should_not have_no_field('form_description')
|
|
|
|
@session.should_not have_no_field('Region')
|
2010-01-18 15:28:06 -05:00
|
|
|
end
|
2010-01-18 16:31:22 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true if the field is not on the page" do
|
|
|
|
@session.should have_no_field('Monkey')
|
|
|
|
end
|
2010-02-20 16:04:06 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context 'with value' do
|
|
|
|
it "should be false if a field with the given value is on the page" do
|
|
|
|
@session.should_not have_no_field('First Name', :with => 'John')
|
|
|
|
@session.should_not have_no_field('Phone', :with => '+1 555 7021')
|
|
|
|
@session.should_not have_no_field('Street', :with => 'Sesame street 66')
|
|
|
|
@session.should_not have_no_field('Description', :with => 'Descriptive text goes here')
|
2010-01-18 16:31:22 -05:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true if the given field is not on the page" do
|
|
|
|
@session.should have_no_field('First Name', :with => 'Peter')
|
|
|
|
@session.should have_no_field('Wrong Name', :with => 'John')
|
|
|
|
@session.should have_no_field('Description', :with => 'Monkey')
|
2010-01-18 16:31:22 -05:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false after the field has been filled in with the given value" do
|
|
|
|
@session.fill_in('First Name', :with => 'Jonas')
|
|
|
|
@session.should_not have_no_field('First Name', :with => 'Jonas')
|
2010-01-18 16:31:22 -05:00
|
|
|
end
|
2010-12-23 13:38:44 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true after the field has been filled in with a different value" do
|
|
|
|
@session.fill_in('First Name', :with => 'Jonas')
|
|
|
|
@session.should have_no_field('First Name', :with => 'John')
|
2010-12-23 13:38:44 -05:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-12-23 13:38:44 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
context 'with type' do
|
|
|
|
it "should be false if a field with the given type is on the page" do
|
|
|
|
@session.should_not have_no_field('First Name', :type => 'text')
|
|
|
|
@session.should_not have_no_field('Html5 Email', :type => 'email')
|
|
|
|
@session.should_not have_no_field('Html5 Tel', :type => 'tel')
|
2013-03-07 12:59:16 -05:00
|
|
|
@session.should_not have_no_field('Description', :type => 'textarea')
|
|
|
|
@session.should_not have_no_field('Languages', :type => 'select')
|
2010-12-23 13:38:44 -05:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true if the given field is not on the page" do
|
2013-03-07 12:59:16 -05:00
|
|
|
@session.should have_no_field('First Name', :type => 'textarea')
|
2012-07-21 16:44:10 -04:00
|
|
|
@session.should have_no_field('Html5 Email', :type => 'tel')
|
|
|
|
@session.should have_no_field('Description', :type => '')
|
2013-03-07 12:59:16 -05:00
|
|
|
@session.should have_no_field('Description', :type => 'email')
|
|
|
|
@session.should have_no_field('Languages', :type => 'textarea')
|
2010-12-23 13:38:44 -05:00
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
|
|
|
end
|
2010-12-23 13:38:44 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#has_checked_field?' do
|
|
|
|
before { @session.visit('/form') }
|
|
|
|
|
|
|
|
it "should be true if a checked field is on the page" do
|
|
|
|
@session.should have_checked_field('gender_female')
|
|
|
|
@session.should have_checked_field('Hamster')
|
2010-01-18 16:31:22 -05:00
|
|
|
end
|
|
|
|
|
2013-08-08 21:36:33 -04:00
|
|
|
it "should be true for disabled checkboxes if :disabled => true" do
|
|
|
|
@session.should have_checked_field('Disabled Checkbox', :disabled => true)
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false if an unchecked field is on the page" do
|
|
|
|
@session.should_not have_checked_field('form_pets_cat')
|
|
|
|
@session.should_not have_checked_field('Male')
|
|
|
|
end
|
2011-03-25 06:35:59 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false if no field is on the page" do
|
|
|
|
@session.should_not have_checked_field('Does Not Exist')
|
|
|
|
end
|
2011-03-25 06:35:59 -04:00
|
|
|
|
2013-08-08 21:36:33 -04:00
|
|
|
it "should be false for disabled checkboxes by default" do
|
|
|
|
@session.should_not have_checked_field('Disabled Checkbox')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be false for disabled checkboxes if :disabled => false" do
|
|
|
|
@session.should_not have_checked_field('Disabled Checkbox', :disabled => false)
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true after an unchecked checkbox is checked" do
|
|
|
|
@session.check('form_pets_cat')
|
|
|
|
@session.should have_checked_field('form_pets_cat')
|
|
|
|
end
|
2011-03-25 06:35:59 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false after a checked checkbox is unchecked" do
|
|
|
|
@session.uncheck('form_pets_dog')
|
|
|
|
@session.should_not have_checked_field('form_pets_dog')
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true after an unchecked radio button is chosen" do
|
|
|
|
@session.choose('gender_male')
|
|
|
|
@session.should have_checked_field('gender_male')
|
|
|
|
end
|
2010-02-20 16:04:06 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false after another radio button in the group is chosen" do
|
|
|
|
@session.choose('gender_male')
|
|
|
|
@session.should_not have_checked_field('gender_female')
|
|
|
|
end
|
|
|
|
end
|
2010-01-18 16:31:22 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#has_no_checked_field?' do
|
|
|
|
before { @session.visit('/form') }
|
2010-01-18 16:31:22 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false if a checked field is on the page" do
|
|
|
|
@session.should_not have_no_checked_field('gender_female')
|
|
|
|
@session.should_not have_no_checked_field('Hamster')
|
|
|
|
end
|
2010-12-23 13:38:44 -05:00
|
|
|
|
2013-08-08 21:36:33 -04:00
|
|
|
it "should be false for disabled checkboxes if :disabled => true" do
|
|
|
|
@session.should_not have_no_checked_field('Disabled Checkbox', :disabled => true)
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true if an unchecked field is on the page" do
|
|
|
|
@session.should have_no_checked_field('form_pets_cat')
|
|
|
|
@session.should have_no_checked_field('Male')
|
|
|
|
end
|
2010-12-23 13:38:44 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true if no field is on the page" do
|
|
|
|
@session.should have_no_checked_field('Does Not Exist')
|
|
|
|
end
|
2013-08-08 21:36:33 -04:00
|
|
|
|
|
|
|
it "should be true for disabled checkboxes by default" do
|
|
|
|
@session.should have_no_checked_field('Disabled Checkbox')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be true for disabled checkboxes if :disabled => false" do
|
|
|
|
@session.should have_no_checked_field('Disabled Checkbox', :disabled => false)
|
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|
2010-12-23 13:38:44 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#has_unchecked_field?' do
|
|
|
|
before { @session.visit('/form') }
|
2010-12-23 13:38:44 -05:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false if a checked field is on the page" do
|
|
|
|
@session.should_not have_unchecked_field('gender_female')
|
|
|
|
@session.should_not have_unchecked_field('Hamster')
|
2010-01-18 16:31:22 -05:00
|
|
|
end
|
2011-03-25 06:35:59 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true if an unchecked field is on the page" do
|
|
|
|
@session.should have_unchecked_field('form_pets_cat')
|
|
|
|
@session.should have_unchecked_field('Male')
|
|
|
|
end
|
2011-03-25 06:35:59 -04:00
|
|
|
|
2013-08-08 21:36:33 -04:00
|
|
|
it "should be true for disabled unchecked fields if :disabled => true" do
|
|
|
|
@session.should have_unchecked_field('Disabled Unchecked Checkbox', :disabled => true)
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false if no field is on the page" do
|
|
|
|
@session.should_not have_unchecked_field('Does Not Exist')
|
|
|
|
end
|
2011-03-25 06:35:59 -04:00
|
|
|
|
2013-08-08 21:36:33 -04:00
|
|
|
it "should be false for disabled unchecked fields by default" do
|
|
|
|
@session.should_not have_unchecked_field('Disabled Unchecked Checkbox')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be false for disabled unchecked fields if :disabled => false" do
|
|
|
|
@session.should_not have_unchecked_field('Disabled Unchecked Checkbox', :disabled => false)
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be false after an unchecked checkbox is checked" do
|
|
|
|
@session.check('form_pets_cat')
|
|
|
|
@session.should_not have_unchecked_field('form_pets_cat')
|
|
|
|
end
|
2011-03-25 06:35:59 -04:00
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true after a checked checkbox is unchecked" do
|
|
|
|
@session.uncheck('form_pets_dog')
|
|
|
|
@session.should have_unchecked_field('form_pets_dog')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be false after an unchecked radio button is chosen" do
|
|
|
|
@session.choose('gender_male')
|
|
|
|
@session.should_not have_unchecked_field('gender_male')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be true after another radio button in the group is chosen" do
|
|
|
|
@session.choose('gender_male')
|
|
|
|
@session.should have_unchecked_field('gender_female')
|
2011-03-25 06:35:59 -04:00
|
|
|
end
|
2010-01-18 15:28:06 -05:00
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
Capybara::SpecHelper.spec '#has_no_unchecked_field?' do
|
|
|
|
before { @session.visit('/form') }
|
|
|
|
|
|
|
|
it "should be true if a checked field is on the page" do
|
|
|
|
@session.should have_no_unchecked_field('gender_female')
|
|
|
|
@session.should have_no_unchecked_field('Hamster')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be false if an unchecked field is on the page" do
|
|
|
|
@session.should_not have_no_unchecked_field('form_pets_cat')
|
|
|
|
@session.should_not have_no_unchecked_field('Male')
|
|
|
|
end
|
|
|
|
|
2013-08-08 21:36:33 -04:00
|
|
|
it "should be false for disabled unchecked fields if :disabled => true" do
|
|
|
|
@session.should_not have_no_unchecked_field('Disabled Unchecked Checkbox', :disabled => true)
|
|
|
|
end
|
|
|
|
|
2012-07-21 16:44:10 -04:00
|
|
|
it "should be true if no field is on the page" do
|
|
|
|
@session.should have_no_unchecked_field('Does Not Exist')
|
|
|
|
end
|
2013-08-08 21:36:33 -04:00
|
|
|
|
|
|
|
it "should be true for disabled unchecked fields by default" do
|
|
|
|
@session.should have_no_unchecked_field('Disabled Unchecked Checkbox')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be true for disabled unchecked fields if :disabled => false" do
|
|
|
|
@session.should have_no_unchecked_field('Disabled Unchecked Checkbox', :disabled => false)
|
|
|
|
end
|
2012-07-21 16:44:10 -04:00
|
|
|
end
|