mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge pull request #994 from yannp/have_field-textarea_select
'textarea' and 'select' as a :type in Rspec matcher have_field()
This commit is contained in:
commit
8971237512
3 changed files with 19 additions and 3 deletions
|
@ -300,6 +300,8 @@ module Capybara
|
|||
#
|
||||
# page.has_field?('Email', :type => 'email')
|
||||
#
|
||||
# Note: 'textarea' and 'select' are valid type values, matching the associated tag names.
|
||||
#
|
||||
# @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
|
||||
|
|
|
@ -84,7 +84,13 @@ 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 }
|
||||
filter(:type) do |node, type|
|
||||
if ['textarea', 'select'].include?(type)
|
||||
node.tag_name == type
|
||||
else
|
||||
node[:type] == type
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Capybara.add_selector(:fieldset) do
|
||||
|
|
|
@ -42,12 +42,16 @@ Capybara::SpecHelper.spec '#has_field' 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')
|
||||
@session.should have_field('Description', :type => 'textarea')
|
||||
@session.should have_field('Languages', :type => 'select')
|
||||
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('First Name', :type => 'textarea')
|
||||
@session.should_not have_field('Html5 Email', :type => 'tel')
|
||||
@session.should_not have_field('Description', :type => '')
|
||||
@session.should_not have_field('Description', :type => 'email')
|
||||
@session.should_not have_field('Languages', :type => 'textarea')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -95,12 +99,16 @@ Capybara::SpecHelper.spec '#has_no_field' 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')
|
||||
@session.should_not have_no_field('Description', :type => 'textarea')
|
||||
@session.should_not have_no_field('Languages', :type => 'select')
|
||||
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('First Name', :type => 'textarea')
|
||||
@session.should have_no_field('Html5 Email', :type => 'tel')
|
||||
@session.should have_no_field('Description', :type => '')
|
||||
@session.should have_no_field('Description', :type => 'email')
|
||||
@session.should have_no_field('Languages', :type => 'textarea')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue