mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge pull request #652 from grzuy/650_support_type_filter
Support :type option for #has_field? matcher
This commit is contained in:
commit
bb7f4b1d68
3 changed files with 35 additions and 0 deletions
|
@ -253,8 +253,13 @@ module Capybara
|
|||
#
|
||||
# page.has_field?('Name', :with => 'Jonas')
|
||||
#
|
||||
# It is also possible to filter by the field type attribute:
|
||||
#
|
||||
# page.has_field?('Email', :type => 'email')
|
||||
#
|
||||
# @param [String] locator The label, name or id of a field to check for
|
||||
# @option options [String] :with The text content of the field
|
||||
# @option options [String] :type The type attribute of the field
|
||||
# @return [Boolean] Whether it exists
|
||||
#
|
||||
def has_field?(locator, options={})
|
||||
|
@ -268,6 +273,7 @@ module Capybara
|
|||
#
|
||||
# @param [String] locator The label, name or id of a field to check for
|
||||
# @option options [String] :with The text content of the field
|
||||
# @option options [String] :type The type attribute of the field
|
||||
# @return [Boolean] Whether it doesn't exist
|
||||
#
|
||||
def has_no_field?(locator, options={})
|
||||
|
|
|
@ -80,6 +80,7 @@ Capybara.add_selector(:field) do
|
|||
filter(:checked) { |node, value| not(value ^ node.checked?) }
|
||||
filter(:unchecked) { |node, value| (value ^ node.checked?) }
|
||||
filter(:with) { |node, with| node.value == with }
|
||||
filter(:type) { |node, type| node[:type] == type }
|
||||
end
|
||||
|
||||
Capybara.add_selector(:fieldset) do
|
||||
|
|
|
@ -36,6 +36,20 @@ shared_examples_for "has_field" do
|
|||
@session.should_not have_field('First Name', :with => 'John')
|
||||
end
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
it "should be false if the given field is not on the page" do
|
||||
@session.should_not have_field('First Name', :type => 'email')
|
||||
@session.should_not have_field('Html5 Email', :type => 'tel')
|
||||
@session.should_not have_field('Description', :type => '')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#has_no_field' do
|
||||
|
@ -75,6 +89,20 @@ shared_examples_for "has_field" do
|
|||
@session.should have_no_field('First Name', :with => 'John')
|
||||
end
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
it "should be true if the given field is not on the page" do
|
||||
@session.should have_no_field('First Name', :type => 'email')
|
||||
@session.should have_no_field('Html5 Email', :type => 'tel')
|
||||
@session.should have_no_field('Description', :type => '')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#has_checked_field?' do
|
||||
|
|
Loading…
Reference in a new issue