Add multiple filter to relevant selectors

This commit is contained in:
Thomas Walpole 2016-02-03 11:02:19 -08:00
parent d5ce08812a
commit f375089b7f
5 changed files with 74 additions and 17 deletions

View File

@ -5,6 +5,9 @@ Release date: unreleased
* Element#visible?/checked?/disabled?/selected? Now return boolean
as expected when using the rack_test driver [Thomas Walpole]
### Added
* multiple filter added to relevant selectors [Thomas Walpole]
#Version 2.6.2
Relase date: 2016-01-27
@ -21,44 +24,44 @@ Release date: 2016-01-27
Relase date: 2016-01-17
### Fixed
* Fixed path escaping issue with current_path matchers [Tom Walpole, Luke Rollans] (Issue #1611)
* Fixed path escaping issue with current_path matchers [Thomas Walpole, Luke Rollans] (Issue #1611)
* Fixed circular require [David Rodríguez]
* Capybara::RackTest::Form no longer overrides Object#method [David Rodriguez]
* options and with_options filter for :select selector have more intuitive visibility behavior [Nathan]
* Test for nested modal API method support [Tom Walpole]
* Test for nested modal API method support [Thomas Walpole]
### Added
* Capybara.modify_selector [Tom Walpole]
* Capybara.modify_selector [Thomas Walpole]
* xfeature and ffeature aliases added when using RSpec [Filip Bartuzi]
* Selenium driver supports a :clear option to #set to handle different strategies for clearing a field [Tom Walpole]
* Support the use of rack 2.0 with the rack_test driver [Travis Grathwell, Tom Walpole]
* Disabled option for default selectors now supports true, false, or :all [Jillian Rosile, Tom Walpole]
* Modal API methods now default wait time to Capybara.default_max_wait_time [Tom Walpole]
* Selenium driver supports a :clear option to #set to handle different strategies for clearing a field [Thomas Walpole]
* Support the use of rack 2.0 with the rack_test driver [Travis Grathwell, Thomas Walpole]
* Disabled option for default selectors now supports true, false, or :all [Jillian Rosile, Thomas Walpole]
* Modal API methods now default wait time to Capybara.default_max_wait_time [Thomas Walpole]
# Version 2.5.0
Release date: 2015-08-25
### Fixed
* Error message now raised correctly when invalid options passed to 'have_text'/'have_content' [Tom Walpole]
* Rack-test driver correctly gets document title when elements on the page have nested title elements (SVG) [Tom Walpole]
* Error message now raised correctly when invalid options passed to 'have_text'/'have_content' [Thomas Walpole]
* Rack-test driver correctly gets document title when elements on the page have nested title elements (SVG) [Thomas Walpole]
* 'save_page' no longer errors when using Capybara.asset_host if the page has no \<head> element [Travis Grathwell]
* rack-test driver will ignore clicks on links with href starting with '#' or 'javascript:'
### Added
* has_current_path? and associated asserts/matchers added [Tom Walpole]
* has_current_path? and associated asserts/matchers added [Thomas Walpole]
* Implement Node#path in selenium driver [Soutaro Matsumoto]
* 'using_session' is now nestable [Tom Walpole]
* 'switch_to_window' will now use waiting behavior for a matching window to appear [Tom Walpole]
* 'using_session' is now nestable [Thomas Walpole]
* 'switch_to_window' will now use waiting behavior for a matching window to appear [Thomas Walpole]
* Warning when attempting to select a disabled option
* Capybara matchers are now available in RSpec view specs by default [Joshua Clayton]
* 'have_link' and 'click_link' now accept Regexp for href matching [Yaniv Savir]
* 'find_all' as an alias of 'all' due to collision with RSpec
* Capybara.wait_on_first_by_default setting (default is false)
If set to true 'first' will use Capybaras waiting behavior to wait for at least one element to appear by default
* Capybara waiting behavior uses the monotonic clock if supported to ease restrictions on freezing time in tests [Dmitry Maksyoma, Tom Walpole]
* Capybara.server_errors setting that allows to configure what type of errors will be raised from the server thread [Tom Walpole]
* Node#send_keys to allow for sending keypresses directly to elements [Tom Walpole]
* Capybara waiting behavior uses the monotonic clock if supported to ease restrictions on freezing time in tests [Dmitry Maksyoma, Thomas Walpole]
* Capybara.server_errors setting that allows to configure what type of errors will be raised from the server thread [Thomas Walpole]
* Node#send_keys to allow for sending keypresses directly to elements [Thomas Walpole]
* 'formmethod' attribute support in RackTest driver [Emilia Andrzejewska]
* Clear field using backspaces in Selenium driver by using `:fill_options => { :clear => :backspace }` [Joe Lencioni]

View File

@ -147,6 +147,7 @@ Capybara.add_selector(:field) do
node[:type] == type
end
end
filter(:multiple, boolean: true) { |node, value| !(value ^ node[:multiple]) }
describe do |options|
desc, states = "", []
desc << " of type #{options[:type].inspect}" if options[:type]
@ -155,6 +156,8 @@ Capybara.add_selector(:field) do
states << 'not checked' if options[:unchecked] || (options.has_key?(:checked) && !options[:checked])
states << 'disabled' if options[:disabled] == true
desc << " that is #{states.join(' and ')}" unless states.empty?
desc << " with the multiple attribute" if options[:multiple] == true
desc << " without the multiple attribute" if options[:multiple] === false
desc
end
end
@ -192,7 +195,14 @@ Capybara.add_selector(:fillable_field) do
label "field"
xpath { |locator| XPath::HTML.fillable_field(locator) }
filter(:disabled, default: false, boolean: true, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
describe { |options| " that is disabled" if options[:disabled] == true }
filter(:multiple, boolean: true) { |node, value| !(value ^ node[:multiple]) }
describe do |options|
desc = ""
desc << " that is disabled" if options[:disabled] == true
desc << " with the multiple attribute" if options[:multiple] == true
desc << " without the multiple attribute" if options[:multiple] === false
desc
end
end
Capybara.add_selector(:radio_button) do
@ -253,12 +263,15 @@ Capybara.add_selector(:select) do
[selected].flatten.sort == actual.sort
end
filter(:disabled, default: false, boolean: true, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
filter(:multiple, boolean: true) { |node, value| !(value ^ node[:multiple]) }
describe do |options|
desc = ""
desc << " with options #{options[:options].inspect}" if options[:options]
desc << " with at least options #{options[:with_options].inspect}" if options[:with_options]
desc << " with #{options[:selected].inspect} selected" if options[:selected]
desc << " that is disabled" if options[:disabled] == true
desc << " that allows multiple selection" if options[:multiple] == true
desc << " that only allows single selection" if options[:multiple] === false
desc
end
end
@ -271,7 +284,14 @@ Capybara.add_selector(:file_field) do
label "file field"
xpath { |locator| XPath::HTML.file_field(locator) }
filter(:disabled, default: false, boolean: true, skip_if: :all) { |node, value| not(value ^ node.disabled?) }
describe { |options| " that is disabled" if options[:disabled] == true}
filter(:multiple, boolean: true) { |node, value| !(value ^ node[:multiple]) }
describe do |options|
desc = ""
desc << " that is disabled" if options[:disabled] == true
desc << " that allows multiple files" if options[:multiple] == true
desc << " that only allows a single file" if options[:multiple] === false
desc
end
end
Capybara.add_selector(:table) do

View File

@ -41,6 +41,7 @@ Capybara::SpecHelper.spec '#has_field' do
it "should be true if a field with the given type is on the page" do
expect(@session).to have_field('First Name', :type => 'text')
expect(@session).to have_field('Html5 Email', :type => 'email')
expect(@session).to have_field('Html5 Multiple Email', :type => 'email')
expect(@session).to have_field('Html5 Tel', :type => 'tel')
expect(@session).to have_field('Description', :type => 'textarea')
expect(@session).to have_field('Languages', :type => 'select')
@ -49,11 +50,22 @@ Capybara::SpecHelper.spec '#has_field' do
it "should be false if the given field is not on the page" do
expect(@session).not_to have_field('First Name', :type => 'textarea')
expect(@session).not_to have_field('Html5 Email', :type => 'tel')
expect(@session).not_to have_field('Html5 Multiple Email', :type => 'tel')
expect(@session).not_to have_field('Description', :type => '')
expect(@session).not_to have_field('Description', :type => 'email')
expect(@session).not_to have_field('Languages', :type => 'textarea')
end
end
context 'with multiple' do
it "should be true if a field with the multiple attribute is on the page" do
expect(@session).to have_field('Html5 Multiple Email', multiple: true)
end
it "should be false if a field without the multiple attribute is not on the page" do
expect(@session).not_to have_field('Html5 Multiple Email', multiple: false)
end
end
end
Capybara::SpecHelper.spec '#has_no_field' do

View File

@ -102,6 +102,24 @@ Capybara::SpecHelper.spec '#has_select?' do
expect(@session).to have_select("Icecream", :visible => false, :with_options => ['Vanilla', 'Strawberry'])
end
end
context 'with multiple option' do
it "should find multiple selects if true" do
expect(@session).to have_select('form_languages', multiple: true)
expect(@session).not_to have_select('form_other_title', multiple: true)
end
it "should not find multiple selects if false" do
expect(@session).not_to have_select('form_languages', multiple: false)
expect(@session).to have_select('form_other_title', multiple: false)
end
it "should find both if not specified" do
expect(@session).to have_select('form_languages')
expect(@session).to have_select('form_other_title')
end
end
end
Capybara::SpecHelper.spec '#has_no_select?' do

View File

@ -437,6 +437,10 @@ New line after and before textarea tag
<label for="html5_email">Html5 Email</label>
<input type="email" name="form[html5_email]" value="person@email.com" id="html5_email"/>
</p>
<p>
<label for="html5_multiple_email">Html5 Multiple Email</label>
<input type="email" multiple name="form[html5_multiple_email]" value="person@email.com" id="html5_multiple_email"/>
</p>
<p>
<label for="html5_url">Html5 Url</label>
<input type="url" name="form[html5_url]" value="http://www.example.com" id="html5_url"/>