generally prefer ruby 1.9 hash format
This commit is contained in:
parent
06a8aa7c05
commit
c5d7089e0e
54
README.md
54
README.md
|
@ -107,8 +107,8 @@ You can use the Capybara DSL in your steps, like so:
|
|||
```ruby
|
||||
When /I sign in/ do
|
||||
within("#session") do
|
||||
fill_in 'Email', :with => 'user@example.com'
|
||||
fill_in 'Password', :with => 'password'
|
||||
fill_in 'Email', with: 'user@example.com'
|
||||
fill_in 'Password', with: 'password'
|
||||
end
|
||||
click_button 'Sign in'
|
||||
end
|
||||
|
@ -150,14 +150,14 @@ You can now write your specs like so:
|
|||
```ruby
|
||||
describe "the signin process", :type => :feature do
|
||||
before :each do
|
||||
User.make(:email => 'user@example.com', :password => 'password')
|
||||
User.make(email: 'user@example.com', password: 'password')
|
||||
end
|
||||
|
||||
it "signs me in" do
|
||||
visit '/sessions/new'
|
||||
within("#session") do
|
||||
fill_in 'Email', :with => 'user@example.com'
|
||||
fill_in 'Password', :with => 'password'
|
||||
fill_in 'Email', with: 'user@example.com'
|
||||
fill_in 'Password', with: 'password'
|
||||
end
|
||||
click_button 'Sign in'
|
||||
expect(page).to have_content 'Success'
|
||||
|
@ -165,12 +165,12 @@ describe "the signin process", :type => :feature do
|
|||
end
|
||||
```
|
||||
|
||||
Use `:js => true` to switch to the `Capybara.javascript_driver`
|
||||
Use `js: true` to switch to the `Capybara.javascript_driver`
|
||||
(`:selenium` by default), or provide a `:driver` option to switch
|
||||
to one specific driver. For example:
|
||||
|
||||
```ruby
|
||||
describe 'some stuff which requires js', :js => true do
|
||||
describe 'some stuff which requires js', js: true do
|
||||
it 'will use the default js driver'
|
||||
it 'will switch to one specific driver', :driver => :webkit
|
||||
end
|
||||
|
@ -181,26 +181,26 @@ Capybara also comes with a built in DSL for creating descriptive acceptance test
|
|||
```ruby
|
||||
feature "Signing in" do
|
||||
background do
|
||||
User.make(:email => 'user@example.com', :password => 'caplin')
|
||||
User.make(email: 'user@example.com', password: 'caplin')
|
||||
end
|
||||
|
||||
scenario "Signing in with correct credentials" do
|
||||
visit '/sessions/new'
|
||||
within("#session") do
|
||||
fill_in 'Email', :with => 'user@example.com'
|
||||
fill_in 'Password', :with => 'caplin'
|
||||
fill_in 'Email', with: 'user@example.com'
|
||||
fill_in 'Password', with: 'caplin'
|
||||
end
|
||||
click_button 'Sign in'
|
||||
expect(page).to have_content 'Success'
|
||||
end
|
||||
|
||||
given(:other_user) { User.make(:email => 'other@example.com', :password => 'rous') }
|
||||
given(:other_user) { User.make(email: 'other@example.com', password: 'rous') }
|
||||
|
||||
scenario "Signing in as another user" do
|
||||
visit '/sessions/new'
|
||||
within("#session") do
|
||||
fill_in 'Email', :with => other_user.email
|
||||
fill_in 'Password', :with => other_user.password
|
||||
fill_in 'Email', with: other_user.email
|
||||
fill_in 'Password', with: other_user.password
|
||||
end
|
||||
click_button 'Sign in'
|
||||
expect(page).to have_content 'Invalid email or password'
|
||||
|
@ -308,7 +308,7 @@ Capybara.default_driver = :selenium
|
|||
|
||||
However, if you are using RSpec or Cucumber, you may instead want to consider
|
||||
leaving the faster `:rack_test` as the __default_driver__, and marking only those
|
||||
tests that require a JavaScript-capable driver using `:js => true` or
|
||||
tests that require a JavaScript-capable driver using `js: true` or
|
||||
`@javascript`, respectively. By default, JavaScript tests are run using the
|
||||
`:selenium` driver. You can change this by setting
|
||||
`Capybara.javascript_driver`.
|
||||
|
@ -344,7 +344,7 @@ RackTest can be configured with a set of headers like this:
|
|||
|
||||
```ruby
|
||||
Capybara.register_driver :rack_test do |app|
|
||||
Capybara::RackTest::Driver.new(app, :headers => { 'HTTP_USER_AGENT' => 'Capybara' })
|
||||
Capybara::RackTest::Driver.new(app, headers: { 'HTTP_USER_AGENT' => 'Capybara' })
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -448,14 +448,14 @@ click_on('Button Value')
|
|||
There are a number of tools for interacting with form elements:
|
||||
|
||||
```ruby
|
||||
fill_in('First Name', :with => 'John')
|
||||
fill_in('Password', :with => 'Seekrit')
|
||||
fill_in('Description', :with => 'Really Long Text...')
|
||||
fill_in('First Name', with: 'John')
|
||||
fill_in('Password', with: 'Seekrit')
|
||||
fill_in('Description', with: 'Really Long Text...')
|
||||
choose('A Radio Button')
|
||||
check('A Checkbox')
|
||||
uncheck('A Checkbox')
|
||||
attach_file('Image', '/path/to/image.jpg')
|
||||
select('Option', :from => 'Select Box')
|
||||
select('Option', from: 'Select Box')
|
||||
```
|
||||
|
||||
### <a name="querying"></a>Querying
|
||||
|
@ -525,11 +525,11 @@ method. Optionally you can specify which kind of selector to use.
|
|||
|
||||
```ruby
|
||||
within("li#employee") do
|
||||
fill_in 'Name', :with => 'Jimmy'
|
||||
fill_in 'Name', with: 'Jimmy'
|
||||
end
|
||||
|
||||
within(:xpath, "//li[@id='employee']") do
|
||||
fill_in 'Name', :with => 'Jimmy'
|
||||
fill_in 'Name', with: 'Jimmy'
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -539,11 +539,11 @@ specific table, identified by either id or text of the table's caption tag.
|
|||
|
||||
```ruby
|
||||
within_fieldset('Employee') do
|
||||
fill_in 'Name', :with => 'Jimmy'
|
||||
fill_in 'Name', with: 'Jimmy'
|
||||
end
|
||||
|
||||
within_table('Employee') do
|
||||
fill_in 'Name', :with => 'Jimmy'
|
||||
fill_in 'Name', with: 'Jimmy'
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -782,8 +782,8 @@ module MyModule
|
|||
|
||||
def login!
|
||||
within(:xpath, "//form[@id='session']") do
|
||||
fill_in 'Email', :with => 'user@example.com'
|
||||
fill_in 'Password', :with => 'password'
|
||||
fill_in 'Email', with: 'user@example.com'
|
||||
fill_in 'Password', with: 'password'
|
||||
end
|
||||
click_button 'Sign in'
|
||||
end
|
||||
|
@ -853,8 +853,8 @@ require 'capybara'
|
|||
|
||||
session = Capybara::Session.new(:webkit, my_rack_app)
|
||||
session.within("form#session") do
|
||||
session.fill_in 'Email', :with => 'user@example.com'
|
||||
session.fill_in 'Password', :with => 'password'
|
||||
session.fill_in 'Email', with: 'user@example.com'
|
||||
session.fill_in 'Password', with: 'password'
|
||||
end
|
||||
session.click_button 'Sign in'
|
||||
```
|
||||
|
|
|
@ -225,7 +225,7 @@ module Capybara
|
|||
# HTML
|
||||
#
|
||||
# node.find('#projects').text # => 'Projects'
|
||||
# node.has_selector?('li#home', :text => 'Home')
|
||||
# node.has_selector?('li#home', text: 'Home')
|
||||
# node.has_selector?('#projects')
|
||||
# node.find('ul').find('li:first-child').text # => 'Home'
|
||||
#
|
||||
|
@ -475,7 +475,7 @@ end
|
|||
|
||||
Capybara.register_server :webrick do |app, port, host|
|
||||
require 'rack/handler/webrick'
|
||||
Rack::Handler::WEBrick.run(app, :Host => host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
||||
Rack::Handler::WEBrick.run(app, Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log::new(nil, 0))
|
||||
end
|
||||
|
||||
Capybara.register_server :puma do |app, port, host|
|
||||
|
|
|
@ -62,7 +62,7 @@ module Capybara
|
|||
# Locate a text field or text area and fill it in with the given text
|
||||
# The field can be found via its name, id or label text.
|
||||
#
|
||||
# page.fill_in 'Name', :with => 'Bob'
|
||||
# page.fill_in 'Name', with: 'Bob'
|
||||
#
|
||||
#
|
||||
# @overload fill_in([locator], options={})
|
||||
|
@ -206,7 +206,7 @@ module Capybara
|
|||
# one option.
|
||||
# The select box can be found via its name, id or label text. The option can be found by its text.
|
||||
#
|
||||
# page.select 'March', :from => 'Month'
|
||||
# page.select 'March', from: 'Month'
|
||||
#
|
||||
# @macro waiting_behavior
|
||||
#
|
||||
|
@ -228,7 +228,7 @@ module Capybara
|
|||
# box is a multiple select, +unselect+ can be called multiple times to unselect more than
|
||||
# one option. The select box can be found via its name, id or label text.
|
||||
#
|
||||
# page.unselect 'March', :from => 'Month'
|
||||
# page.unselect 'March', from: 'Month'
|
||||
#
|
||||
# @macro waiting_behavior
|
||||
#
|
||||
|
|
|
@ -17,9 +17,9 @@ module Capybara
|
|||
#
|
||||
# session = Capybara::Session.new(:rack_test, my_app)
|
||||
# session.visit('/')
|
||||
# session.fill_in('Foo', :with => 'Bar') # from Capybara::Node::Actions
|
||||
# session.fill_in('Foo', with: 'Bar') # from Capybara::Node::Actions
|
||||
# bar = session.find('#bar') # from Capybara::Node::Finders
|
||||
# bar.select('Baz', :from => 'Quox') # from Capybara::Node::Actions
|
||||
# bar.select('Baz', from: 'Quox') # from Capybara::Node::Actions
|
||||
# session.has_css?('#foobar') # from Capybara::Node::Matchers
|
||||
#
|
||||
class Base
|
||||
|
|
|
@ -10,7 +10,7 @@ module Capybara
|
|||
# session = Capybara::Session.new(:rack_test, my_app)
|
||||
#
|
||||
# bar = session.find('#bar') # from Capybara::Node::Finders
|
||||
# bar.select('Baz', :from => 'Quox') # from Capybara::Node::Actions
|
||||
# bar.select('Baz', from: 'Quox') # from Capybara::Node::Actions
|
||||
#
|
||||
# {Capybara::Node::Element} also has access to HTML attributes and other properties of the
|
||||
# element:
|
||||
|
|
|
@ -19,7 +19,7 @@ module Capybara
|
|||
#
|
||||
# page.find('#foo').find('.bar')
|
||||
# page.find(:xpath, '//div[contains(., "bar")]')
|
||||
# page.find('li', :text => 'Quox').click_link('Delete')
|
||||
# page.find('li', text: 'Quox').click_link('Delete')
|
||||
#
|
||||
# @param (see Capybara::Node::Finders#all)
|
||||
#
|
||||
|
@ -169,18 +169,18 @@ module Capybara
|
|||
# The set of found elements can further be restricted by specifying
|
||||
# options. It's possible to select elements by their text or visibility:
|
||||
#
|
||||
# page.all('a', :text => 'Home')
|
||||
# page.all('#menu li', :visible => true)
|
||||
# page.all('a', text: 'Home')
|
||||
# page.all('#menu li', visible: true)
|
||||
#
|
||||
# By default if no elements are found, an empty array is returned;
|
||||
# however, expectations can be set on the number of elements to be found which
|
||||
# will trigger Capybara's waiting behavior for the expectations to match.The
|
||||
# expectations can be set using
|
||||
#
|
||||
# page.assert_selector('p#foo', :count => 4)
|
||||
# page.assert_selector('p#foo', :maximum => 10)
|
||||
# page.assert_selector('p#foo', :minimum => 1)
|
||||
# page.assert_selector('p#foo', :between => 1..10)
|
||||
# page.assert_selector('p#foo', count: 4)
|
||||
# page.assert_selector('p#foo', maximum: 10)
|
||||
# page.assert_selector('p#foo', minimum: 1)
|
||||
# page.assert_selector('p#foo', between: 1..10)
|
||||
#
|
||||
# See {Capybara::Helpers#matches_count?} for additional information about
|
||||
# count matching.
|
||||
|
|
|
@ -14,14 +14,14 @@ module Capybara
|
|||
# By default it will check if the expression occurs at least once,
|
||||
# but a different number can be specified.
|
||||
#
|
||||
# page.has_selector?('p.foo', :count => 4)
|
||||
# page.has_selector?('p.foo', count: 4)
|
||||
#
|
||||
# This will check if the expression occurs exactly 4 times.
|
||||
#
|
||||
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
||||
# such as :text and :visible.
|
||||
#
|
||||
# page.has_selector?('li', :text => 'Horse', :visible => true)
|
||||
# page.has_selector?('li', text: 'Horse', visible: true)
|
||||
#
|
||||
# has_selector? can also accept XPath expressions generated by the
|
||||
# XPath gem:
|
||||
|
@ -67,7 +67,7 @@ module Capybara
|
|||
# By default it will check if the expression occurs at least once,
|
||||
# but a different number can be specified.
|
||||
#
|
||||
# page.assert_selector('p#foo', :count => 4)
|
||||
# page.assert_selector('p#foo', count: 4)
|
||||
#
|
||||
# This will check if the expression occurs exactly 4 times. See
|
||||
# {Capybara::Node::Finders#all} for other available result size options.
|
||||
|
@ -78,7 +78,7 @@ module Capybara
|
|||
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
||||
# such as :text and :visible.
|
||||
#
|
||||
# page.assert_selector('li', :text => 'Horse', :visible => true)
|
||||
# page.assert_selector('li', text: 'Horse', visible: true)
|
||||
#
|
||||
# `assert_selector` can also accept XPath expressions generated by the
|
||||
# XPath gem:
|
||||
|
@ -109,9 +109,9 @@ module Capybara
|
|||
# considered to be an integral part of the selector. This will return
|
||||
# true, for example, if a page contains 4 anchors but the query expects 5:
|
||||
#
|
||||
# page.assert_no_selector('a', :minimum => 1) # Found, raises Capybara::ExpectationNotMet
|
||||
# page.assert_no_selector('a', :count => 4) # Found, raises Capybara::ExpectationNotMet
|
||||
# page.assert_no_selector('a', :count => 5) # Not Found, returns true
|
||||
# page.assert_no_selector('a', minimum: 1) # Found, raises Capybara::ExpectationNotMet
|
||||
# page.assert_no_selector('a', count: 4) # Found, raises Capybara::ExpectationNotMet
|
||||
# page.assert_no_selector('a', count: 5) # Not Found, returns true
|
||||
#
|
||||
# @param (see Capybara::Node::Finders#assert_selector)
|
||||
# @raise [Capybara::ExpectationNotMet] If the selector exists
|
||||
|
@ -137,14 +137,14 @@ module Capybara
|
|||
# By default it will check if the expression occurs at least once,
|
||||
# but a different number can be specified.
|
||||
#
|
||||
# page.has_xpath?('.//p[@id="foo"]', :count => 4)
|
||||
# page.has_xpath?('.//p[@id="foo"]', count: 4)
|
||||
#
|
||||
# This will check if the expression occurs exactly 4 times.
|
||||
#
|
||||
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
||||
# such as :text and :visible.
|
||||
#
|
||||
# page.has_xpath?('.//li', :text => 'Horse', :visible => true)
|
||||
# page.has_xpath?('.//li', text: 'Horse', visible: true)
|
||||
#
|
||||
# has_xpath? can also accept XPath expressions generate by the
|
||||
# XPath gem:
|
||||
|
@ -182,14 +182,14 @@ module Capybara
|
|||
# By default it will check if the selector occurs at least once,
|
||||
# but a different number can be specified.
|
||||
#
|
||||
# page.has_css?('p#foo', :count => 4)
|
||||
# page.has_css?('p#foo', count: 4)
|
||||
#
|
||||
# This will check if the selector occurs exactly 4 times.
|
||||
#
|
||||
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
||||
# such as :text and :visible.
|
||||
#
|
||||
# page.has_css?('li', :text => 'Horse', :visible => true)
|
||||
# page.has_css?('li', text: 'Horse', visible: true)
|
||||
#
|
||||
# @param [String] path A CSS selector
|
||||
# @param options (see Capybara::Node::Finders#all)
|
||||
|
@ -275,11 +275,11 @@ module Capybara
|
|||
# HTML5 email/url/etc. fields, it's possible to specify a :with
|
||||
# option to specify the text the field should contain:
|
||||
#
|
||||
# page.has_field?('Name', :with => 'Jonas')
|
||||
# page.has_field?('Name', with: 'Jonas')
|
||||
#
|
||||
# It is also possible to filter by the field type attribute:
|
||||
#
|
||||
# page.has_field?('Email', :type => 'email')
|
||||
# page.has_field?('Email', type: 'email')
|
||||
#
|
||||
# Note: 'textarea' and 'select' are valid type values, matching the associated tag names.
|
||||
#
|
||||
|
@ -319,7 +319,7 @@ module Capybara
|
|||
#
|
||||
def has_checked_field?(locator=nil, options={}, &optional_filter_block)
|
||||
locator, options = nil, locator if locator.is_a? Hash
|
||||
has_selector?(:field, locator, options.merge(:checked => true), &optional_filter_block)
|
||||
has_selector?(:field, locator, options.merge(checked: true), &optional_filter_block)
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -333,7 +333,7 @@ module Capybara
|
|||
#
|
||||
def has_no_checked_field?(locator=nil, options={}, &optional_filter_block)
|
||||
locator, options = nil, locator if locator.is_a? Hash
|
||||
has_no_selector?(:field, locator, options.merge(:checked => true))
|
||||
has_no_selector?(:field, locator, options.merge(checked: true))
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -347,7 +347,7 @@ module Capybara
|
|||
#
|
||||
def has_unchecked_field?(locator=nil, options={}, &optional_filter_block)
|
||||
locator, options = nil, locator if locator.is_a? Hash
|
||||
has_selector?(:field, locator, options.merge(:unchecked => true), &optional_filter_block)
|
||||
has_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -361,7 +361,7 @@ module Capybara
|
|||
#
|
||||
def has_no_unchecked_field?(locator=nil, options={}, &optional_filter_block)
|
||||
locator, options = nil, locator if locator.is_a? Hash
|
||||
has_no_selector?(:field, locator, options.merge(:unchecked => true), &optional_filter_block)
|
||||
has_no_selector?(:field, locator, options.merge(unchecked: true), &optional_filter_block)
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -371,20 +371,20 @@ module Capybara
|
|||
#
|
||||
# It can be specified which option should currently be selected:
|
||||
#
|
||||
# page.has_select?('Language', :selected => 'German')
|
||||
# page.has_select?('Language', selected: 'German')
|
||||
#
|
||||
# For multiple select boxes, several options may be specified:
|
||||
#
|
||||
# page.has_select?('Language', :selected => ['English', 'German'])
|
||||
# page.has_select?('Language', selected: ['English', 'German'])
|
||||
#
|
||||
# It's also possible to check if the exact set of options exists for
|
||||
# this select box:
|
||||
#
|
||||
# page.has_select?('Language', :options => ['English', 'German', 'Spanish'])
|
||||
# page.has_select?('Language', options: ['English', 'German', 'Spanish'])
|
||||
#
|
||||
# You can also check for a partial set of options:
|
||||
#
|
||||
# page.has_select?('Language', :with_options => ['English', 'German'])
|
||||
# page.has_select?('Language', with_options: ['English', 'German'])
|
||||
#
|
||||
# @param [String] locator The label, name or id of a select box
|
||||
# @option options [Array] :options Options which should be contained in this select box
|
||||
|
@ -449,7 +449,7 @@ module Capybara
|
|||
# It also accepts all options that {Capybara::Node::Finders#all} accepts,
|
||||
# such as :text and :visible.
|
||||
#
|
||||
# node.assert_matches_selector('li', :text => 'Horse', :visible => true)
|
||||
# node.assert_matches_selector('li', text: 'Horse', visible: true)
|
||||
#
|
||||
# @param (see Capybara::Node::Finders#all)
|
||||
# @raise [Capybara::ExpectationNotMet] If the selector does not match
|
||||
|
|
|
@ -7,9 +7,9 @@ require 'cgi'
|
|||
|
||||
class Capybara::RackTest::Driver < Capybara::Driver::Base
|
||||
DEFAULT_OPTIONS = {
|
||||
:respect_data_method => false,
|
||||
:follow_redirects => true,
|
||||
:redirect_limit => 5
|
||||
respect_data_method: false,
|
||||
follow_redirects: true,
|
||||
redirect_limit: 5
|
||||
}
|
||||
attr_reader :app, :options
|
||||
|
||||
|
|
|
@ -16,5 +16,5 @@ Capybara.save_path = Rails.root.join('tmp/capybara')
|
|||
|
||||
# Override default rack_test driver to respect data-method attributes.
|
||||
Capybara.register_driver :rack_test do |app|
|
||||
Capybara::RackTest::Driver.new(app, :respect_data_method => true)
|
||||
Capybara::RackTest::Driver.new(app, respect_data_method: true)
|
||||
end
|
||||
|
|
|
@ -51,6 +51,6 @@ else
|
|||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include(Capybara::Features, :capybara_feature => true)
|
||||
config.include(Capybara::Features, capybara_feature: true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -280,12 +280,12 @@ module Capybara
|
|||
|
||||
def have_checked_field(locator=nil, options={}, &optional_filter_block)
|
||||
locator, options = nil, locator if locator.is_a? Hash
|
||||
HaveSelector.new(:field, locator, options.merge(:checked => true), &optional_filter_block)
|
||||
HaveSelector.new(:field, locator, options.merge(checked: true), &optional_filter_block)
|
||||
end
|
||||
|
||||
def have_unchecked_field(locator=nil, options={}, &optional_filter_block)
|
||||
locator, options = nil, locator if locator.is_a? Hash
|
||||
HaveSelector.new(:field, locator, options.merge(:unchecked => true), &optional_filter_block)
|
||||
HaveSelector.new(:field, locator, options.merge(unchecked: true), &optional_filter_block)
|
||||
end
|
||||
|
||||
def have_select(locator=nil, options={}, &optional_filter_block)
|
||||
|
|
|
@ -20,7 +20,7 @@ module Capybara
|
|||
# +current_path, and so on. It also delegate a number of methods to a Capybara::Document, representing
|
||||
# the current HTML document. This allows interaction:
|
||||
#
|
||||
# session.fill_in('q', :with => 'Capybara')
|
||||
# session.fill_in('q', with: 'Capybara')
|
||||
# session.click_button('Search')
|
||||
# expect(session).to have_content('Capybara')
|
||||
#
|
||||
|
@ -264,7 +264,7 @@ module Capybara
|
|||
# to the given element.
|
||||
#
|
||||
# within(:xpath, '//div[@id="delivery-address"]') do
|
||||
# fill_in('Street', :with => '12 Main Street')
|
||||
# fill_in('Street', with: '12 Main Street')
|
||||
# end
|
||||
#
|
||||
# Just as with `find`, if multiple elements match the selector given to
|
||||
|
@ -275,13 +275,13 @@ module Capybara
|
|||
# assumed to be of the type set in Capybara.default_selector.
|
||||
#
|
||||
# within('div#delivery-address') do
|
||||
# fill_in('Street', :with => '12 Main Street')
|
||||
# fill_in('Street', with: '12 Main Street')
|
||||
# end
|
||||
#
|
||||
# Note that a lot of uses of `within` can be replaced more succinctly with
|
||||
# chaining:
|
||||
#
|
||||
# find('div#delivery-address').fill_in('Street', :with => '12 Main Street')
|
||||
# find('div#delivery-address').fill_in('Street', with: '12 Main Street')
|
||||
#
|
||||
# @overload within(*find_args)
|
||||
# @param (see Capybara::Node::Finders#all)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
|
||||
Capybara::SpecHelper.spec '#accept_alert', requires: [:modals] do
|
||||
before do
|
||||
@session.visit('/with_js')
|
||||
end
|
||||
|
@ -10,14 +10,14 @@ Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
|
|||
end
|
||||
expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
|
||||
end
|
||||
|
||||
|
||||
it "should accept the alert if the text matches" do
|
||||
@session.accept_alert 'Alert opened' do
|
||||
@session.click_link('Open alert')
|
||||
end
|
||||
expect(@session).to have_xpath("//a[@id='open-alert' and @opened='true']")
|
||||
end
|
||||
|
||||
|
||||
it "should not accept the alert if the text doesnt match" do
|
||||
expect do
|
||||
@session.accept_alert 'Incorrect Text' do
|
||||
|
@ -47,7 +47,7 @@ Capybara::SpecHelper.spec '#accept_alert', :requires => [:modals] do
|
|||
end
|
||||
expect(message).to eq('Delayed alert opened')
|
||||
end
|
||||
|
||||
|
||||
it "should allow to adjust the delay" do
|
||||
@session.accept_alert wait: 4 do
|
||||
@session.click_link('Open slow alert')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#accept_confirm', :requires => [:modals] do
|
||||
Capybara::SpecHelper.spec '#accept_confirm', requires: [:modals] do
|
||||
before do
|
||||
@session.visit('/with_js')
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#accept_prompt', :requires => [:modals] do
|
||||
Capybara::SpecHelper.spec '#accept_prompt', requires: [:modals] do
|
||||
before do
|
||||
@session.visit('/with_js')
|
||||
end
|
||||
|
@ -17,21 +17,21 @@ Capybara::SpecHelper.spec '#accept_prompt', :requires => [:modals] do
|
|||
end
|
||||
expect(message).to eq('Prompt opened')
|
||||
end
|
||||
|
||||
|
||||
it "should accept the prompt with a response" do
|
||||
@session.accept_prompt with: 'the response' do
|
||||
@session.click_link('Open prompt')
|
||||
end
|
||||
expect(@session).to have_xpath("//a[@id='open-prompt' and @response='the response']")
|
||||
end
|
||||
|
||||
|
||||
it "should accept the prompt if the message matches" do
|
||||
@session.accept_prompt 'Prompt opened', with: 'matched' do
|
||||
@session.click_link('Open prompt')
|
||||
end
|
||||
expect(@session).to have_xpath("//a[@id='open-prompt' and @response='matched']")
|
||||
end
|
||||
|
||||
|
||||
it "should not accept the prompt if the message doesn't match" do
|
||||
expect do
|
||||
@session.accept_prompt 'Incorrect Text', with: 'not matched' do
|
||||
|
@ -39,7 +39,7 @@ Capybara::SpecHelper.spec '#accept_prompt', :requires => [:modals] do
|
|||
end
|
||||
end.to raise_error(Capybara::ModalNotFound)
|
||||
end
|
||||
|
||||
|
||||
|
||||
it "should return the message presented" do
|
||||
message = @session.accept_prompt with: 'the response' do
|
||||
|
|
|
@ -22,7 +22,7 @@ Capybara::SpecHelper.spec "#all" do
|
|||
end
|
||||
|
||||
it "should raise an error when given invalid options" do
|
||||
expect { @session.all('//p', :schmoo => "foo") }.to raise_error(ArgumentError)
|
||||
expect { @session.all('//p', schmoo: "foo") }.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
context "with css selectors" do
|
||||
|
@ -53,11 +53,11 @@ Capybara::SpecHelper.spec "#all" do
|
|||
|
||||
context "with visible filter" do
|
||||
it "should only find visible nodes when true" do
|
||||
expect(@session.all(:css, "a.simple", :visible => true).size).to eq(1)
|
||||
expect(@session.all(:css, "a.simple", visible: true).size).to eq(1)
|
||||
end
|
||||
|
||||
it "should find nodes regardless of whether they are invisible when false" do
|
||||
expect(@session.all(:css, "a.simple", :visible => false).size).to eq(2)
|
||||
expect(@session.all(:css, "a.simple", visible: false).size).to eq(2)
|
||||
end
|
||||
|
||||
it "should default to Capybara.ignore_hidden_elements" do
|
||||
|
@ -71,68 +71,68 @@ Capybara::SpecHelper.spec "#all" do
|
|||
context 'with element count filters' do
|
||||
context ':count' do
|
||||
it 'should succeed when the number of elements founds matches the expectation' do
|
||||
expect { @session.all(:css, 'h1, p', :count => 4) }.to_not raise_error
|
||||
expect { @session.all(:css, 'h1, p', count: 4) }.to_not raise_error
|
||||
end
|
||||
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
||||
expect { @session.all(:css, 'h1, p', :count => 5) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
expect { @session.all(:css, 'h1, p', count: 5) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
end
|
||||
context ':minimum' do
|
||||
it 'should succeed when the number of elements founds matches the expectation' do
|
||||
expect { @session.all(:css, 'h1, p', :minimum => 0) }.to_not raise_error
|
||||
expect { @session.all(:css, 'h1, p', minimum: 0) }.to_not raise_error
|
||||
end
|
||||
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
||||
expect { @session.all(:css, 'h1, p', :minimum => 5) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
expect { @session.all(:css, 'h1, p', minimum: 5) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
end
|
||||
context ':maximum' do
|
||||
it 'should succeed when the number of elements founds matches the expectation' do
|
||||
expect { @session.all(:css, 'h1, p', :maximum => 4) }.to_not raise_error
|
||||
expect { @session.all(:css, 'h1, p', maximum: 4) }.to_not raise_error
|
||||
end
|
||||
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
||||
expect { @session.all(:css, 'h1, p', :maximum => 0) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
expect { @session.all(:css, 'h1, p', maximum: 0) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
end
|
||||
context ':between' do
|
||||
it 'should succeed when the number of elements founds matches the expectation' do
|
||||
expect { @session.all(:css, 'h1, p', :between => 2..7) }.to_not raise_error
|
||||
expect { @session.all(:css, 'h1, p', between: 2..7) }.to_not raise_error
|
||||
end
|
||||
it 'should raise ExpectationNotMet when the number of elements founds does not match the expectation' do
|
||||
expect { @session.all(:css, 'h1, p', :between => 0..3) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
expect { @session.all(:css, 'h1, p', between: 0..3) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with multiple count filters' do
|
||||
it 'ignores other filters when :count is specified' do
|
||||
o = {:count => 4,
|
||||
:minimum => 5,
|
||||
:maximum => 0,
|
||||
:between => 0..3}
|
||||
o = {count: 4,
|
||||
minimum: 5,
|
||||
maximum: 0,
|
||||
between: 0..3}
|
||||
expect { @session.all(:css, 'h1, p', o) }.to_not raise_error
|
||||
end
|
||||
context 'with no :count expectation' do
|
||||
it 'fails if :minimum is not met' do
|
||||
o = {:minimum => 5,
|
||||
:maximum => 4,
|
||||
:between => 2..7}
|
||||
o = {minimum: 5,
|
||||
maximum: 4,
|
||||
between: 2..7}
|
||||
expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
it 'fails if :maximum is not met' do
|
||||
o = {:minimum => 0,
|
||||
:maximum => 0,
|
||||
:between => 2..7}
|
||||
o = {minimum: 0,
|
||||
maximum: 0,
|
||||
between: 2..7}
|
||||
expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
it 'fails if :between is not met' do
|
||||
o = {:minimum => 0,
|
||||
:maximum => 4,
|
||||
:between => 0..3}
|
||||
o = {minimum: 0,
|
||||
maximum: 4,
|
||||
between: 0..3}
|
||||
expect { @session.all(:css, 'h1, p', o) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
it 'succeeds if all combineable expectations are met' do
|
||||
o = {:minimum => 0,
|
||||
:maximum => 4,
|
||||
:between => 2..7}
|
||||
o = {minimum: 0,
|
||||
maximum: 4,
|
||||
between: 2..7}
|
||||
expect { @session.all(:css, 'h1, p', o) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ Capybara::SpecHelper.spec '#assert_current_path' do
|
|||
expect { @session.assert_current_path(/w[a-z]{3}_js/) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "should wait for current_path", :requires => [:js] do
|
||||
it "should wait for current_path", requires: [:js] do
|
||||
@session.click_link("Change page")
|
||||
expect { @session.assert_current_path("/with_html") }.not_to raise_error
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ Capybara::SpecHelper.spec '#assert_no_current_path?' do
|
|||
expect{@session.assert_no_current_path(/monkey/)}.not_to raise_error
|
||||
end
|
||||
|
||||
it "should wait for current_path to disappear", :requires => [:js] do
|
||||
it "should wait for current_path to disappear", requires: [:js] do
|
||||
@session.click_link("Change page")
|
||||
expect{@session.assert_no_current_path('/with_js')}.not_to raise_error
|
||||
end
|
||||
|
|
|
@ -31,41 +31,41 @@ Capybara::SpecHelper.spec '#assert_selector' do
|
|||
|
||||
context "with count" do
|
||||
it "should be true if the content is on the page the given number of times" do
|
||||
@session.assert_selector("//p", :count => 3)
|
||||
@session.assert_selector("//p//a[@id='foo']", :count => 1)
|
||||
@session.assert_selector("//p[contains(.,'est')]", :count => 1)
|
||||
@session.assert_selector("//p", count: 3)
|
||||
@session.assert_selector("//p//a[@id='foo']", count: 1)
|
||||
@session.assert_selector("//p[contains(.,'est')]", count: 1)
|
||||
end
|
||||
|
||||
it "should be false if the content is on the page the given number of times" do
|
||||
expect { @session.assert_selector("//p", :count => 6) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_selector("//p//a[@id='foo']", :count => 2) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_selector("//p[contains(.,'est')]", :count => 5) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_selector("//p", count: 6) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_selector("//p//a[@id='foo']", count: 2) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_selector("//p[contains(.,'est')]", count: 5) }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "should be false if the content isn't on the page at all" do
|
||||
expect { @session.assert_selector("//abbr", :count => 2) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_selector("//p//a[@id='doesnotexist']", :count => 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_selector("//abbr", count: 2) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_selector("//p//a[@id='doesnotexist']", count: 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is not contained" do
|
||||
@session.assert_selector("//p//a", :text => "Redirect", :count => 1)
|
||||
expect { @session.assert_selector("//p", :text => "Doesnotexist") }.to raise_error(Capybara::ElementNotFound)
|
||||
@session.assert_selector("//p//a", text: "Redirect", count: 1)
|
||||
expect { @session.assert_selector("//p", text: "Doesnotexist") }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "should discard all matches where the given regexp is not matched" do
|
||||
@session.assert_selector("//p//a", :text => /re[dab]i/i, :count => 1)
|
||||
expect { @session.assert_selector("//p//a", :text => /Red$/) }.to raise_error(Capybara::ElementNotFound)
|
||||
@session.assert_selector("//p//a", text: /re[dab]i/i, count: 1)
|
||||
expect { @session.assert_selector("//p//a", text: /Red$/) }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
context "with wait", requires: [:js] do
|
||||
it "should find element if it appears before given wait duration" do
|
||||
Capybara.using_wait_time(0.1) do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
@session.assert_selector(:css, "a#has-been-clicked", :text => "Has been clicked", :wait => 0.9)
|
||||
@session.assert_selector(:css, "a#has-been-clicked", text: "Has been clicked", wait: 0.9)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -109,40 +109,40 @@ Capybara::SpecHelper.spec '#assert_no_selector' do
|
|||
|
||||
context "with count" do
|
||||
it "should be false if the content is on the page the given number of times" do
|
||||
expect { @session.assert_no_selector("//p", :count => 3) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_no_selector("//p//a[@id='foo']", :count => 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_no_selector("//p[contains(.,'est')]", :count => 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_no_selector("//p", count: 3) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_no_selector("//p//a[@id='foo']", count: 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.assert_no_selector("//p[contains(.,'est')]", count: 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "should be true if the content is on the page the wrong number of times" do
|
||||
@session.assert_no_selector("//p", :count => 6)
|
||||
@session.assert_no_selector("//p//a[@id='foo']", :count => 2)
|
||||
@session.assert_no_selector("//p[contains(.,'est')]", :count => 5)
|
||||
@session.assert_no_selector("//p", count: 6)
|
||||
@session.assert_no_selector("//p//a[@id='foo']", count: 2)
|
||||
@session.assert_no_selector("//p[contains(.,'est')]", count: 5)
|
||||
end
|
||||
|
||||
it "should be true if the content isn't on the page at all" do
|
||||
@session.assert_no_selector("//abbr", :count => 2)
|
||||
@session.assert_no_selector("//p//a[@id='doesnotexist']", :count => 1)
|
||||
@session.assert_no_selector("//abbr", count: 2)
|
||||
@session.assert_no_selector("//p//a[@id='doesnotexist']", count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is contained" do
|
||||
expect { @session.assert_no_selector("//p//a", :text => "Redirect", :count => 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
@session.assert_no_selector("//p", :text => "Doesnotexist")
|
||||
expect { @session.assert_no_selector("//p//a", text: "Redirect", count: 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
@session.assert_no_selector("//p", text: "Doesnotexist")
|
||||
end
|
||||
|
||||
it "should discard all matches where the given regexp is matched" do
|
||||
expect { @session.assert_no_selector("//p//a", :text => /re[dab]i/i, :count => 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
@session.assert_no_selector("//p//a", :text => /Red$/)
|
||||
expect { @session.assert_no_selector("//p//a", text: /re[dab]i/i, count: 1) }.to raise_error(Capybara::ElementNotFound)
|
||||
@session.assert_no_selector("//p//a", text: /Red$/)
|
||||
end
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
context "with wait", requires: [:js] do
|
||||
it "should not find element if it appears after given wait duration" do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
@session.assert_no_selector(:css, "a#has-been-clicked", :text => "Has been clicked", :wait => 0.1)
|
||||
@session.assert_no_selector(:css, "a#has-been-clicked", text: "Has been clicked", wait: 0.1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,7 +78,7 @@ Capybara::SpecHelper.spec '#assert_text' do
|
|||
end.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
|
||||
it "should wait for text to appear", :requires => [:js] do
|
||||
it "should wait for text to appear", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session.assert_text('Has been clicked')).to eq(true)
|
||||
|
@ -98,7 +98,7 @@ Capybara::SpecHelper.spec '#assert_text' do
|
|||
end
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
context "with wait", requires: [:js] do
|
||||
it "should find element if it appears before given wait duration" do
|
||||
Capybara.using_wait_time(0) do
|
||||
@session.visit('/with_js')
|
||||
|
@ -125,35 +125,35 @@ Capybara::SpecHelper.spec '#assert_text' do
|
|||
end
|
||||
|
||||
it 'ignores other filters when :count is specified' do
|
||||
o = {:count => 5,
|
||||
:minimum => 6,
|
||||
:maximum => 0,
|
||||
:between => 0..4}
|
||||
o = {count: 5,
|
||||
minimum: 6,
|
||||
maximum: 0,
|
||||
between: 0..4}
|
||||
expect { @session.assert_text('Header', o) }.not_to raise_error
|
||||
end
|
||||
context 'with no :count expectation' do
|
||||
it 'fails if :minimum is not met' do
|
||||
o = {:minimum => 6,
|
||||
:maximum => 5,
|
||||
:between => 2..7}
|
||||
o = {minimum: 6,
|
||||
maximum: 5,
|
||||
between: 2..7}
|
||||
expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
it 'fails if :maximum is not met' do
|
||||
o = {:minimum => 0,
|
||||
:maximum => 0,
|
||||
:between => 2..7}
|
||||
o = {minimum: 0,
|
||||
maximum: 0,
|
||||
between: 2..7}
|
||||
expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
it 'fails if :between is not met' do
|
||||
o = {:minimum => 0,
|
||||
:maximum => 5,
|
||||
:between => 0..4}
|
||||
o = {minimum: 0,
|
||||
maximum: 5,
|
||||
between: 0..4}
|
||||
expect { @session.assert_text('Header', o) }.to raise_error(Capybara::ExpectationNotMet)
|
||||
end
|
||||
it 'succeeds if all combineable expectations are met' do
|
||||
o = {:minimum => 0,
|
||||
:maximum => 5,
|
||||
:between => 2..7}
|
||||
o = {minimum: 0,
|
||||
maximum: 5,
|
||||
between: 2..7}
|
||||
expect { @session.assert_text('Header', o) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
@ -215,12 +215,12 @@ Capybara::SpecHelper.spec '#assert_no_text' do
|
|||
end
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
context "with wait", requires: [:js] do
|
||||
it "should not find element if it appears after given wait duration" do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
@session.find(:css, '#reload-list').click
|
||||
@session.find(:css, '#the-list').assert_no_text('Foo Bar', :wait => 0.3)
|
||||
@session.find(:css, '#the-list').assert_no_text('Foo Bar', wait: 0.3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ Capybara::SpecHelper.spec '#assert_title' do
|
|||
end.to raise_error(Capybara::ExpectationNotMet, 'expected "with_js" to match /w[a-z]{10}_js/')
|
||||
end
|
||||
|
||||
it "should wait for title", :requires => [:js] do
|
||||
it "should wait for title", requires: [:js] do
|
||||
@session.click_link("Change title")
|
||||
expect(@session.assert_title("changed title")).to eq(true)
|
||||
end
|
||||
|
@ -59,7 +59,7 @@ Capybara::SpecHelper.spec '#assert_no_title' do
|
|||
@session.assert_no_title(/monkey/)
|
||||
end
|
||||
|
||||
it "should wait for title to disappear", :requires => [:js] do
|
||||
it "should wait for title to disappear", requires: [:js] do
|
||||
@session.click_link("Change title")
|
||||
expect(@session.assert_no_title('with_js')).to eq(true)
|
||||
end
|
||||
|
|
|
@ -96,14 +96,14 @@ Capybara::SpecHelper.spec "#attach_file" do
|
|||
|
||||
context "with :exact option" do
|
||||
it "should set a file path by partial label when false" do
|
||||
@session.attach_file "Imag", __FILE__, :exact => false
|
||||
@session.attach_file "Imag", __FILE__, exact: false
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
|
||||
end
|
||||
|
||||
it "not allow partial matches when true" do
|
||||
expect do
|
||||
@session.attach_file "Imag", __FILE__, :exact => true
|
||||
@session.attach_file "Imag", __FILE__, exact: true
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ Capybara::SpecHelper.spec "#check" do
|
|||
end
|
||||
end
|
||||
|
||||
it "should trigger associated events", :requires => [:js] do
|
||||
it "should trigger associated events", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.check('checkbox_with_event')
|
||||
expect(@session).to have_css('#checkbox_event_triggered');
|
||||
|
@ -86,28 +86,28 @@ Capybara::SpecHelper.spec "#check" do
|
|||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
@session.check('Ham', :exact => false)
|
||||
@session.check('Ham', exact: false)
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['pets']).to include('hamster')
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.check('Ham', :exact => true)
|
||||
@session.check('Ham', exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with `option` option" do
|
||||
it "can check boxes by their value" do
|
||||
@session.check('form[pets][]', :option => "cat")
|
||||
@session.check('form[pets][]', option: "cat")
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['pets']).to include('cat')
|
||||
end
|
||||
|
||||
it "should raise an error if option not found" do
|
||||
expect do
|
||||
@session.check('form[pets][]', :option => "elephant")
|
||||
@session.check('form[pets][]', option: "elephant")
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,28 +41,28 @@ Capybara::SpecHelper.spec "#choose" do
|
|||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
@session.choose("Mal", :exact => false)
|
||||
@session.choose("Mal", exact: false)
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['gender']).to eq('male')
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.choose("Mal", :exact => true)
|
||||
@session.choose("Mal", exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with `option` option" do
|
||||
it "can check radio buttons by their value" do
|
||||
@session.choose('form[gender]', :option => "male")
|
||||
@session.choose('form[gender]', option: "male")
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['gender']).to eq("male")
|
||||
end
|
||||
|
||||
it "should raise an error if option not found" do
|
||||
expect do
|
||||
@session.choose('form[gender]', :option => "hermaphrodite")
|
||||
@session.choose('form[gender]', option: "hermaphrodite")
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
@session.visit('/form')
|
||||
end
|
||||
|
||||
it "should wait for asynchronous load", :requires => [:js] do
|
||||
it "should wait for asynchronous load", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
@session.click_button('New Here')
|
||||
|
@ -427,8 +427,8 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
@session.fill_in('address1_city', :with =>'Paris')
|
||||
@session.fill_in('address1_street', :with =>'CDG')
|
||||
|
||||
@session.fill_in('address2_city', :with => 'Mikolaiv')
|
||||
@session.fill_in('address2_street', :with => 'PGS')
|
||||
@session.fill_in('address2_city', with: 'Mikolaiv')
|
||||
@session.fill_in('address2_street', with: 'PGS')
|
||||
|
||||
@session.click_button "awesome"
|
||||
|
||||
|
@ -446,13 +446,13 @@ Capybara::SpecHelper.spec '#click_button' do
|
|||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
@session.click_button('What an Awesome', :exact => false)
|
||||
@session.click_button('What an Awesome', exact: false)
|
||||
expect(extract_results(@session)['first_name']).to eq('John')
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.click_button('What an Awesome', :exact => true)
|
||||
@session.click_button('What an Awesome', exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
|
|||
expect(extract_results(@session)['first_name']).to eq('John')
|
||||
end
|
||||
|
||||
it "should wait for asynchronous load", :requires => [:js] do
|
||||
it "should wait for asynchronous load", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
@session.click_link_or_button('Has been clicked')
|
||||
|
@ -40,7 +40,7 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
|
|||
context "when `true`" do
|
||||
it "clicks on approximately matching link" do
|
||||
@session.visit('/with_html')
|
||||
@session.click_link_or_button('abore', :exact => false)
|
||||
@session.click_link_or_button('abore', exact: false)
|
||||
expect(@session).to have_content('Bar')
|
||||
end
|
||||
|
||||
|
@ -56,7 +56,7 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
|
|||
@session.visit('/with_html')
|
||||
msg = "Unable to find link or button \"abore\""
|
||||
expect do
|
||||
@session.click_link_or_button('abore', :exact => true)
|
||||
@session.click_link_or_button('abore', exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound, msg)
|
||||
end
|
||||
|
||||
|
@ -65,7 +65,7 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
|
|||
msg = "Unable to find link or button \"awe\""
|
||||
|
||||
expect do
|
||||
@session.click_link_or_button('awe', :exact => true)
|
||||
@session.click_link_or_button('awe', exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound, msg)
|
||||
end
|
||||
end
|
||||
|
@ -85,7 +85,7 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
|
|||
it "ignores disabled buttons when false" do
|
||||
@session.visit('/form')
|
||||
expect do
|
||||
@session.click_link_or_button('Disabled button', :disabled => false)
|
||||
@session.click_link_or_button('Disabled button', disabled: false)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
|
@ -105,7 +105,7 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
|
|||
it "does nothing when button is disabled" do
|
||||
@session.visit('/form')
|
||||
expect do
|
||||
@session.click_link_or_button('Disabled button', :disabled => false)
|
||||
@session.click_link_or_button('Disabled button', disabled: false)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ Capybara::SpecHelper.spec '#click_link' do
|
|||
@session.visit('/with_html')
|
||||
end
|
||||
|
||||
it "should wait for asynchronous load", :requires => [:js] do
|
||||
it "should wait for asynchronous load", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
@session.click_link('Has been clicked')
|
||||
|
@ -15,7 +15,7 @@ Capybara::SpecHelper.spec '#click_link' do
|
|||
expect(@session).to have_content('Another World')
|
||||
end
|
||||
|
||||
it "raises any errors caught inside the server", :requires => [:server] do
|
||||
it "raises any errors caught inside the server", requires: [:server] do
|
||||
quietly { @session.visit("/error") }
|
||||
expect do
|
||||
@session.click_link('foo')
|
||||
|
@ -76,34 +76,34 @@ Capybara::SpecHelper.spec '#click_link' do
|
|||
|
||||
context "with :href option given" do
|
||||
it "should find links with valid href" do
|
||||
@session.click_link('labore', :href => '/with_simple_html')
|
||||
@session.click_link('labore', href: '/with_simple_html')
|
||||
expect(@session).to have_content('Bar')
|
||||
end
|
||||
|
||||
it "should raise error if link wasn't found" do
|
||||
expect { @session.click_link('labore', :href => 'invalid_href') }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.click_link('labore', href: 'invalid_href') }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a regex :href option given" do
|
||||
it "should find a link matching an all-matching regex pattern" do
|
||||
@session.click_link('labore', :href => /.+/)
|
||||
@session.click_link('labore', href: /.+/)
|
||||
expect(@session).to have_content('Bar')
|
||||
end
|
||||
|
||||
it "should find a link matching an exact regex pattern" do
|
||||
@session.click_link('labore', :href => /\/with_simple_html/)
|
||||
@session.click_link('labore', href: /\/with_simple_html/)
|
||||
expect(@session).to have_content('Bar')
|
||||
end
|
||||
|
||||
it "should find a link matching a partial regex pattern" do
|
||||
@session.click_link('labore', :href => /\/with_simple/)
|
||||
@session.click_link('labore', href: /\/with_simple/)
|
||||
expect(@session).to have_content('Bar')
|
||||
end
|
||||
|
||||
it "should raise an error if no link's href matched the pattern" do
|
||||
expect { @session.click_link('labore', :href => /invalid_pattern/) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.click_link('labore', :href => /.+d+/) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.click_link('labore', href: /invalid_pattern/) }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.click_link('labore', href: /.+d+/) }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -135,7 +135,7 @@ Capybara::SpecHelper.spec '#click_link' do
|
|||
end
|
||||
|
||||
it "should do nothing on anchor links" do
|
||||
@session.fill_in("test_field", :with => 'blah')
|
||||
@session.fill_in("test_field", with: 'blah')
|
||||
@session.click_link('Normal Anchor')
|
||||
expect(@session.find_field("test_field").value).to eq('blah')
|
||||
@session.click_link('Blank Anchor')
|
||||
|
@ -145,7 +145,7 @@ Capybara::SpecHelper.spec '#click_link' do
|
|||
end
|
||||
|
||||
it "should do nothing on URL+anchor links for the same page" do
|
||||
@session.fill_in("test_field", :with => 'blah')
|
||||
@session.fill_in("test_field", with: 'blah')
|
||||
@session.click_link('Anchor on same page')
|
||||
expect(@session.find_field("test_field").value).to eq('blah')
|
||||
end
|
||||
|
@ -169,13 +169,13 @@ Capybara::SpecHelper.spec '#click_link' do
|
|||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
@session.click_link('abo', :exact => false)
|
||||
@session.click_link('abo', exact: false)
|
||||
expect(@session).to have_content('Bar')
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.click_link('abo', :exact => true)
|
||||
@session.click_link('abo', exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -85,13 +85,13 @@ Capybara::SpecHelper.spec '#current_url, #current_path, #current_host' do
|
|||
should_be_on 0, "/landed"
|
||||
end
|
||||
|
||||
it "is affected by pushState", :requires => [:js] do
|
||||
it "is affected by pushState", requires: [:js] do
|
||||
@session.visit("/with_js")
|
||||
@session.execute_script("window.history.pushState({}, '', '/pushed')")
|
||||
expect(@session.current_path).to eq("/pushed")
|
||||
end
|
||||
|
||||
it "is affected by replaceState", :requires => [:js] do
|
||||
it "is affected by replaceState", requires: [:js] do
|
||||
@session.visit("/with_js")
|
||||
@session.execute_script("window.history.replaceState({}, '', '/replaced')")
|
||||
expect(@session.current_path).to eq("/replaced")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#dismiss_confirm', :requires => [:modals] do
|
||||
Capybara::SpecHelper.spec '#dismiss_confirm', requires: [:modals] do
|
||||
before do
|
||||
@session.visit('/with_js')
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#dismiss_prompt', :requires => [:modals] do
|
||||
Capybara::SpecHelper.spec '#dismiss_prompt', requires: [:modals] do
|
||||
before do
|
||||
@session.visit('/with_js')
|
||||
end
|
||||
|
|
|
@ -24,8 +24,8 @@ Capybara::SpecHelper.spec '#match_selector?' do
|
|||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is not contained" do
|
||||
expect(@element).to match_selector("//span", :text => "42")
|
||||
expect(@element).not_to match_selector("//span", :text => "Doesnotexist")
|
||||
expect(@element).to match_selector("//span", text: "42")
|
||||
expect(@element).not_to match_selector("//span", text: "Doesnotexist")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -83,22 +83,22 @@ Capybara::SpecHelper.spec '#not_matches_selector?' do
|
|||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is contained" do
|
||||
expect(@element).not_to not_match_selector(:css, "span.number", :text => "42")
|
||||
expect(@element).to not_match_selector(:css, "span.number", :text => "Doesnotexist")
|
||||
expect(@element).not_to not_match_selector(:css, "span.number", text: "42")
|
||||
expect(@element).to not_match_selector(:css, "span.number", text: "Doesnotexist")
|
||||
end
|
||||
end
|
||||
|
||||
it "should have CSS sugar" do
|
||||
expect(@element.not_matches_css?("span.number")).to be false
|
||||
expect(@element.not_matches_css?("p a#doesnotexist")).to be true
|
||||
expect(@element.not_matches_css?("span.number", :text => "42")).to be false
|
||||
expect(@element.not_matches_css?("span.number", :text => "Doesnotexist")).to be true
|
||||
expect(@element.not_matches_css?("span.number", text: "42")).to be false
|
||||
expect(@element.not_matches_css?("span.number", text: "Doesnotexist")).to be true
|
||||
end
|
||||
|
||||
it "should have xpath sugar" do
|
||||
expect(@element.not_matches_xpath?("//span")).to be false
|
||||
expect(@element.not_matches_xpath?("//div")).to be true
|
||||
expect(@element.not_matches_xpath?("//span", :text => "42")).to be false
|
||||
expect(@element.not_matches_xpath?("//span", :text => "Doesnotexist")).to be true
|
||||
expect(@element.not_matches_xpath?("//span", text: "42")).to be false
|
||||
expect(@element.not_matches_xpath?("//span", text: "Doesnotexist")).to be true
|
||||
end
|
||||
end if Gem::Version.new(RSpec::Expectations::Version::STRING) >= Gem::Version.new('3.1')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec "#evaluate_script", :requires => [:js] do
|
||||
Capybara::SpecHelper.spec "#evaluate_script", requires: [:js] do
|
||||
it "should evaluate the given script and return whatever it produces" do
|
||||
@session.visit('/with_js')
|
||||
expect(@session.evaluate_script("1+3")).to eq(4)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec "#execute_script", :requires => [:js] do
|
||||
Capybara::SpecHelper.spec "#execute_script", requires: [:js] do
|
||||
it "should execute the given script and return nothing" do
|
||||
@session.visit('/with_js')
|
||||
expect(@session.execute_script("document.getElementById('change').textContent = 'Funky Doodle'")).to be_nil
|
||||
expect(@session).to have_css('#change', :text => 'Funky Doodle')
|
||||
expect(@session).to have_css('#change', text: 'Funky Doodle')
|
||||
end
|
||||
|
||||
it "should be able to call functions defined in the page" do
|
||||
|
|
|
@ -5,97 +5,97 @@ Capybara::SpecHelper.spec "#fill_in" do
|
|||
end
|
||||
|
||||
it "should fill in a text field by id" do
|
||||
@session.fill_in('form_first_name', :with => 'Harry')
|
||||
@session.fill_in('form_first_name', with: 'Harry')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['first_name']).to eq('Harry')
|
||||
end
|
||||
|
||||
it "should fill in a text field by name" do
|
||||
@session.fill_in('form[last_name]', :with => 'Green')
|
||||
@session.fill_in('form[last_name]', with: 'Green')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['last_name']).to eq('Green')
|
||||
end
|
||||
|
||||
it "should fill in a text field by label without for" do
|
||||
@session.fill_in('First Name', :with => 'Harry')
|
||||
@session.fill_in('First Name', with: 'Harry')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['first_name']).to eq('Harry')
|
||||
end
|
||||
|
||||
it "should fill in a url field by label without for" do
|
||||
@session.fill_in('Html5 Url', :with => 'http://www.avenueq.com')
|
||||
@session.fill_in('Html5 Url', with: 'http://www.avenueq.com')
|
||||
@session.click_button('html5_submit')
|
||||
expect(extract_results(@session)['html5_url']).to eq('http://www.avenueq.com')
|
||||
end
|
||||
|
||||
it "should fill in a textarea by id" do
|
||||
@session.fill_in('form_description', :with => 'Texty text')
|
||||
@session.fill_in('form_description', with: 'Texty text')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['description']).to eq('Texty text')
|
||||
end
|
||||
|
||||
it "should fill in a textarea by label" do
|
||||
@session.fill_in('Description', :with => 'Texty text')
|
||||
@session.fill_in('Description', with: 'Texty text')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['description']).to eq('Texty text')
|
||||
end
|
||||
|
||||
it "should fill in a textarea by name" do
|
||||
@session.fill_in('form[description]', :with => 'Texty text')
|
||||
@session.fill_in('form[description]', with: 'Texty text')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['description']).to eq('Texty text')
|
||||
end
|
||||
|
||||
it "should fill in a password field by id" do
|
||||
@session.fill_in('form_password', :with => 'supasikrit')
|
||||
@session.fill_in('form_password', with: 'supasikrit')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['password']).to eq('supasikrit')
|
||||
end
|
||||
|
||||
it "should handle HTML in a textarea" do
|
||||
@session.fill_in('form_description', :with => 'is <strong>very</strong> secret!')
|
||||
@session.fill_in('form_description', with: 'is <strong>very</strong> secret!')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['description']).to eq('is <strong>very</strong> secret!')
|
||||
end
|
||||
|
||||
it "should handle newlines in a textarea" do
|
||||
@session.fill_in('form_description', :with => "\nSome text\n")
|
||||
@session.fill_in('form_description', with: "\nSome text\n")
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['description']).to eq("\r\nSome text\r\n")
|
||||
end
|
||||
|
||||
it "should fill in a field with a custom type" do
|
||||
@session.fill_in('Schmooo', :with => 'Schmooo is the game')
|
||||
@session.fill_in('Schmooo', with: 'Schmooo is the game')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['schmooo']).to eq('Schmooo is the game')
|
||||
end
|
||||
|
||||
it "should fill in a field without a type" do
|
||||
@session.fill_in('Phone', :with => '+1 555 7022')
|
||||
@session.fill_in('Phone', with: '+1 555 7022')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['phone']).to eq('+1 555 7022')
|
||||
end
|
||||
|
||||
it "should fill in a text field respecting its maxlength attribute" do
|
||||
@session.fill_in('Zipcode', :with => '52071350')
|
||||
@session.fill_in('Zipcode', with: '52071350')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['zipcode']).to eq('52071')
|
||||
end
|
||||
|
||||
it "should fill in a password field by name" do
|
||||
@session.fill_in('form[password]', :with => 'supasikrit')
|
||||
@session.fill_in('form[password]', with: 'supasikrit')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['password']).to eq('supasikrit')
|
||||
end
|
||||
|
||||
it "should fill in a password field by label" do
|
||||
@session.fill_in('Password', :with => 'supasikrit')
|
||||
@session.fill_in('Password', with: 'supasikrit')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['password']).to eq('supasikrit')
|
||||
end
|
||||
|
||||
it "should fill in a password field by name" do
|
||||
@session.fill_in('form[password]', :with => 'supasikrit')
|
||||
@session.fill_in('form[password]', with: 'supasikrit')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['password']).to eq('supasikrit')
|
||||
end
|
||||
|
@ -104,39 +104,39 @@ Capybara::SpecHelper.spec "#fill_in" do
|
|||
expect {@session.fill_in 'Name', 'ignu'}.to raise_error(RuntimeError, /with/)
|
||||
end
|
||||
|
||||
it "should wait for asynchronous load", :requires => [:js] do
|
||||
it "should wait for asynchronous load", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
@session.fill_in('new_field', :with => 'Testing...')
|
||||
@session.fill_in('new_field', with: 'Testing...')
|
||||
end
|
||||
|
||||
it "casts to string" do
|
||||
@session.fill_in(:'form_first_name', :with => :'Harry')
|
||||
@session.fill_in(:'form_first_name', with: :'Harry')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['first_name']).to eq('Harry')
|
||||
end
|
||||
|
||||
it "casts to string if field has maxlength" do
|
||||
@session.fill_in(:'form_zipcode', :with => 1234567)
|
||||
@session.fill_in(:'form_zipcode', with: 1234567)
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['zipcode']).to eq('12345')
|
||||
end
|
||||
|
||||
context 'on a pre-populated textfield with a reformatting onchange', :requires => [:js] do
|
||||
context 'on a pre-populated textfield with a reformatting onchange', requires: [:js] do
|
||||
it 'should only trigger onchange once' do
|
||||
@session.visit('/with_js')
|
||||
@session.fill_in('with_change_event', :with => 'some value')
|
||||
@session.fill_in('with_change_event', with: 'some value')
|
||||
# click outside the field to trigger the change event
|
||||
@session.find(:css, 'body').click
|
||||
expect(@session.find(:css, '.change_event_triggered', :match => :one)).to have_text 'some value'
|
||||
expect(@session.find(:css, '.change_event_triggered', match: :one)).to have_text 'some value'
|
||||
end
|
||||
|
||||
it 'should trigger change when clearing field' do
|
||||
@session.visit('/with_js')
|
||||
@session.fill_in('with_change_event', :with => '')
|
||||
@session.fill_in('with_change_event', with: '')
|
||||
# click outside the field to trigger the change event
|
||||
@session.find(:css, 'body').click
|
||||
expect(@session).to have_selector(:css, '.change_event_triggered', :match => :one)
|
||||
expect(@session).to have_selector(:css, '.change_event_triggered', match: :one)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -146,7 +146,7 @@ Capybara::SpecHelper.spec "#fill_in" do
|
|||
it "should not find a hidden field" do
|
||||
msg = "Unable to find field \"Super Secret\""
|
||||
expect do
|
||||
@session.fill_in('Super Secret', :with => '777')
|
||||
@session.fill_in('Super Secret', with: '777')
|
||||
end.to raise_error(Capybara::ElementNotFound, msg)
|
||||
end
|
||||
end
|
||||
|
@ -155,7 +155,7 @@ Capybara::SpecHelper.spec "#fill_in" do
|
|||
it "should raise an error" do
|
||||
msg = "Unable to find field \"does not exist\""
|
||||
expect do
|
||||
@session.fill_in('does not exist', :with => 'Blah blah')
|
||||
@session.fill_in('does not exist', with: 'Blah blah')
|
||||
end.to raise_error(Capybara::ElementNotFound, msg)
|
||||
end
|
||||
end
|
||||
|
@ -163,21 +163,21 @@ Capybara::SpecHelper.spec "#fill_in" do
|
|||
context "on a disabled field" do
|
||||
it "should raise an error" do
|
||||
expect do
|
||||
@session.fill_in('Disabled Text Field', :with => 'Blah blah')
|
||||
@session.fill_in('Disabled Text Field', with: 'Blah blah')
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
@session.fill_in("Explanation", :with => "Dude", :exact => false)
|
||||
@session.fill_in("Explanation", with: "Dude", exact: false)
|
||||
@session.click_button("awesome")
|
||||
expect(extract_results(@session)["name_explanation"]).to eq("Dude")
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.fill_in("Explanation", :with => "Dude", :exact => true)
|
||||
@session.fill_in("Explanation", with: "Dude", exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,24 +33,24 @@ Capybara::SpecHelper.spec '#find_button' do
|
|||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
expect(@session.find_button('What an Awesome', :exact => false).value).to eq("awesome")
|
||||
expect(@session.find_button('What an Awesome', exact: false).value).to eq("awesome")
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.find_button('What an Awesome', :exact => true)
|
||||
@session.find_button('What an Awesome', exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with :disabled option" do
|
||||
it "should find disabled buttons when true" do
|
||||
expect(@session.find_button('Disabled button', :disabled => true).value).to eq("Disabled button")
|
||||
expect(@session.find_button('Disabled button', disabled: true).value).to eq("Disabled button")
|
||||
end
|
||||
|
||||
it "should not find disabled buttons when false" do
|
||||
expect do
|
||||
@session.find_button('Disabled button', :disabled => false)
|
||||
@session.find_button('Disabled button', disabled: false)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
|
@ -61,7 +61,7 @@ Capybara::SpecHelper.spec '#find_button' do
|
|||
end
|
||||
|
||||
it "should find disabled buttons when :all" do
|
||||
expect(@session.find_button('Disabled button', :disabled => :all).value).to eq("Disabled button")
|
||||
expect(@session.find_button('Disabled button', disabled: :all).value).to eq("Disabled button")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,12 +20,12 @@ Capybara::SpecHelper.spec '#find_by_id' do
|
|||
|
||||
context "with :visible option" do
|
||||
it "finds invisible elements when `false`" do
|
||||
expect(@session.find_by_id("hidden_via_ancestor", :visible => false).text(:all)).to match(/with hidden ancestor/)
|
||||
expect(@session.find_by_id("hidden_via_ancestor", visible: false).text(:all)).to match(/with hidden ancestor/)
|
||||
end
|
||||
|
||||
it "finds invisible elements when `false`" do
|
||||
expect do
|
||||
@session.find_by_id("hidden_via_ancestor", :visible => true)
|
||||
@session.find_by_id("hidden_via_ancestor", visible: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,24 +49,24 @@ Capybara::SpecHelper.spec '#find_field' do
|
|||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
expect(@session.find_field("Explanation", :exact => false)[:name]).to eq("form[name_explanation]")
|
||||
expect(@session.find_field("Explanation", exact: false)[:name]).to eq("form[name_explanation]")
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.find_field("Explanation", :exact => true)
|
||||
@session.find_field("Explanation", exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with :disabled option" do
|
||||
it "should find disabled fields when true" do
|
||||
expect(@session.find_field("Disabled Checkbox", :disabled => true)[:name]).to eq("form[disabled_checkbox]")
|
||||
expect(@session.find_field("Disabled Checkbox", disabled: true)[:name]).to eq("form[disabled_checkbox]")
|
||||
end
|
||||
|
||||
it "should not find disabled fields when false" do
|
||||
expect do
|
||||
@session.find_field("Disabled Checkbox", :disabled => false)
|
||||
@session.find_field("Disabled Checkbox", disabled: false)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
|
@ -77,11 +77,11 @@ Capybara::SpecHelper.spec '#find_field' do
|
|||
end
|
||||
|
||||
it "should find disabled fields when :all" do
|
||||
expect(@session.find_field("Disabled Checkbox", :disabled => :all)[:name]).to eq("form[disabled_checkbox]")
|
||||
expect(@session.find_field("Disabled Checkbox", disabled: :all)[:name]).to eq("form[disabled_checkbox]")
|
||||
end
|
||||
|
||||
it "should find enabled fields when :all" do
|
||||
expect(@session.find_field('Dog', :disabled => :all).value).to eq('dog')
|
||||
expect(@session.find_field('Dog', disabled: :all).value).to eq('dog')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -33,12 +33,12 @@ Capybara::SpecHelper.spec '#find_link' do
|
|||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
expect(@session.find_link('abo', :exact => false).text).to eq("labore")
|
||||
expect(@session.find_link('abo', exact: false).text).to eq("labore")
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.find_link('abo', :exact => true)
|
||||
@session.find_link('abo', exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,15 +14,15 @@ Capybara::SpecHelper.spec '#find' do
|
|||
end
|
||||
|
||||
it "should find the first element using the given locator and options" do
|
||||
expect(@session.find('//a', :text => 'Redirect')[:id]).to eq('red')
|
||||
expect(@session.find(:css, 'a', :text => 'A link came first')[:title]).to eq('twas a fine link')
|
||||
expect(@session.find('//a', text: 'Redirect')[:id]).to eq('red')
|
||||
expect(@session.find(:css, 'a', text: 'A link came first')[:title]).to eq('twas a fine link')
|
||||
end
|
||||
|
||||
it "should raise an error if there are multiple matches" do
|
||||
expect { @session.find('//a') }.to raise_error(Capybara::Ambiguous)
|
||||
end
|
||||
|
||||
it "should wait for asynchronous load", :requires => [:js] do
|
||||
it "should wait for asynchronous load", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session.find(:css, "a#has-been-clicked").text).to include('Has been clicked')
|
||||
|
@ -34,12 +34,12 @@ Capybara::SpecHelper.spec '#find' do
|
|||
end
|
||||
end
|
||||
|
||||
context "with :wait option", :requires => [:js] do
|
||||
context "with :wait option", requires: [:js] do
|
||||
it "should not wait for asynchronous load when `false` given" do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect do
|
||||
@session.find(:css, "a#has-been-clicked", :wait => false)
|
||||
@session.find(:css, "a#has-been-clicked", wait: false)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
|
@ -47,18 +47,18 @@ Capybara::SpecHelper.spec '#find' do
|
|||
@session.visit('/with_js')
|
||||
@session.click_link('Slowly')
|
||||
expect do
|
||||
@session.find(:css, "a#slow-clicked", :wait => 0.2)
|
||||
@session.find(:css, "a#slow-clicked", wait: 0.2)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "should find element if it appears before given wait duration" do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session.find(:css, "a#has-been-clicked", :wait => 0.9).text).to include('Has been clicked')
|
||||
expect(@session.find(:css, "a#has-been-clicked", wait: 0.9).text).to include('Has been clicked')
|
||||
end
|
||||
end
|
||||
|
||||
context "with frozen time", :requires => [:js] do
|
||||
context "with frozen time", requires: [:js] do
|
||||
if defined?(Process::CLOCK_MONOTONIC)
|
||||
it "will time out even if time is frozen" do
|
||||
@session.visit('/with_js')
|
||||
|
@ -126,8 +126,8 @@ Capybara::SpecHelper.spec '#find' do
|
|||
end
|
||||
|
||||
it "should find elements that match the filter" do
|
||||
expect(@session.find(:beatle, 'Paul', :type => 'drummer').text).to eq('Paul')
|
||||
expect(@session.find(:beatle, 'Ringo', :type => 'drummer').text).to eq('Ringo')
|
||||
expect(@session.find(:beatle, 'Paul', type: 'drummer').text).to eq('Paul')
|
||||
expect(@session.find(:beatle, 'Ringo', type: 'drummer').text).to eq('Ringo')
|
||||
end
|
||||
|
||||
it "ignores filter when it is not given" do
|
||||
|
@ -136,8 +136,8 @@ Capybara::SpecHelper.spec '#find' do
|
|||
end
|
||||
|
||||
it "should not find elements that don't match the filter" do
|
||||
expect { @session.find(:beatle, 'John', :type => 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.find(:beatle, 'George', :type => 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.find(:beatle, 'John', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.find(:beatle, 'George', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -145,13 +145,13 @@ Capybara::SpecHelper.spec '#find' do
|
|||
before do
|
||||
Capybara.add_selector(:beatle) do
|
||||
xpath { |name| ".//li[contains(@class, 'beatle')][contains(text(), '#{name}')]" }
|
||||
filter(:type, :default => "drummer") { |node, type| node[:class].split(/\s+/).include?(type) }
|
||||
filter(:type, default: "drummer") { |node, type| node[:class].split(/\s+/).include?(type) }
|
||||
end
|
||||
end
|
||||
|
||||
it "should find elements that match the filter" do
|
||||
expect(@session.find(:beatle, 'Paul', :type => 'drummer').text).to eq('Paul')
|
||||
expect(@session.find(:beatle, 'Ringo', :type => 'drummer').text).to eq('Ringo')
|
||||
expect(@session.find(:beatle, 'Paul', type: 'drummer').text).to eq('Paul')
|
||||
expect(@session.find(:beatle, 'Ringo', type: 'drummer').text).to eq('Ringo')
|
||||
end
|
||||
|
||||
it "should use default value when filter is not given" do
|
||||
|
@ -160,8 +160,8 @@ Capybara::SpecHelper.spec '#find' do
|
|||
end
|
||||
|
||||
it "should not find elements that don't match the filter" do
|
||||
expect { @session.find(:beatle, 'John', :type => 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.find(:beatle, 'George', :type => 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.find(:beatle, 'John', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
||||
expect { @session.find(:beatle, 'George', type: 'drummer') }.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -216,15 +216,15 @@ Capybara::SpecHelper.spec '#find' do
|
|||
|
||||
context "with :exact option" do
|
||||
it "matches exactly when true" do
|
||||
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => true).value).to eq("monkey")
|
||||
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: true).value).to eq("monkey")
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :exact => true)
|
||||
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "matches loosely when false" do
|
||||
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => false).value).to eq("monkey")
|
||||
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :exact => false).value).to eq("monkey")
|
||||
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], exact: false).value).to eq("monkey")
|
||||
expect(@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], exact: false).value).to eq("monkey")
|
||||
end
|
||||
|
||||
it "defaults to `Capybara.exact`" do
|
||||
|
@ -247,31 +247,31 @@ Capybara::SpecHelper.spec '#find' do
|
|||
context "when set to `one`" do
|
||||
it "raises an error when multiple matches exist" do
|
||||
expect do
|
||||
@session.find(:css, ".multiple", :match => :one)
|
||||
@session.find(:css, ".multiple", match: :one)
|
||||
end.to raise_error(Capybara::Ambiguous)
|
||||
end
|
||||
it "raises an error even if there the match is exact and the others are inexact" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :exact => false, :match => :one)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], exact: false, match: :one)
|
||||
end.to raise_error(Capybara::Ambiguous)
|
||||
end
|
||||
it "returns the element if there is only one" do
|
||||
expect(@session.find(:css, ".singular", :match => :one).text).to eq("singular")
|
||||
expect(@session.find(:css, ".singular", match: :one).text).to eq("singular")
|
||||
end
|
||||
it "raises an error if there is no match" do
|
||||
expect do
|
||||
@session.find(:css, ".does-not-exist", :match => :one)
|
||||
@session.find(:css, ".does-not-exist", match: :one)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "when set to `first`" do
|
||||
it "returns the first matched element" do
|
||||
expect(@session.find(:css, ".multiple", :match => :first).text).to eq("multiple one")
|
||||
expect(@session.find(:css, ".multiple", match: :first).text).to eq("multiple one")
|
||||
end
|
||||
it "raises an error if there is no match" do
|
||||
expect do
|
||||
@session.find(:css, ".does-not-exist", :match => :first)
|
||||
@session.find(:css, ".does-not-exist", match: :first)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
@ -280,25 +280,25 @@ Capybara::SpecHelper.spec '#find' do
|
|||
context "and `exact` set to `false`" do
|
||||
it "raises an error when there are multiple exact matches" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :smart, :exact => false)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: false)
|
||||
end.to raise_error(Capybara::Ambiguous)
|
||||
end
|
||||
it "finds a single exact match when there also are inexact matches" do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :smart, :exact => false)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: false)
|
||||
expect(result.text).to eq("almost singular")
|
||||
end
|
||||
it "raises an error when there are multiple inexact matches" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :smart, :exact => false)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: false)
|
||||
end.to raise_error(Capybara::Ambiguous)
|
||||
end
|
||||
it "finds a single inexact match" do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :smart, :exact => false)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: false)
|
||||
expect(result.text).to eq("almost singular but not quite")
|
||||
end
|
||||
it "raises an error if there is no match" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :smart, :exact => false)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: false)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
@ -306,26 +306,26 @@ Capybara::SpecHelper.spec '#find' do
|
|||
context "with `exact` set to `true`" do
|
||||
it "raises an error when there are multiple exact matches" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :smart, :exact => true)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :smart, exact: true)
|
||||
end.to raise_error(Capybara::Ambiguous)
|
||||
end
|
||||
it "finds a single exact match when there also are inexact matches" do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :smart, :exact => true)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :smart, exact: true)
|
||||
expect(result.text).to eq("almost singular")
|
||||
end
|
||||
it "raises an error when there are multiple inexact matches" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :smart, :exact => true)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :smart, exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
it "raises an error when there is a single inexact matches" do
|
||||
expect do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :smart, :exact => true)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :smart, exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
it "raises an error if there is no match" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :smart, :exact => true)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :smart, exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
@ -334,50 +334,50 @@ Capybara::SpecHelper.spec '#find' do
|
|||
context "when set to `prefer_exact`" do
|
||||
context "and `exact` set to `false`" do
|
||||
it "picks the first one when there are multiple exact matches" do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :prefer_exact, :exact => false)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: false)
|
||||
expect(result.text).to eq("multiple one")
|
||||
end
|
||||
it "finds a single exact match when there also are inexact matches" do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :prefer_exact, :exact => false)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: false)
|
||||
expect(result.text).to eq("almost singular")
|
||||
end
|
||||
it "picks the first one when there are multiple inexact matches" do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :prefer_exact, :exact => false)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: false)
|
||||
expect(result.text).to eq("almost singular but not quite")
|
||||
end
|
||||
it "finds a single inexact match" do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :prefer_exact, :exact => false)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: false)
|
||||
expect(result.text).to eq("almost singular but not quite")
|
||||
end
|
||||
it "raises an error if there is no match" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :prefer_exact, :exact => false)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: false)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "with `exact` set to `true`" do
|
||||
it "picks the first one when there are multiple exact matches" do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :prefer_exact, :exact => true)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], match: :prefer_exact, exact: true)
|
||||
expect(result.text).to eq("multiple one")
|
||||
end
|
||||
it "finds a single exact match when there also are inexact matches" do
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :prefer_exact, :exact => true)
|
||||
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], match: :prefer_exact, exact: true)
|
||||
expect(result.text).to eq("almost singular")
|
||||
end
|
||||
it "raises an error if there are multiple inexact matches" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :prefer_exact, :exact => true)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], match: :prefer_exact, exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
it "raises an error if there is a single inexact match" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :prefer_exact, :exact => true)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], match: :prefer_exact, exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
it "raises an error if there is no match" do
|
||||
expect do
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], :match => :prefer_exact, :exact => true)
|
||||
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("does-not-exist")], match: :prefer_exact, exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
@ -394,7 +394,7 @@ Capybara::SpecHelper.spec '#find' do
|
|||
|
||||
it "raises an error when unknown option given" do
|
||||
expect do
|
||||
@session.find(:css, ".singular", :match => :schmoo)
|
||||
@session.find(:css, ".singular", match: :schmoo)
|
||||
end.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,27 +43,27 @@ Capybara::SpecHelper.spec '#first' do
|
|||
|
||||
context "with visible filter" do
|
||||
it "should only find visible nodes when true" do
|
||||
expect(@session.first(:css, "a#invisible", :visible => true)).to be_nil
|
||||
expect(@session.first(:css, "a#invisible", visible: true)).to be_nil
|
||||
end
|
||||
|
||||
it "should find nodes regardless of whether they are invisible when false" do
|
||||
expect(@session.first(:css, "a#invisible", :visible => false)).not_to be_nil
|
||||
expect(@session.first(:css, "a#visible", :visible => false)).not_to be_nil
|
||||
expect(@session.first(:css, "a#invisible", visible: false)).not_to be_nil
|
||||
expect(@session.first(:css, "a#visible", visible: false)).not_to be_nil
|
||||
end
|
||||
|
||||
it "should find nodes regardless of whether they are invisible when :all" do
|
||||
expect(@session.first(:css, "a#invisible", :visible => :all)).not_to be_nil
|
||||
expect(@session.first(:css, "a#visible", :visible => :all)).not_to be_nil
|
||||
expect(@session.first(:css, "a#invisible", visible: :all)).not_to be_nil
|
||||
expect(@session.first(:css, "a#visible", visible: :all)).not_to be_nil
|
||||
end
|
||||
|
||||
it "should find only hidden nodes when :hidden" do
|
||||
expect(@session.first(:css, "a#invisible", :visible => :hidden)).not_to be_nil
|
||||
expect(@session.first(:css, "a#visible", :visible => :hidden)).to be_nil
|
||||
expect(@session.first(:css, "a#invisible", visible: :hidden)).not_to be_nil
|
||||
expect(@session.first(:css, "a#visible", visible: :hidden)).to be_nil
|
||||
end
|
||||
|
||||
it "should find only visible nodes when :visible" do
|
||||
expect(@session.first(:css, "a#invisible", :visible => :visible)).to be_nil
|
||||
expect(@session.first(:css, "a#visible", :visible => :visible)).not_to be_nil
|
||||
expect(@session.first(:css, "a#invisible", visible: :visible)).to be_nil
|
||||
expect(@session.first(:css, "a#visible", visible: :visible)).not_to be_nil
|
||||
end
|
||||
|
||||
it "should default to Capybara.ignore_hidden_elements" do
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#go_back', :requires => [:js] do
|
||||
Capybara::SpecHelper.spec '#go_back', requires: [:js] do
|
||||
it "should fetch a response from the driver from the previous page" do
|
||||
@session.visit('/')
|
||||
expect(@session).to have_content('Hello world!')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#go_forward', :requires => [:js] do
|
||||
Capybara::SpecHelper.spec '#go_forward', requires: [:js] do
|
||||
it "should fetch a response from the driver from the previous page" do
|
||||
@session.visit('/')
|
||||
expect(@session).to have_content('Hello world!')
|
||||
|
|
|
@ -10,8 +10,8 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|||
expect(@session).to have_button(:'crap321')
|
||||
end
|
||||
|
||||
it "should be true for disabled buttons if :disabled => true" do
|
||||
expect(@session).to have_button('Disabled button', :disabled => true)
|
||||
it "should be true for disabled buttons if disabled: true" do
|
||||
expect(@session).to have_button('Disabled button', disabled: true)
|
||||
end
|
||||
|
||||
it "should be false if the given button is not on the page" do
|
||||
|
@ -22,16 +22,16 @@ Capybara::SpecHelper.spec '#has_button?' do
|
|||
expect(@session).not_to have_button('Disabled button')
|
||||
end
|
||||
|
||||
it "should be false for disabled buttons if :disabled => false" do
|
||||
expect(@session).not_to have_button('Disabled button', :disabled => false)
|
||||
it "should be false for disabled buttons if disabled: false" do
|
||||
expect(@session).not_to have_button('Disabled button', disabled: false)
|
||||
end
|
||||
|
||||
it "should be true for disabled buttons if :disabled => :all" do
|
||||
expect(@session).to have_button('Disabled button', :disabled => :all)
|
||||
it "should be true for disabled buttons if disabled: :all" do
|
||||
expect(@session).to have_button('Disabled button', disabled: :all)
|
||||
end
|
||||
|
||||
it "should be true for enabled buttons if :disabled => :all" do
|
||||
expect(@session).to have_button('med', :disabled => :all)
|
||||
it "should be true for enabled buttons if disabled: :all" do
|
||||
expect(@session).to have_button('med', disabled: :all)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -45,8 +45,8 @@ Capybara::SpecHelper.spec '#has_no_button?' do
|
|||
expect(@session).not_to have_no_button('crap321')
|
||||
end
|
||||
|
||||
it "should be true for disabled buttons if :disabled => true" do
|
||||
expect(@session).not_to have_no_button('Disabled button', :disabled => true)
|
||||
it "should be true for disabled buttons if disabled: true" do
|
||||
expect(@session).not_to have_no_button('Disabled button', disabled: true)
|
||||
end
|
||||
|
||||
it "should be false if the given button is not on the page" do
|
||||
|
@ -57,7 +57,7 @@ Capybara::SpecHelper.spec '#has_no_button?' do
|
|||
expect(@session).to have_no_button('Disabled button')
|
||||
end
|
||||
|
||||
it "should be false for disabled buttons if :disabled => false" do
|
||||
expect(@session).to have_no_button('Disabled button', :disabled => false)
|
||||
it "should be false for disabled buttons if disabled: false" do
|
||||
expect(@session).to have_no_button('Disabled button', disabled: false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|||
end
|
||||
end
|
||||
|
||||
it "should wait for content to appear", :requires => [:js] do
|
||||
it "should wait for content to appear", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session).to have_css("input[type='submit'][value='New Here']")
|
||||
|
@ -30,86 +30,86 @@ Capybara::SpecHelper.spec '#has_css?' do
|
|||
|
||||
context "with between" do
|
||||
it "should be true if the content occurs within the range given" do
|
||||
expect(@session).to have_css("p", :between => 1..4)
|
||||
expect(@session).to have_css("p a#foo", :between => 1..3)
|
||||
expect(@session).to have_css("p a.doesnotexist", :between => 0..8)
|
||||
expect(@session).to have_css("p", between: 1..4)
|
||||
expect(@session).to have_css("p a#foo", between: 1..3)
|
||||
expect(@session).to have_css("p a.doesnotexist", between: 0..8)
|
||||
end
|
||||
|
||||
it "should be false if the content occurs more or fewer times than range" do
|
||||
expect(@session).not_to have_css("p", :between => 6..11 )
|
||||
expect(@session).not_to have_css("p a#foo", :between => 4..7)
|
||||
expect(@session).not_to have_css("p a.doesnotexist", :between => 3..8)
|
||||
expect(@session).not_to have_css("p", between: 6..11 )
|
||||
expect(@session).not_to have_css("p a#foo", between: 4..7)
|
||||
expect(@session).not_to have_css("p a.doesnotexist", between: 3..8)
|
||||
end
|
||||
end
|
||||
|
||||
context "with count" do
|
||||
it "should be true if the content occurs the given number of times" do
|
||||
expect(@session).to have_css("p", :count => 3)
|
||||
expect(@session).to have_css("p a#foo", :count => 1)
|
||||
expect(@session).to have_css("p a.doesnotexist", :count => 0)
|
||||
expect(@session).to have_css("p", count: 3)
|
||||
expect(@session).to have_css("p a#foo", count: 1)
|
||||
expect(@session).to have_css("p a.doesnotexist", count: 0)
|
||||
end
|
||||
|
||||
it "should be false if the content occurs a different number of times than the given" do
|
||||
expect(@session).not_to have_css("p", :count => 6)
|
||||
expect(@session).not_to have_css("p a#foo", :count => 2)
|
||||
expect(@session).not_to have_css("p a.doesnotexist", :count => 1)
|
||||
expect(@session).not_to have_css("p", count: 6)
|
||||
expect(@session).not_to have_css("p a#foo", count: 2)
|
||||
expect(@session).not_to have_css("p a.doesnotexist", count: 1)
|
||||
end
|
||||
|
||||
it "should coerce count to an integer" do
|
||||
expect(@session).to have_css("p", :count => "3")
|
||||
expect(@session).to have_css("p a#foo", :count => "1")
|
||||
expect(@session).to have_css("p", count: "3")
|
||||
expect(@session).to have_css("p a#foo", count: "1")
|
||||
end
|
||||
end
|
||||
|
||||
context "with maximum" do
|
||||
it "should be true when content occurs same or fewer times than given" do
|
||||
expect(@session).to have_css("h2.head", :maximum => 5) # edge case
|
||||
expect(@session).to have_css("h2", :maximum => 10)
|
||||
expect(@session).to have_css("p a.doesnotexist", :maximum => 1)
|
||||
expect(@session).to have_css("p a.doesnotexist", :maximum => 0)
|
||||
expect(@session).to have_css("h2.head", maximum: 5) # edge case
|
||||
expect(@session).to have_css("h2", maximum: 10)
|
||||
expect(@session).to have_css("p a.doesnotexist", maximum: 1)
|
||||
expect(@session).to have_css("p a.doesnotexist", maximum: 0)
|
||||
end
|
||||
|
||||
it "should be false when content occurs more times than given" do
|
||||
expect(@session).not_to have_css("h2.head", :maximum => 4) # edge case
|
||||
expect(@session).not_to have_css("h2", :maximum => 3)
|
||||
expect(@session).not_to have_css("p", :maximum => 1)
|
||||
expect(@session).not_to have_css("h2.head", maximum: 4) # edge case
|
||||
expect(@session).not_to have_css("h2", maximum: 3)
|
||||
expect(@session).not_to have_css("p", maximum: 1)
|
||||
end
|
||||
|
||||
it "should coerce maximum to an integer" do
|
||||
expect(@session).to have_css("h2.head", :maximum => "5") # edge case
|
||||
expect(@session).to have_css("h2", :maximum => "10")
|
||||
expect(@session).to have_css("h2.head", maximum: "5") # edge case
|
||||
expect(@session).to have_css("h2", maximum: "10")
|
||||
end
|
||||
end
|
||||
|
||||
context "with minimum" do
|
||||
it "should be true when content occurs same or more times than given" do
|
||||
expect(@session).to have_css("h2.head", :minimum => 5) # edge case
|
||||
expect(@session).to have_css("h2", :minimum => 3)
|
||||
expect(@session).to have_css("p a.doesnotexist", :minimum => 0)
|
||||
expect(@session).to have_css("h2.head", minimum: 5) # edge case
|
||||
expect(@session).to have_css("h2", minimum: 3)
|
||||
expect(@session).to have_css("p a.doesnotexist", minimum: 0)
|
||||
end
|
||||
|
||||
it "should be false when content occurs fewer times than given" do
|
||||
expect(@session).not_to have_css("h2.head", :minimum => 6) # edge case
|
||||
expect(@session).not_to have_css("h2", :minimum => 8)
|
||||
expect(@session).not_to have_css("p", :minimum => 10)
|
||||
expect(@session).not_to have_css("p a.doesnotexist", :minimum => 1)
|
||||
expect(@session).not_to have_css("h2.head", minimum: 6) # edge case
|
||||
expect(@session).not_to have_css("h2", minimum: 8)
|
||||
expect(@session).not_to have_css("p", minimum: 10)
|
||||
expect(@session).not_to have_css("p a.doesnotexist", minimum: 1)
|
||||
end
|
||||
|
||||
it "should coerce minimum to an integer" do
|
||||
expect(@session).to have_css("h2.head", :minimum => "5") # edge case
|
||||
expect(@session).to have_css("h2", :minimum => "3")
|
||||
expect(@session).to have_css("h2.head", minimum: "5") # edge case
|
||||
expect(@session).to have_css("h2", minimum: "3")
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is not contained" do
|
||||
expect(@session).to have_css("p a", :text => "Redirect", :count => 1)
|
||||
expect(@session).not_to have_css("p a", :text => "Doesnotexist")
|
||||
expect(@session).to have_css("p a", text: "Redirect", count: 1)
|
||||
expect(@session).not_to have_css("p a", text: "Doesnotexist")
|
||||
end
|
||||
|
||||
it "should discard all matches where the given regexp is not matched" do
|
||||
expect(@session).to have_css("p a", :text => /re[dab]i/i, :count => 1)
|
||||
expect(@session).not_to have_css("p a", :text => /Red$/)
|
||||
expect(@session).to have_css("p a", text: /re[dab]i/i, count: 1)
|
||||
expect(@session).not_to have_css("p a", text: /Red$/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -137,7 +137,7 @@ Capybara::SpecHelper.spec '#has_no_css?' do
|
|||
end
|
||||
end
|
||||
|
||||
it "should wait for content to disappear", :requires => [:js] do
|
||||
it "should wait for content to disappear", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session).to have_no_css("p#change")
|
||||
|
@ -145,85 +145,85 @@ Capybara::SpecHelper.spec '#has_no_css?' do
|
|||
|
||||
context "with between" do
|
||||
it "should be false if the content occurs within the range given" do
|
||||
expect(@session).not_to have_no_css("p", :between => 1..4)
|
||||
expect(@session).not_to have_no_css("p a#foo", :between => 1..3)
|
||||
expect(@session).not_to have_no_css("p a.doesnotexist", :between => 0..2)
|
||||
expect(@session).not_to have_no_css("p", between: 1..4)
|
||||
expect(@session).not_to have_no_css("p a#foo", between: 1..3)
|
||||
expect(@session).not_to have_no_css("p a.doesnotexist", between: 0..2)
|
||||
end
|
||||
|
||||
it "should be true if the content occurs more or fewer times than range" do
|
||||
expect(@session).to have_no_css("p", :between => 6..11 )
|
||||
expect(@session).to have_no_css("p a#foo", :between => 4..7)
|
||||
expect(@session).to have_no_css("p a.doesnotexist", :between => 3..8)
|
||||
expect(@session).to have_no_css("p", between: 6..11 )
|
||||
expect(@session).to have_no_css("p a#foo", between: 4..7)
|
||||
expect(@session).to have_no_css("p a.doesnotexist", between: 3..8)
|
||||
end
|
||||
end
|
||||
|
||||
context "with count" do
|
||||
it "should be false if the content is on the page the given number of times" do
|
||||
expect(@session).not_to have_no_css("p", :count => 3)
|
||||
expect(@session).not_to have_no_css("p a#foo", :count => 1)
|
||||
expect(@session).not_to have_no_css("p a.doesnotexist", :count => 0)
|
||||
expect(@session).not_to have_no_css("p", count: 3)
|
||||
expect(@session).not_to have_no_css("p a#foo", count: 1)
|
||||
expect(@session).not_to have_no_css("p a.doesnotexist", count: 0)
|
||||
end
|
||||
|
||||
it "should be true if the content is on the page the given number of times" do
|
||||
expect(@session).to have_no_css("p", :count => 6)
|
||||
expect(@session).to have_no_css("p a#foo", :count => 2)
|
||||
expect(@session).to have_no_css("p a.doesnotexist", :count => 1)
|
||||
expect(@session).to have_no_css("p", count: 6)
|
||||
expect(@session).to have_no_css("p a#foo", count: 2)
|
||||
expect(@session).to have_no_css("p a.doesnotexist", count: 1)
|
||||
end
|
||||
|
||||
it "should coerce count to an integer" do
|
||||
expect(@session).not_to have_no_css("p", :count => "3")
|
||||
expect(@session).not_to have_no_css("p a#foo", :count => "1")
|
||||
expect(@session).not_to have_no_css("p", count: "3")
|
||||
expect(@session).not_to have_no_css("p a#foo", count: "1")
|
||||
end
|
||||
end
|
||||
|
||||
context "with maximum" do
|
||||
it "should be false when content occurs same or fewer times than given" do
|
||||
expect(@session).not_to have_no_css("h2.head", :maximum => 5) # edge case
|
||||
expect(@session).not_to have_no_css("h2", :maximum => 10)
|
||||
expect(@session).not_to have_no_css("p a.doesnotexist", :maximum => 0)
|
||||
expect(@session).not_to have_no_css("h2.head", maximum: 5) # edge case
|
||||
expect(@session).not_to have_no_css("h2", maximum: 10)
|
||||
expect(@session).not_to have_no_css("p a.doesnotexist", maximum: 0)
|
||||
end
|
||||
|
||||
it "should be true when content occurs more times than given" do
|
||||
expect(@session).to have_no_css("h2.head", :maximum => 4) # edge case
|
||||
expect(@session).to have_no_css("h2", :maximum => 3)
|
||||
expect(@session).to have_no_css("p", :maximum => 1)
|
||||
expect(@session).to have_no_css("h2.head", maximum: 4) # edge case
|
||||
expect(@session).to have_no_css("h2", maximum: 3)
|
||||
expect(@session).to have_no_css("p", maximum: 1)
|
||||
end
|
||||
|
||||
it "should coerce maximum to an integer" do
|
||||
expect(@session).not_to have_no_css("h2.head", :maximum => "5") # edge case
|
||||
expect(@session).not_to have_no_css("h2", :maximum => "10")
|
||||
expect(@session).not_to have_no_css("h2.head", maximum: "5") # edge case
|
||||
expect(@session).not_to have_no_css("h2", maximum: "10")
|
||||
end
|
||||
end
|
||||
|
||||
context "with minimum" do
|
||||
it "should be false when content occurs same or more times than given" do
|
||||
expect(@session).not_to have_no_css("h2.head", :minimum => 5) # edge case
|
||||
expect(@session).not_to have_no_css("h2", :minimum => 3)
|
||||
expect(@session).not_to have_no_css("p a.doesnotexist", :minimum => 0)
|
||||
expect(@session).not_to have_no_css("h2.head", minimum: 5) # edge case
|
||||
expect(@session).not_to have_no_css("h2", minimum: 3)
|
||||
expect(@session).not_to have_no_css("p a.doesnotexist", minimum: 0)
|
||||
end
|
||||
|
||||
it "should be true when content occurs fewer times than given" do
|
||||
expect(@session).to have_no_css("h2.head", :minimum => 6) # edge case
|
||||
expect(@session).to have_no_css("h2", :minimum => 8)
|
||||
expect(@session).to have_no_css("p", :minimum => 15)
|
||||
expect(@session).to have_no_css("p a.doesnotexist", :minimum => 1)
|
||||
expect(@session).to have_no_css("h2.head", minimum: 6) # edge case
|
||||
expect(@session).to have_no_css("h2", minimum: 8)
|
||||
expect(@session).to have_no_css("p", minimum: 15)
|
||||
expect(@session).to have_no_css("p a.doesnotexist", minimum: 1)
|
||||
end
|
||||
|
||||
it "should coerce minimum to an integer" do
|
||||
expect(@session).not_to have_no_css("h2.head", :minimum => "4") # edge case
|
||||
expect(@session).not_to have_no_css("h2", :minimum => "3")
|
||||
expect(@session).not_to have_no_css("h2.head", minimum: "4") # edge case
|
||||
expect(@session).not_to have_no_css("h2", minimum: "3")
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is not contained" do
|
||||
expect(@session).not_to have_no_css("p a", :text => "Redirect", :count => 1)
|
||||
expect(@session).to have_no_css("p a", :text => "Doesnotexist")
|
||||
expect(@session).not_to have_no_css("p a", text: "Redirect", count: 1)
|
||||
expect(@session).to have_no_css("p a", text: "Doesnotexist")
|
||||
end
|
||||
|
||||
it "should discard all matches where the given regexp is not matched" do
|
||||
expect(@session).not_to have_no_css("p a", :text => /re[dab]i/i, :count => 1)
|
||||
expect(@session).to have_no_css("p a", :text => /Red$/)
|
||||
expect(@session).not_to have_no_css("p a", text: /re[dab]i/i, count: 1)
|
||||
expect(@session).to have_no_css("p a", text: /Red$/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ Capybara::SpecHelper.spec '#has_current_path?' do
|
|||
expect(@session).to have_current_path("/with_html?options%5B%5D=things")
|
||||
end
|
||||
|
||||
it "should wait for current_path", :requires => [:js] do
|
||||
it "should wait for current_path", requires: [:js] do
|
||||
@session.click_link("Change page")
|
||||
expect(@session).to have_current_path("/with_html")
|
||||
end
|
||||
|
@ -68,7 +68,7 @@ Capybara::SpecHelper.spec '#has_no_current_path?' do
|
|||
expect(@session).to have_no_current_path(/monkey/)
|
||||
end
|
||||
|
||||
it "should wait for current_path to disappear", :requires => [:js] do
|
||||
it "should wait for current_path to disappear", requires: [:js] do
|
||||
@session.click_link("Change page")
|
||||
expect(@session).to have_no_current_path('/with_js')
|
||||
end
|
||||
|
|
|
@ -15,50 +15,50 @@ Capybara::SpecHelper.spec '#has_field' do
|
|||
|
||||
context 'with value' do
|
||||
it "should be true if a field with the given value is on the page" do
|
||||
expect(@session).to have_field('First Name', :with => 'John')
|
||||
expect(@session).to have_field('First Name', :with => /^Joh/)
|
||||
expect(@session).to have_field('Phone', :with => '+1 555 7021')
|
||||
expect(@session).to have_field('Street', :with => 'Sesame street 66')
|
||||
expect(@session).to have_field('Description', :with => 'Descriptive text goes here')
|
||||
expect(@session).to have_field('First Name', with: 'John')
|
||||
expect(@session).to have_field('First Name', with: /^Joh/)
|
||||
expect(@session).to have_field('Phone', with: '+1 555 7021')
|
||||
expect(@session).to have_field('Street', with: 'Sesame street 66')
|
||||
expect(@session).to have_field('Description', with: 'Descriptive text goes here')
|
||||
end
|
||||
|
||||
it "should be false if the given field is not on the page" do
|
||||
expect(@session).not_to have_field('First Name', :with => 'Peter')
|
||||
expect(@session).not_to have_field('First Name', :with => /eter$/)
|
||||
expect(@session).not_to have_field('Wrong Name', :with => 'John')
|
||||
expect(@session).not_to have_field('Description', :with => 'Monkey')
|
||||
expect(@session).not_to have_field('First Name', with: 'Peter')
|
||||
expect(@session).not_to have_field('First Name', with: /eter$/)
|
||||
expect(@session).not_to have_field('Wrong Name', with: 'John')
|
||||
expect(@session).not_to have_field('Description', with: 'Monkey')
|
||||
end
|
||||
|
||||
it "should be true after the field has been filled in with the given value" do
|
||||
@session.fill_in('First Name', :with => 'Jonas')
|
||||
expect(@session).to have_field('First Name', :with => 'Jonas')
|
||||
expect(@session).to have_field('First Name', :with => /ona/)
|
||||
@session.fill_in('First Name', with: 'Jonas')
|
||||
expect(@session).to have_field('First Name', with: 'Jonas')
|
||||
expect(@session).to have_field('First Name', with: /ona/)
|
||||
end
|
||||
|
||||
it "should be false after the field has been filled in with a different value" do
|
||||
@session.fill_in('First Name', :with => 'Jonas')
|
||||
expect(@session).not_to have_field('First Name', :with => 'John')
|
||||
expect(@session).not_to have_field('First Name', :with => /John|Paul|George|Ringo/)
|
||||
@session.fill_in('First Name', with: 'Jonas')
|
||||
expect(@session).not_to have_field('First Name', with: 'John')
|
||||
expect(@session).not_to have_field('First Name', with: /John|Paul|George|Ringo/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with type' 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')
|
||||
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')
|
||||
end
|
||||
|
||||
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')
|
||||
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
|
||||
|
||||
|
@ -88,44 +88,44 @@ Capybara::SpecHelper.spec '#has_no_field' do
|
|||
|
||||
context 'with value' do
|
||||
it "should be false if a field with the given value is on the page" do
|
||||
expect(@session).not_to have_no_field('First Name', :with => 'John')
|
||||
expect(@session).not_to have_no_field('Phone', :with => '+1 555 7021')
|
||||
expect(@session).not_to have_no_field('Street', :with => 'Sesame street 66')
|
||||
expect(@session).not_to have_no_field('Description', :with => 'Descriptive text goes here')
|
||||
expect(@session).not_to have_no_field('First Name', with: 'John')
|
||||
expect(@session).not_to have_no_field('Phone', with: '+1 555 7021')
|
||||
expect(@session).not_to have_no_field('Street', with: 'Sesame street 66')
|
||||
expect(@session).not_to have_no_field('Description', with: 'Descriptive text goes here')
|
||||
end
|
||||
|
||||
it "should be true if the given field is not on the page" do
|
||||
expect(@session).to have_no_field('First Name', :with => 'Peter')
|
||||
expect(@session).to have_no_field('Wrong Name', :with => 'John')
|
||||
expect(@session).to have_no_field('Description', :with => 'Monkey')
|
||||
expect(@session).to have_no_field('First Name', with: 'Peter')
|
||||
expect(@session).to have_no_field('Wrong Name', with: 'John')
|
||||
expect(@session).to have_no_field('Description', with: 'Monkey')
|
||||
end
|
||||
|
||||
it "should be false after the field has been filled in with the given value" do
|
||||
@session.fill_in('First Name', :with => 'Jonas')
|
||||
expect(@session).not_to have_no_field('First Name', :with => 'Jonas')
|
||||
@session.fill_in('First Name', with: 'Jonas')
|
||||
expect(@session).not_to have_no_field('First Name', with: 'Jonas')
|
||||
end
|
||||
|
||||
it "should be true after the field has been filled in with a different value" do
|
||||
@session.fill_in('First Name', :with => 'Jonas')
|
||||
expect(@session).to have_no_field('First Name', :with => 'John')
|
||||
@session.fill_in('First Name', with: 'Jonas')
|
||||
expect(@session).to 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
|
||||
expect(@session).not_to have_no_field('First Name', :type => 'text')
|
||||
expect(@session).not_to have_no_field('Html5 Email', :type => 'email')
|
||||
expect(@session).not_to have_no_field('Html5 Tel', :type => 'tel')
|
||||
expect(@session).not_to have_no_field('Description', :type => 'textarea')
|
||||
expect(@session).not_to have_no_field('Languages', :type => 'select')
|
||||
expect(@session).not_to have_no_field('First Name', type: 'text')
|
||||
expect(@session).not_to have_no_field('Html5 Email', type: 'email')
|
||||
expect(@session).not_to have_no_field('Html5 Tel', type: 'tel')
|
||||
expect(@session).not_to have_no_field('Description', type: 'textarea')
|
||||
expect(@session).not_to have_no_field('Languages', type: 'select')
|
||||
end
|
||||
|
||||
it "should be true if the given field is not on the page" do
|
||||
expect(@session).to have_no_field('First Name', :type => 'textarea')
|
||||
expect(@session).to have_no_field('Html5 Email', :type => 'tel')
|
||||
expect(@session).to have_no_field('Description', :type => '')
|
||||
expect(@session).to have_no_field('Description', :type => 'email')
|
||||
expect(@session).to have_no_field('Languages', :type => 'textarea')
|
||||
expect(@session).to have_no_field('First Name', type: 'textarea')
|
||||
expect(@session).to have_no_field('Html5 Email', type: 'tel')
|
||||
expect(@session).to have_no_field('Description', type: '')
|
||||
expect(@session).to have_no_field('Description', type: 'email')
|
||||
expect(@session).to have_no_field('Languages', type: 'textarea')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -138,8 +138,8 @@ Capybara::SpecHelper.spec '#has_checked_field?' do
|
|||
expect(@session).to have_checked_field('Hamster')
|
||||
end
|
||||
|
||||
it "should be true for disabled checkboxes if :disabled => true" do
|
||||
expect(@session).to have_checked_field('Disabled Checkbox', :disabled => true)
|
||||
it "should be true for disabled checkboxes if disabled: true" do
|
||||
expect(@session).to have_checked_field('Disabled Checkbox', disabled: true)
|
||||
end
|
||||
|
||||
it "should be false if an unchecked field is on the page" do
|
||||
|
@ -155,16 +155,16 @@ Capybara::SpecHelper.spec '#has_checked_field?' do
|
|||
expect(@session).not_to have_checked_field('Disabled Checkbox')
|
||||
end
|
||||
|
||||
it "should be false for disabled checkboxes if :disabled => false" do
|
||||
expect(@session).not_to have_checked_field('Disabled Checkbox', :disabled => false)
|
||||
it "should be false for disabled checkboxes if disabled: false" do
|
||||
expect(@session).not_to have_checked_field('Disabled Checkbox', disabled: false)
|
||||
end
|
||||
|
||||
it "should be true for disabled checkboxes if :disabled => :all" do
|
||||
expect(@session).to have_checked_field('Disabled Checkbox', :disabled => :all)
|
||||
it "should be true for disabled checkboxes if disabled: :all" do
|
||||
expect(@session).to have_checked_field('Disabled Checkbox', disabled: :all)
|
||||
end
|
||||
|
||||
it "should be true for enabled checkboxes if :disabled => :all" do
|
||||
expect(@session).to have_checked_field('gender_female', :disabled => :all)
|
||||
it "should be true for enabled checkboxes if disabled: :all" do
|
||||
expect(@session).to have_checked_field('gender_female', disabled: :all)
|
||||
end
|
||||
|
||||
it "should be true after an unchecked checkbox is checked" do
|
||||
|
@ -196,8 +196,8 @@ Capybara::SpecHelper.spec '#has_no_checked_field?' do
|
|||
expect(@session).not_to have_no_checked_field('Hamster')
|
||||
end
|
||||
|
||||
it "should be false for disabled checkboxes if :disabled => true" do
|
||||
expect(@session).not_to have_no_checked_field('Disabled Checkbox', :disabled => true)
|
||||
it "should be false for disabled checkboxes if disabled: true" do
|
||||
expect(@session).not_to have_no_checked_field('Disabled Checkbox', disabled: true)
|
||||
end
|
||||
|
||||
it "should be true if an unchecked field is on the page" do
|
||||
|
@ -213,8 +213,8 @@ Capybara::SpecHelper.spec '#has_no_checked_field?' do
|
|||
expect(@session).to have_no_checked_field('Disabled Checkbox')
|
||||
end
|
||||
|
||||
it "should be true for disabled checkboxes if :disabled => false" do
|
||||
expect(@session).to have_no_checked_field('Disabled Checkbox', :disabled => false)
|
||||
it "should be true for disabled checkboxes if disabled: false" do
|
||||
expect(@session).to have_no_checked_field('Disabled Checkbox', disabled: false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -231,8 +231,8 @@ Capybara::SpecHelper.spec '#has_unchecked_field?' do
|
|||
expect(@session).to have_unchecked_field('Male')
|
||||
end
|
||||
|
||||
it "should be true for disabled unchecked fields if :disabled => true" do
|
||||
expect(@session).to have_unchecked_field('Disabled Unchecked Checkbox', :disabled => true)
|
||||
it "should be true for disabled unchecked fields if disabled: true" do
|
||||
expect(@session).to have_unchecked_field('Disabled Unchecked Checkbox', disabled: true)
|
||||
end
|
||||
|
||||
it "should be false if no field is on the page" do
|
||||
|
@ -243,8 +243,8 @@ Capybara::SpecHelper.spec '#has_unchecked_field?' do
|
|||
expect(@session).not_to have_unchecked_field('Disabled Unchecked Checkbox')
|
||||
end
|
||||
|
||||
it "should be false for disabled unchecked fields if :disabled => false" do
|
||||
expect(@session).not_to have_unchecked_field('Disabled Unchecked Checkbox', :disabled => false)
|
||||
it "should be false for disabled unchecked fields if disabled: false" do
|
||||
expect(@session).not_to have_unchecked_field('Disabled Unchecked Checkbox', disabled: false)
|
||||
end
|
||||
|
||||
it "should be false after an unchecked checkbox is checked" do
|
||||
|
@ -286,8 +286,8 @@ Capybara::SpecHelper.spec '#has_no_unchecked_field?' do
|
|||
expect(@session).not_to have_no_unchecked_field('Male')
|
||||
end
|
||||
|
||||
it "should be false for disabled unchecked fields if :disabled => true" do
|
||||
expect(@session).not_to have_no_unchecked_field('Disabled Unchecked Checkbox', :disabled => true)
|
||||
it "should be false for disabled unchecked fields if disabled: true" do
|
||||
expect(@session).not_to have_no_unchecked_field('Disabled Unchecked Checkbox', disabled: true)
|
||||
end
|
||||
|
||||
it "should be true if no field is on the page" do
|
||||
|
@ -298,8 +298,8 @@ Capybara::SpecHelper.spec '#has_no_unchecked_field?' do
|
|||
expect(@session).to have_no_unchecked_field('Disabled Unchecked Checkbox')
|
||||
end
|
||||
|
||||
it "should be true for disabled unchecked fields if :disabled => false" do
|
||||
expect(@session).to have_no_unchecked_field('Disabled Unchecked Checkbox', :disabled => false)
|
||||
it "should be true for disabled unchecked fields if disabled: false" do
|
||||
expect(@session).to have_no_unchecked_field('Disabled Unchecked Checkbox', disabled: false)
|
||||
end
|
||||
|
||||
it "should support locator-less usage" do
|
||||
|
|
|
@ -7,15 +7,15 @@ Capybara::SpecHelper.spec '#has_link?' do
|
|||
it "should be true if the given link is on the page" do
|
||||
expect(@session).to have_link('foo')
|
||||
expect(@session).to have_link('awesome title')
|
||||
expect(@session).to have_link('A link', :href => '/with_simple_html')
|
||||
expect(@session).to have_link(:'A link', :href => :'/with_simple_html')
|
||||
expect(@session).to have_link('A link', :href => /\/with_simple_html/)
|
||||
expect(@session).to have_link('A link', href: '/with_simple_html')
|
||||
expect(@session).to have_link(:'A link', href: :'/with_simple_html')
|
||||
expect(@session).to have_link('A link', href: /\/with_simple_html/)
|
||||
end
|
||||
|
||||
it "should be false if the given link is not on the page" do
|
||||
expect(@session).not_to have_link('monkey')
|
||||
expect(@session).not_to have_link('A link', :href => '/non-existant-href')
|
||||
expect(@session).not_to have_link('A link', :href => /non-existant/)
|
||||
expect(@session).not_to have_link('A link', href: '/non-existant-href')
|
||||
expect(@session).not_to have_link('A link', href: /non-existant/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -27,12 +27,12 @@ Capybara::SpecHelper.spec '#has_no_link?' do
|
|||
it "should be false if the given link is on the page" do
|
||||
expect(@session).not_to have_no_link('foo')
|
||||
expect(@session).not_to have_no_link('awesome title')
|
||||
expect(@session).not_to have_no_link('A link', :href => '/with_simple_html')
|
||||
expect(@session).not_to have_no_link('A link', href: '/with_simple_html')
|
||||
end
|
||||
|
||||
it "should be true if the given link is not on the page" do
|
||||
expect(@session).to have_no_link('monkey')
|
||||
expect(@session).to have_no_link('A link', :href => '/non-existant-href')
|
||||
expect(@session).to have_no_link('A link', :href => /\/non-existant-href/)
|
||||
expect(@session).to have_no_link('A link', href: '/non-existant-href')
|
||||
expect(@session).to have_no_link('A link', href: /\/non-existant-href/)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,92 +15,92 @@ Capybara::SpecHelper.spec '#has_select?' do
|
|||
|
||||
context 'with selected value' do
|
||||
it "should be true if a field with the given value is on the page" do
|
||||
expect(@session).to have_select('form_locale', :selected => 'English')
|
||||
expect(@session).to have_select('Region', :selected => 'Norway')
|
||||
expect(@session).to have_select('Underwear', :selected => [
|
||||
expect(@session).to have_select('form_locale', selected: 'English')
|
||||
expect(@session).to have_select('Region', selected: 'Norway')
|
||||
expect(@session).to have_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
|
||||
])
|
||||
end
|
||||
|
||||
it "should be false if the given field is not on the page" do
|
||||
expect(@session).not_to have_select('Locale', :selected => 'Swedish')
|
||||
expect(@session).not_to have_select('Does not exist', :selected => 'John')
|
||||
expect(@session).not_to have_select('City', :selected => 'Not there')
|
||||
expect(@session).not_to have_select('Underwear', :selected => [
|
||||
expect(@session).not_to have_select('Locale', selected: 'Swedish')
|
||||
expect(@session).not_to have_select('Does not exist', selected: 'John')
|
||||
expect(@session).not_to have_select('City', selected: 'Not there')
|
||||
expect(@session).not_to have_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns', 'Nonexistant'
|
||||
])
|
||||
expect(@session).not_to have_select('Underwear', :selected => [
|
||||
expect(@session).not_to have_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
|
||||
])
|
||||
expect(@session).not_to have_select('Underwear', :selected => [
|
||||
expect(@session).not_to have_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs','Commando', "Frenchman's Pantalons"
|
||||
])
|
||||
end
|
||||
|
||||
it "should be true after the given value is selected" do
|
||||
@session.select('Swedish', :from => 'Locale')
|
||||
expect(@session).to have_select('Locale', :selected => 'Swedish')
|
||||
@session.select('Swedish', from: 'Locale')
|
||||
expect(@session).to have_select('Locale', selected: 'Swedish')
|
||||
end
|
||||
|
||||
it "should be false after a different value is selected" do
|
||||
@session.select('Swedish', :from => 'Locale')
|
||||
expect(@session).not_to have_select('Locale', :selected => 'English')
|
||||
@session.select('Swedish', from: 'Locale')
|
||||
expect(@session).not_to have_select('Locale', selected: 'English')
|
||||
end
|
||||
|
||||
it "should be true after the given values are selected" do
|
||||
@session.select('Boxers', :from => 'Underwear')
|
||||
expect(@session).to have_select('Underwear', :selected => [
|
||||
@session.select('Boxers', from: 'Underwear')
|
||||
expect(@session).to have_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
|
||||
])
|
||||
end
|
||||
|
||||
it "should be false after one of the values is unselected" do
|
||||
@session.unselect('Briefs', :from => 'Underwear')
|
||||
expect(@session).not_to have_select('Underwear', :selected => [
|
||||
@session.unselect('Briefs', from: 'Underwear')
|
||||
expect(@session).not_to have_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
|
||||
])
|
||||
end
|
||||
|
||||
it "should be true even when the selected option invisible, regardless of the select's visibility" do
|
||||
expect(@session).to have_select('Icecream', :visible => false, :selected => 'Chocolate')
|
||||
expect(@session).to have_select('Sorbet', :selected => 'Vanilla')
|
||||
expect(@session).to have_select('Icecream', visible: false, selected: 'Chocolate')
|
||||
expect(@session).to have_select('Sorbet', selected: 'Vanilla')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with exact options' do
|
||||
it "should be true if a field with the given options is on the page" do
|
||||
expect(@session).to have_select('Region', :options => ['Norway', 'Sweden', 'Finland'])
|
||||
expect(@session).to have_select('Tendency', :options => [])
|
||||
expect(@session).to have_select('Region', options: ['Norway', 'Sweden', 'Finland'])
|
||||
expect(@session).to have_select('Tendency', options: [])
|
||||
end
|
||||
|
||||
it "should be false if the given field is not on the page" do
|
||||
expect(@session).not_to have_select('Locale', :options => ['Swedish'])
|
||||
expect(@session).not_to have_select('Does not exist', :options => ['John'])
|
||||
expect(@session).not_to have_select('City', :options => ['London', 'Made up city'])
|
||||
expect(@session).not_to have_select('Region', :options => ['Norway', 'Sweden'])
|
||||
expect(@session).not_to have_select('Region', :options => ['Norway', 'Norway', 'Norway'])
|
||||
expect(@session).not_to have_select('Locale', options: ['Swedish'])
|
||||
expect(@session).not_to have_select('Does not exist', options: ['John'])
|
||||
expect(@session).not_to have_select('City', options: ['London', 'Made up city'])
|
||||
expect(@session).not_to have_select('Region', options: ['Norway', 'Sweden'])
|
||||
expect(@session).not_to have_select('Region', options: ['Norway', 'Norway', 'Norway'])
|
||||
end
|
||||
|
||||
it" should be true even when the options are invisible, if the select itself is invisible" do
|
||||
expect(@session).to have_select("Icecream", :visible => false, :options => ['Chocolate', 'Vanilla', 'Strawberry'])
|
||||
expect(@session).to have_select("Icecream", visible: false, options: ['Chocolate', 'Vanilla', 'Strawberry'])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'with partial options' do
|
||||
it "should be true if a field with the given partial options is on the page" do
|
||||
expect(@session).to have_select('Region', :with_options => ['Norway', 'Sweden'])
|
||||
expect(@session).to have_select('City', :with_options => ['London'])
|
||||
expect(@session).to have_select('Region', with_options: ['Norway', 'Sweden'])
|
||||
expect(@session).to have_select('City', with_options: ['London'])
|
||||
end
|
||||
|
||||
it "should be false if a field with the given partial options is not on the page" do
|
||||
expect(@session).not_to have_select('Locale', :with_options => ['Uruguayan'])
|
||||
expect(@session).not_to have_select('Does not exist', :with_options => ['John'])
|
||||
expect(@session).not_to have_select('Region', :with_options => ['Norway', 'Sweden', 'Finland', 'Latvia'])
|
||||
expect(@session).not_to have_select('Locale', with_options: ['Uruguayan'])
|
||||
expect(@session).not_to have_select('Does not exist', with_options: ['John'])
|
||||
expect(@session).not_to have_select('Region', with_options: ['Norway', 'Sweden', 'Finland', 'Latvia'])
|
||||
end
|
||||
|
||||
it" should be true even when the options are invisible, if the select itself is invisible" do
|
||||
expect(@session).to have_select("Icecream", :visible => false, :with_options => ['Vanilla', 'Strawberry'])
|
||||
expect(@session).to have_select("Icecream", visible: false, with_options: ['Vanilla', 'Strawberry'])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -122,8 +122,8 @@ Capybara::SpecHelper.spec '#has_select?' do
|
|||
end
|
||||
|
||||
it "should support locator-less usage" do
|
||||
expect(@session.has_select?(:with_options => ['Norway', 'Sweden'])).to eq true
|
||||
expect(@session).to have_select(:with_options => ['London'] )
|
||||
expect(@session.has_select?(with_options: ['Norway', 'Sweden'])).to eq true
|
||||
expect(@session).to have_select(with_options: ['London'] )
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -142,48 +142,48 @@ Capybara::SpecHelper.spec '#has_no_select?' do
|
|||
|
||||
context 'with selected value' do
|
||||
it "should be false if a field with the given value is on the page" do
|
||||
expect(@session).not_to have_no_select('form_locale', :selected => 'English')
|
||||
expect(@session).not_to have_no_select('Region', :selected => 'Norway')
|
||||
expect(@session).not_to have_no_select('Underwear', :selected => [
|
||||
expect(@session).not_to have_no_select('form_locale', selected: 'English')
|
||||
expect(@session).not_to have_no_select('Region', selected: 'Norway')
|
||||
expect(@session).not_to have_no_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
|
||||
])
|
||||
end
|
||||
|
||||
it "should be true if the given field is not on the page" do
|
||||
expect(@session).to have_no_select('Locale', :selected => 'Swedish')
|
||||
expect(@session).to have_no_select('Does not exist', :selected => 'John')
|
||||
expect(@session).to have_no_select('City', :selected => 'Not there')
|
||||
expect(@session).to have_no_select('Underwear', :selected => [
|
||||
expect(@session).to have_no_select('Locale', selected: 'Swedish')
|
||||
expect(@session).to have_no_select('Does not exist', selected: 'John')
|
||||
expect(@session).to have_no_select('City', selected: 'Not there')
|
||||
expect(@session).to have_no_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns', 'Nonexistant'
|
||||
])
|
||||
expect(@session).to have_no_select('Underwear', :selected => [
|
||||
expect(@session).to have_no_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
|
||||
])
|
||||
expect(@session).to have_no_select('Underwear', :selected => [
|
||||
expect(@session).to have_no_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs','Commando', "Frenchman's Pantalons"
|
||||
])
|
||||
end
|
||||
|
||||
it "should be false after the given value is selected" do
|
||||
@session.select('Swedish', :from => 'Locale')
|
||||
expect(@session).not_to have_no_select('Locale', :selected => 'Swedish')
|
||||
@session.select('Swedish', from: 'Locale')
|
||||
expect(@session).not_to have_no_select('Locale', selected: 'Swedish')
|
||||
end
|
||||
|
||||
it "should be true after a different value is selected" do
|
||||
@session.select('Swedish', :from => 'Locale')
|
||||
expect(@session).to have_no_select('Locale', :selected => 'English')
|
||||
@session.select('Swedish', from: 'Locale')
|
||||
expect(@session).to have_no_select('Locale', selected: 'English')
|
||||
end
|
||||
|
||||
it "should be false after the given values are selected" do
|
||||
@session.select('Boxers', :from => 'Underwear')
|
||||
expect(@session).not_to have_no_select('Underwear', :selected => [
|
||||
@session.select('Boxers', from: 'Underwear')
|
||||
expect(@session).not_to have_no_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Boxers', 'Commando', "Frenchman's Pantalons", 'Long Johns'
|
||||
])
|
||||
end
|
||||
|
||||
it "should be true after one of the values is unselected" do
|
||||
@session.unselect('Briefs', :from => 'Underwear')
|
||||
expect(@session).to have_no_select('Underwear', :selected => [
|
||||
@session.unselect('Briefs', from: 'Underwear')
|
||||
expect(@session).to have_no_select('Underwear', selected: [
|
||||
'Boxerbriefs', 'Briefs', 'Commando', "Frenchman's Pantalons", 'Long Johns'
|
||||
])
|
||||
end
|
||||
|
@ -191,33 +191,33 @@ Capybara::SpecHelper.spec '#has_no_select?' do
|
|||
|
||||
context 'with exact options' do
|
||||
it "should be false if a field with the given options is on the page" do
|
||||
expect(@session).not_to have_no_select('Region', :options => ['Norway', 'Sweden', 'Finland'])
|
||||
expect(@session).not_to have_no_select('Region', options: ['Norway', 'Sweden', 'Finland'])
|
||||
end
|
||||
|
||||
it "should be true if the given field is not on the page" do
|
||||
expect(@session).to have_no_select('Locale', :options => ['Swedish'])
|
||||
expect(@session).to have_no_select('Does not exist', :options => ['John'])
|
||||
expect(@session).to have_no_select('City', :options => ['London', 'Made up city'])
|
||||
expect(@session).to have_no_select('Region', :options => ['Norway', 'Sweden'])
|
||||
expect(@session).to have_no_select('Region', :options => ['Norway', 'Norway', 'Norway'])
|
||||
expect(@session).to have_no_select('Locale', options: ['Swedish'])
|
||||
expect(@session).to have_no_select('Does not exist', options: ['John'])
|
||||
expect(@session).to have_no_select('City', options: ['London', 'Made up city'])
|
||||
expect(@session).to have_no_select('Region', options: ['Norway', 'Sweden'])
|
||||
expect(@session).to have_no_select('Region', options: ['Norway', 'Norway', 'Norway'])
|
||||
end
|
||||
end
|
||||
|
||||
context 'with partial options' do
|
||||
it "should be false if a field with the given partial options is on the page" do
|
||||
expect(@session).not_to have_no_select('Region', :with_options => ['Norway', 'Sweden'])
|
||||
expect(@session).not_to have_no_select('City', :with_options => ['London'])
|
||||
expect(@session).not_to have_no_select('Region', with_options: ['Norway', 'Sweden'])
|
||||
expect(@session).not_to have_no_select('City', with_options: ['London'])
|
||||
end
|
||||
|
||||
it "should be true if a field with the given partial options is not on the page" do
|
||||
expect(@session).to have_no_select('Locale', :with_options => ['Uruguayan'])
|
||||
expect(@session).to have_no_select('Does not exist', :with_options => ['John'])
|
||||
expect(@session).to have_no_select('Region', :with_options => ['Norway', 'Sweden', 'Finland', 'Latvia'])
|
||||
expect(@session).to have_no_select('Locale', with_options: ['Uruguayan'])
|
||||
expect(@session).to have_no_select('Does not exist', with_options: ['John'])
|
||||
expect(@session).to have_no_select('Region', with_options: ['Norway', 'Sweden', 'Finland', 'Latvia'])
|
||||
end
|
||||
end
|
||||
|
||||
it "should support locator-less usage" do
|
||||
expect(@session.has_no_select?(:with_options => ['Norway', 'Sweden', 'Finland', 'Latvia'])).to eq true
|
||||
expect(@session).to have_no_select(:with_options => ['New London'] )
|
||||
expect(@session.has_no_select?(with_options: ['Norway', 'Sweden', 'Finland', 'Latvia'])).to eq true
|
||||
expect(@session).to have_no_select(with_options: ['New London'] )
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,41 +31,41 @@ Capybara::SpecHelper.spec '#has_selector?' do
|
|||
|
||||
context "with count" do
|
||||
it "should be true if the content is on the page the given number of times" do
|
||||
expect(@session).to have_selector("//p", :count => 3)
|
||||
expect(@session).to have_selector("//p//a[@id='foo']", :count => 1)
|
||||
expect(@session).to have_selector("//p[contains(.,'est')]", :count => 1)
|
||||
expect(@session).to have_selector("//p", count: 3)
|
||||
expect(@session).to have_selector("//p//a[@id='foo']", count: 1)
|
||||
expect(@session).to have_selector("//p[contains(.,'est')]", count: 1)
|
||||
end
|
||||
|
||||
it "should be false if the content is on the page the given number of times" do
|
||||
expect(@session).not_to have_selector("//p", :count => 6)
|
||||
expect(@session).not_to have_selector("//p//a[@id='foo']", :count => 2)
|
||||
expect(@session).not_to have_selector("//p[contains(.,'est')]", :count => 5)
|
||||
expect(@session).not_to have_selector("//p", count: 6)
|
||||
expect(@session).not_to have_selector("//p//a[@id='foo']", count: 2)
|
||||
expect(@session).not_to have_selector("//p[contains(.,'est')]", count: 5)
|
||||
end
|
||||
|
||||
it "should be false if the content isn't on the page at all" do
|
||||
expect(@session).not_to have_selector("//abbr", :count => 2)
|
||||
expect(@session).not_to have_selector("//p//a[@id='doesnotexist']", :count => 1)
|
||||
expect(@session).not_to have_selector("//abbr", count: 2)
|
||||
expect(@session).not_to have_selector("//p//a[@id='doesnotexist']", count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is not contained" do
|
||||
expect(@session).to have_selector("//p//a", :text => "Redirect", :count => 1)
|
||||
expect(@session).not_to have_selector("//p", :text => "Doesnotexist")
|
||||
expect(@session).to have_selector("//p//a", text: "Redirect", count: 1)
|
||||
expect(@session).not_to have_selector("//p", text: "Doesnotexist")
|
||||
end
|
||||
|
||||
it "should respect visibility setting" do
|
||||
expect(@session).to have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => false)
|
||||
expect(@session).not_to have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => true)
|
||||
expect(@session).to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: false)
|
||||
expect(@session).not_to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: true)
|
||||
Capybara.ignore_hidden_elements = false
|
||||
expect(@session).to have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => false)
|
||||
expect(@session).to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: false)
|
||||
Capybara.visible_text_only = true
|
||||
expect(@session).not_to have_selector(:id, "hidden-text", :text => "Some of this text is hidden!", :visible => true)
|
||||
expect(@session).not_to have_selector(:id, "hidden-text", text: "Some of this text is hidden!", visible: true)
|
||||
end
|
||||
|
||||
it "should discard all matches where the given regexp is not matched" do
|
||||
expect(@session).to have_selector("//p//a", :text => /re[dab]i/i, :count => 1)
|
||||
expect(@session).not_to have_selector("//p//a", :text => /Red$/)
|
||||
expect(@session).to have_selector("//p//a", text: /re[dab]i/i, count: 1)
|
||||
expect(@session).not_to have_selector("//p//a", text: /Red$/)
|
||||
end
|
||||
|
||||
it "should warn when extra parameters passed" do
|
||||
|
@ -107,32 +107,32 @@ Capybara::SpecHelper.spec '#has_no_selector?' do
|
|||
|
||||
context "with count" do
|
||||
it "should be false if the content is on the page the given number of times" do
|
||||
expect(@session).not_to have_no_selector("//p", :count => 3)
|
||||
expect(@session).not_to have_no_selector("//p//a[@id='foo']", :count => 1)
|
||||
expect(@session).not_to have_no_selector("//p[contains(.,'est')]", :count => 1)
|
||||
expect(@session).not_to have_no_selector("//p", count: 3)
|
||||
expect(@session).not_to have_no_selector("//p//a[@id='foo']", count: 1)
|
||||
expect(@session).not_to have_no_selector("//p[contains(.,'est')]", count: 1)
|
||||
end
|
||||
|
||||
it "should be true if the content is on the page the wrong number of times" do
|
||||
expect(@session).to have_no_selector("//p", :count => 6)
|
||||
expect(@session).to have_no_selector("//p//a[@id='foo']", :count => 2)
|
||||
expect(@session).to have_no_selector("//p[contains(.,'est')]", :count => 5)
|
||||
expect(@session).to have_no_selector("//p", count: 6)
|
||||
expect(@session).to have_no_selector("//p//a[@id='foo']", count: 2)
|
||||
expect(@session).to have_no_selector("//p[contains(.,'est')]", count: 5)
|
||||
end
|
||||
|
||||
it "should be true if the content isn't on the page at all" do
|
||||
expect(@session).to have_no_selector("//abbr", :count => 2)
|
||||
expect(@session).to have_no_selector("//p//a[@id='doesnotexist']", :count => 1)
|
||||
expect(@session).to have_no_selector("//abbr", count: 2)
|
||||
expect(@session).to have_no_selector("//p//a[@id='doesnotexist']", count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is contained" do
|
||||
expect(@session).not_to have_no_selector("//p//a", :text => "Redirect", :count => 1)
|
||||
expect(@session).to have_no_selector("//p", :text => "Doesnotexist")
|
||||
expect(@session).not_to have_no_selector("//p//a", text: "Redirect", count: 1)
|
||||
expect(@session).to have_no_selector("//p", text: "Doesnotexist")
|
||||
end
|
||||
|
||||
it "should discard all matches where the given regexp is matched" do
|
||||
expect(@session).not_to have_no_selector("//p//a", :text => /re[dab]i/i, :count => 1)
|
||||
expect(@session).to have_no_selector("//p//a", :text => /Red$/)
|
||||
expect(@session).not_to have_no_selector("//p//a", text: /re[dab]i/i, count: 1)
|
||||
expect(@session).to have_no_selector("//p//a", text: /Red$/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -112,7 +112,7 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|||
expect(@session).to have_text(nil)
|
||||
end
|
||||
|
||||
it "should wait for text to appear", :requires => [:js] do
|
||||
it "should wait for text to appear", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session).to have_text("Has been clicked")
|
||||
|
@ -192,12 +192,12 @@ Capybara::SpecHelper.spec '#has_text?' do
|
|||
end
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
context "with wait", requires: [:js] do
|
||||
it "should find element if it appears before given wait duration" do
|
||||
Capybara.using_wait_time(0.1) do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session).to have_text('Has been clicked', :wait => 0.9)
|
||||
expect(@session).to have_text('Has been clicked', wait: 0.9)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -301,17 +301,17 @@ Capybara::SpecHelper.spec '#has_no_text?' do
|
|||
expect(@session).to have_no_text('.orem')
|
||||
end
|
||||
|
||||
it "should wait for text to disappear", :requires => [:js] do
|
||||
it "should wait for text to disappear", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session).to have_no_text("I changed it")
|
||||
end
|
||||
|
||||
context "with wait", :requires => [:js] do
|
||||
context "with wait", requires: [:js] do
|
||||
it "should not find element if it appears after given wait duration" do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session).to have_no_text('Has been clicked', :wait => 0.1)
|
||||
expect(@session).to have_no_text('Has been clicked', wait: 0.1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ Capybara::SpecHelper.spec '#has_title?' do
|
|||
expect(@session).not_to have_title(/monkey/)
|
||||
end
|
||||
|
||||
it "should wait for title", :requires => [:js] do
|
||||
it "should wait for title", requires: [:js] do
|
||||
@session.click_link("Change title")
|
||||
expect(@session).to have_title("changed title")
|
||||
end
|
||||
|
@ -37,7 +37,7 @@ Capybara::SpecHelper.spec '#has_no_title?' do
|
|||
expect(@session).to have_no_title(/monkey/)
|
||||
end
|
||||
|
||||
it "should wait for title to disappear", :requires => [:js] do
|
||||
it "should wait for title to disappear", requires: [:js] do
|
||||
@session.click_link("Change title")
|
||||
expect(@session).to have_no_title('with_js')
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ Capybara::SpecHelper.spec '#has_xpath?' do
|
|||
end
|
||||
end
|
||||
|
||||
it "should wait for content to appear", :requires => [:js] do
|
||||
it "should wait for content to appear", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session).to have_xpath("//input[@type='submit' and @value='New Here']")
|
||||
|
@ -36,29 +36,29 @@ Capybara::SpecHelper.spec '#has_xpath?' do
|
|||
|
||||
context "with count" do
|
||||
it "should be true if the content occurs the given number of times" do
|
||||
expect(@session).to have_xpath("//p", :count => 3)
|
||||
expect(@session).to have_xpath("//p//a[@id='foo']", :count => 1)
|
||||
expect(@session).to have_xpath("//p[contains(.,'est')]", :count => 1)
|
||||
expect(@session).to have_xpath("//p//a[@id='doesnotexist']", :count => 0)
|
||||
expect(@session).to have_xpath("//p", count: 3)
|
||||
expect(@session).to have_xpath("//p//a[@id='foo']", count: 1)
|
||||
expect(@session).to have_xpath("//p[contains(.,'est')]", count: 1)
|
||||
expect(@session).to have_xpath("//p//a[@id='doesnotexist']", count: 0)
|
||||
end
|
||||
|
||||
it "should be false if the content occurs a different number of times than the given" do
|
||||
expect(@session).not_to have_xpath("//p", :count => 6)
|
||||
expect(@session).not_to have_xpath("//p//a[@id='foo']", :count => 2)
|
||||
expect(@session).not_to have_xpath("//p[contains(.,'est')]", :count => 5)
|
||||
expect(@session).not_to have_xpath("//p//a[@id='doesnotexist']", :count => 1)
|
||||
expect(@session).not_to have_xpath("//p", count: 6)
|
||||
expect(@session).not_to have_xpath("//p//a[@id='foo']", count: 2)
|
||||
expect(@session).not_to have_xpath("//p[contains(.,'est')]", count: 5)
|
||||
expect(@session).not_to have_xpath("//p//a[@id='doesnotexist']", count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is not contained" do
|
||||
expect(@session).to have_xpath("//p//a", :text => "Redirect", :count => 1)
|
||||
expect(@session).not_to have_xpath("//p", :text => "Doesnotexist")
|
||||
expect(@session).to have_xpath("//p//a", text: "Redirect", count: 1)
|
||||
expect(@session).not_to have_xpath("//p", text: "Doesnotexist")
|
||||
end
|
||||
|
||||
it "should discard all matches where the given regexp is not matched" do
|
||||
expect(@session).to have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
|
||||
expect(@session).not_to have_xpath("//p//a", :text => /Red$/)
|
||||
expect(@session).to have_xpath("//p//a", text: /re[dab]i/i, count: 1)
|
||||
expect(@session).not_to have_xpath("//p//a", text: /Red$/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -92,7 +92,7 @@ Capybara::SpecHelper.spec '#has_no_xpath?' do
|
|||
end
|
||||
end
|
||||
|
||||
it "should wait for content to disappear", :requires => [:js] do
|
||||
it "should wait for content to disappear", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.click_link('Click me')
|
||||
expect(@session).to have_no_xpath("//p[@id='change']")
|
||||
|
@ -100,29 +100,29 @@ Capybara::SpecHelper.spec '#has_no_xpath?' do
|
|||
|
||||
context "with count" do
|
||||
it "should be false if the content occurs the given number of times" do
|
||||
expect(@session).not_to have_no_xpath("//p", :count => 3)
|
||||
expect(@session).not_to have_no_xpath("//p//a[@id='foo']", :count => 1)
|
||||
expect(@session).not_to have_no_xpath("//p[contains(.,'est')]", :count => 1)
|
||||
expect(@session).not_to have_no_xpath("//p//a[@id='doesnotexist']", :count => 0)
|
||||
expect(@session).not_to have_no_xpath("//p", count: 3)
|
||||
expect(@session).not_to have_no_xpath("//p//a[@id='foo']", count: 1)
|
||||
expect(@session).not_to have_no_xpath("//p[contains(.,'est')]", count: 1)
|
||||
expect(@session).not_to have_no_xpath("//p//a[@id='doesnotexist']", count: 0)
|
||||
end
|
||||
|
||||
it "should be true if the content occurs a different number of times than the given" do
|
||||
expect(@session).to have_no_xpath("//p", :count => 6)
|
||||
expect(@session).to have_no_xpath("//p//a[@id='foo']", :count => 2)
|
||||
expect(@session).to have_no_xpath("//p[contains(.,'est')]", :count => 5)
|
||||
expect(@session).to have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
|
||||
expect(@session).to have_no_xpath("//p", count: 6)
|
||||
expect(@session).to have_no_xpath("//p//a[@id='foo']", count: 2)
|
||||
expect(@session).to have_no_xpath("//p[contains(.,'est')]", count: 5)
|
||||
expect(@session).to have_no_xpath("//p//a[@id='doesnotexist']", count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
context "with text" do
|
||||
it "should discard all matches where the given string is contained" do
|
||||
expect(@session).not_to have_no_xpath("//p//a", :text => "Redirect", :count => 1)
|
||||
expect(@session).to have_no_xpath("//p", :text => "Doesnotexist")
|
||||
expect(@session).not_to have_no_xpath("//p//a", text: "Redirect", count: 1)
|
||||
expect(@session).to have_no_xpath("//p", text: "Doesnotexist")
|
||||
end
|
||||
|
||||
it "should discard all matches where the given regexp is matched" do
|
||||
expect(@session).not_to have_no_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
|
||||
expect(@session).to have_no_xpath("//p//a", :text => /Red$/)
|
||||
expect(@session).not_to have_no_xpath("//p//a", text: /re[dab]i/i, count: 1)
|
||||
expect(@session).to have_no_xpath("//p//a", text: /Red$/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#response_headers' do
|
||||
it "should return response headers", :requires => [:response_headers] do
|
||||
it "should return response headers", requires: [:response_headers] do
|
||||
@session.visit('/with_simple_html')
|
||||
expect(@session.response_headers['Content-Type']).to match %r(text/html)
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ Capybara::SpecHelper.spec '#html' do
|
|||
expect(@session.html).to include('Hello world!')
|
||||
end
|
||||
|
||||
it "should return the current state of the page", :requires => [:js] do
|
||||
it "should return the current state of the page", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
expect(@session.html).to include('I changed it')
|
||||
expect(@session.html).not_to include('This is text')
|
||||
|
@ -18,7 +18,7 @@ Capybara::SpecHelper.spec '#source' do
|
|||
expect(@session.source).to include('Hello world!')
|
||||
end
|
||||
|
||||
it "should return the current state of the page", :requires => [:js] do
|
||||
it "should return the current state of the page", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
expect(@session.source).to include('I changed it')
|
||||
expect(@session.source).not_to include('This is text')
|
||||
|
@ -31,7 +31,7 @@ Capybara::SpecHelper.spec '#body' do
|
|||
expect(@session.body).to include('Hello world!')
|
||||
end
|
||||
|
||||
it "should return the current state of the page", :requires => [:js] do
|
||||
it "should return the current state of the page", requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
expect(@session.body).to include('I changed it')
|
||||
expect(@session.body).not_to include('This is text')
|
||||
|
|
|
@ -10,7 +10,7 @@ Capybara::SpecHelper.spec "node" do
|
|||
@form = @session.find(:css, '#get-form')
|
||||
expect(@form).to have_field('Middle Name')
|
||||
expect(@form).to have_no_field('Languages')
|
||||
@form.fill_in('Middle Name', :with => 'Monkey')
|
||||
@form.fill_in('Middle Name', with: 'Monkey')
|
||||
@form.click_button('med')
|
||||
expect(extract_results(@session)['middle_name']).to eq('Monkey')
|
||||
end
|
||||
|
@ -96,7 +96,7 @@ Capybara::SpecHelper.spec "node" do
|
|||
expect(@session.first('//input').value).to eq('gorilla')
|
||||
end
|
||||
|
||||
it "should fill the field even if the caret was not at the end", :requires => [:js] do
|
||||
it "should fill the field even if the caret was not at the end", requires: [:js] do
|
||||
@session.execute_script("var el = document.getElementById('test_field'); el.focus(); el.setSelectionRange(0, 0);")
|
||||
@session.first('//input').set('')
|
||||
expect(@session.first('//input').value).to eq('')
|
||||
|
@ -122,19 +122,19 @@ Capybara::SpecHelper.spec "node" do
|
|||
expect(@session.first('//textarea[@readonly]').set('changed')).to raise_error(Capybara::ReadOnlyElementError)
|
||||
end if Capybara::VERSION.to_f > 3.0
|
||||
|
||||
it 'should allow me to change the contents of a contenteditable element', :requires => [:js] do
|
||||
it 'should allow me to change the contents of a contenteditable element', requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.find(:css,'#existing_content_editable').set('WYSIWYG')
|
||||
expect(@session.find(:css,'#existing_content_editable').text).to eq('WYSIWYG')
|
||||
end
|
||||
|
||||
it 'should allow me to set the contents of a contenteditable element', :requires => [:js] do
|
||||
it 'should allow me to set the contents of a contenteditable element', requires: [:js] do
|
||||
@session.visit('/with_js')
|
||||
@session.find(:css,'#blank_content_editable').set('WYSIWYG')
|
||||
expect(@session.find(:css,'#blank_content_editable').text).to eq('WYSIWYG')
|
||||
end
|
||||
|
||||
it 'should allow me to change the contents of a contenteditable elements child', :requires => [:js] do
|
||||
it 'should allow me to change the contents of a contenteditable elements child', requires: [:js] do
|
||||
pending "Selenium doesn't like editing nested contents"
|
||||
@session.visit('/with_js')
|
||||
@session.find(:css,'#existing_content_editable_child').set('WYSIWYG')
|
||||
|
@ -253,7 +253,7 @@ Capybara::SpecHelper.spec "node" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#trigger", :requires => [:js, :trigger] do
|
||||
describe "#trigger", requires: [:js, :trigger] do
|
||||
it "should allow triggering of custom JS events" do
|
||||
@session.visit('/with_js')
|
||||
@session.find(:css, '#with_focus_event').trigger(:focus)
|
||||
|
@ -261,7 +261,7 @@ Capybara::SpecHelper.spec "node" do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#drag_to', :requires => [:js, :drag] do
|
||||
describe '#drag_to', requires: [:js, :drag] do
|
||||
it "should drag and drop an object" do
|
||||
@session.visit('/with_js')
|
||||
element = @session.find('//div[@id="drag"]')
|
||||
|
@ -271,12 +271,12 @@ Capybara::SpecHelper.spec "node" do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#hover', :requires => [:hover] do
|
||||
describe '#hover', requires: [:hover] do
|
||||
it "should allow hovering on an element" do
|
||||
@session.visit('/with_hover')
|
||||
expect(@session.find(:css,'.hidden_until_hover', :visible => false)).not_to be_visible
|
||||
expect(@session.find(:css,'.hidden_until_hover', visible: false)).not_to be_visible
|
||||
@session.find(:css,'.wrapper').hover
|
||||
expect(@session.find(:css, '.hidden_until_hover', :visible => false)).to be_visible
|
||||
expect(@session.find(:css, '.hidden_until_hover', visible: false)).to be_visible
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -287,7 +287,7 @@ Capybara::SpecHelper.spec "node" do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#double_click', :requires => [:js] do
|
||||
describe '#double_click', requires: [:js] do
|
||||
it "should double click an element" do
|
||||
@session.visit('/with_js')
|
||||
@session.find(:css, '#click-test').double_click
|
||||
|
@ -295,7 +295,7 @@ Capybara::SpecHelper.spec "node" do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#right_click', :requires => [:js] do
|
||||
describe '#right_click', requires: [:js] do
|
||||
it "should right click an element" do
|
||||
@session.visit('/with_js')
|
||||
@session.find(:css, '#click-test').right_click
|
||||
|
@ -329,7 +329,7 @@ Capybara::SpecHelper.spec "node" do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#reload', :requires => [:js] do
|
||||
describe '#reload', requires: [:js] do
|
||||
context "without automatic reload" do
|
||||
before { Capybara.automatic_reload = false }
|
||||
it "should reload the current context of the node" do
|
||||
|
@ -409,7 +409,7 @@ Capybara::SpecHelper.spec "node" do
|
|||
|
||||
it "should reload nodes with options" do
|
||||
@session.visit('/with_js')
|
||||
node = @session.find(:css, 'em', :text => "reloaded")
|
||||
node = @session.find(:css, 'em', text: "reloaded")
|
||||
@session.click_link('Reload!')
|
||||
sleep(1)
|
||||
expect(node.text).to eq('has been reloaded')
|
||||
|
@ -418,7 +418,7 @@ Capybara::SpecHelper.spec "node" do
|
|||
end
|
||||
|
||||
context "when #synchronize raises server errors" do
|
||||
it "sets an explanatory exception as the cause of server exceptions", :requires => [:server, :js] do
|
||||
it "sets an explanatory exception as the cause of server exceptions", requires: [:server, :js] do
|
||||
skip "This version of ruby doesn't support exception causes" unless Exception.instance_methods.include? :cause
|
||||
quietly { @session.visit("/error") }
|
||||
expect do
|
||||
|
|
|
@ -53,7 +53,7 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|||
expect(@session).to have_no_selector :xpath, "/html/body/*", wait: false
|
||||
end
|
||||
|
||||
it "raises any standard errors caught inside the server", :requires => [:server] do
|
||||
it "raises any standard errors caught inside the server", requires: [:server] do
|
||||
quietly { @session.visit("/error") }
|
||||
expect do
|
||||
@session.reset_session!
|
||||
|
@ -68,7 +68,7 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|||
Capybara.reuse_server = false
|
||||
end
|
||||
|
||||
it "raises any standard errors caught inside the server during a second session", :requires => [:server] do
|
||||
it "raises any standard errors caught inside the server during a second session", requires: [:server] do
|
||||
Capybara.using_driver(@session.mode) do
|
||||
Capybara.using_session(:another_session) do
|
||||
@another_session = Capybara.current_session
|
||||
|
@ -87,7 +87,7 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|||
end
|
||||
end
|
||||
|
||||
it "raises configured errors caught inside the server", :requires => [:server] do
|
||||
it "raises configured errors caught inside the server", requires: [:server] do
|
||||
prev_errors = Capybara.server_errors
|
||||
|
||||
Capybara.server_errors = [LoadError]
|
||||
|
@ -104,7 +104,7 @@ Capybara::SpecHelper.spec '#reset_session!' do
|
|||
Capybara.server_errors = prev_errors
|
||||
end
|
||||
|
||||
it "ignores server errors when `Capybara.raise_server_errors = false`", :requires => [:server] do
|
||||
it "ignores server errors when `Capybara.raise_server_errors = false`", requires: [:server] do
|
||||
Capybara.raise_server_errors = false
|
||||
quietly { @session.visit("/error") }
|
||||
@session.reset_session!
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#status_code' do
|
||||
it "should return response codes", :requires => [:status_code] do
|
||||
it "should return response codes", requires: [:status_code] do
|
||||
@session.visit('/with_simple_html')
|
||||
expect(@session.status_code).to eq(200)
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
|||
@session.visit '/'
|
||||
end
|
||||
|
||||
it 'opens file from the default directory', :requires => [:screenshot] do
|
||||
it 'opens file from the default directory', requires: [:screenshot] do
|
||||
expected_file_regex = %r{capybara-\d+\.png}
|
||||
allow(@session.driver).to receive(:save_screenshot)
|
||||
allow(Launchy).to receive(:open)
|
||||
|
@ -18,7 +18,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
|||
expect(Launchy).to have_received(:open).with(expected_file_regex)
|
||||
end
|
||||
|
||||
it 'opens file from the provided directory', :requires => [:screenshot] do
|
||||
it 'opens file from the provided directory', requires: [:screenshot] do
|
||||
custom_path = 'screenshots/1.png'
|
||||
allow(@session.driver).to receive(:save_screenshot)
|
||||
allow(Launchy).to receive(:open)
|
||||
|
@ -31,7 +31,7 @@ Capybara::SpecHelper.spec '#save_and_open_screenshot' do
|
|||
end
|
||||
|
||||
context 'when launchy cannot be required' do
|
||||
it 'prints out a correct warning message', :requires => [:screenshot] do
|
||||
it 'prints out a correct warning message', requires: [:screenshot] do
|
||||
file_path = File.join(Dir.tmpdir, 'test.png')
|
||||
allow(@session).to receive(:require).with('launchy').and_raise(LoadError)
|
||||
allow(@session).to receive(:warn)
|
||||
|
|
|
@ -8,7 +8,7 @@ Capybara::SpecHelper.spec "#save_screenshot" do
|
|||
@session.visit '/'
|
||||
end
|
||||
|
||||
it "should generate PNG file", :requires => [:screenshot] do
|
||||
it "should generate PNG file", requires: [:screenshot] do
|
||||
path = @session.save_screenshot image_path
|
||||
|
||||
magic = File.read(image_path, 4)
|
||||
|
|
|
@ -9,30 +9,30 @@ Capybara::SpecHelper.spec "#select" do
|
|||
end
|
||||
|
||||
it "should return value of the selected option" do
|
||||
@session.select("Miss", :from => 'Title')
|
||||
@session.select("Miss", from: 'Title')
|
||||
expect(@session.find_field('Title').value).to eq('Miss')
|
||||
end
|
||||
|
||||
it "should allow selecting options where there are inexact matches" do
|
||||
@session.select("Mr", :from => 'Title')
|
||||
@session.select("Mr", from: 'Title')
|
||||
expect(@session.find_field('Title').value).to eq('Mr')
|
||||
end
|
||||
|
||||
it "should allow selecting options where they are the only inexact match" do
|
||||
@session.select("Mis", :from => 'Title')
|
||||
@session.select("Mis", from: 'Title')
|
||||
expect(@session.find_field('Title').value).to eq('Miss')
|
||||
end
|
||||
|
||||
it "should not allow selecting options where they are the only inexact match if `Capybara.exact_options = true`" do
|
||||
Capybara.exact_options = true
|
||||
expect do
|
||||
@session.select("Mis", :from => 'Title')
|
||||
@session.select("Mis", from: 'Title')
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "should not allow selecting an option if the match is ambiguous" do
|
||||
expect do
|
||||
@session.select("M", :from => 'Title')
|
||||
@session.select("M", from: 'Title')
|
||||
end.to raise_error(Capybara::Ambiguous)
|
||||
end
|
||||
|
||||
|
@ -41,13 +41,13 @@ Capybara::SpecHelper.spec "#select" do
|
|||
end
|
||||
|
||||
it "should select an option from a select box by id" do
|
||||
@session.select("Finish", :from => 'form_locale')
|
||||
@session.select("Finish", from: 'form_locale')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['locale']).to eq('fi')
|
||||
end
|
||||
|
||||
it "should select an option from a select box by label" do
|
||||
@session.select("Finish", :from => 'Locale')
|
||||
@session.select("Finish", from: 'Locale')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['locale']).to eq('fi')
|
||||
end
|
||||
|
@ -59,13 +59,13 @@ Capybara::SpecHelper.spec "#select" do
|
|||
end
|
||||
|
||||
it "should escape quotes" do
|
||||
@session.select("John's made-up language", :from => 'Locale')
|
||||
@session.select("John's made-up language", from: 'Locale')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['locale']).to eq('jo')
|
||||
end
|
||||
|
||||
it "should obey from" do
|
||||
@session.select("Miss", :from => "Other title")
|
||||
@session.select("Miss", from: "Other title")
|
||||
@session.click_button('awesome')
|
||||
results = extract_results(@session)
|
||||
expect(results['other_title']).to eq("Miss")
|
||||
|
@ -73,13 +73,13 @@ Capybara::SpecHelper.spec "#select" do
|
|||
end
|
||||
|
||||
it "show match labels with preceding or trailing whitespace" do
|
||||
@session.select("Lojban", :from => 'Locale')
|
||||
@session.select("Lojban", from: 'Locale')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['locale']).to eq('jbo')
|
||||
end
|
||||
|
||||
it "casts to string" do
|
||||
@session.select(:"Miss", :from => :'Title')
|
||||
@session.select(:"Miss", from: :'Title')
|
||||
expect(@session.find_field('Title').value).to eq('Miss')
|
||||
end
|
||||
|
||||
|
@ -87,7 +87,7 @@ Capybara::SpecHelper.spec "#select" do
|
|||
it "should raise an error" do
|
||||
msg = "Unable to find select box \"does not exist\""
|
||||
expect do
|
||||
@session.select('foo', :from => 'does not exist')
|
||||
@session.select('foo', from: 'does not exist')
|
||||
end.to raise_error(Capybara::ElementNotFound, msg)
|
||||
end
|
||||
end
|
||||
|
@ -96,7 +96,7 @@ Capybara::SpecHelper.spec "#select" do
|
|||
it "should raise an error" do
|
||||
msg = "Unable to find option \"Does not Exist\""
|
||||
expect do
|
||||
@session.select('Does not Exist', :from => 'form_locale')
|
||||
@session.select('Does not Exist', from: 'form_locale')
|
||||
end.to raise_error(Capybara::ElementNotFound, msg)
|
||||
end
|
||||
end
|
||||
|
@ -104,20 +104,20 @@ Capybara::SpecHelper.spec "#select" do
|
|||
context "on a disabled select" do
|
||||
it "should raise an error" do
|
||||
expect do
|
||||
@session.select('Should not see me', :from => 'Disabled Select')
|
||||
@session.select('Should not see me', from: 'Disabled Select')
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context "on a disabled option" do
|
||||
it "should not select" do
|
||||
@session.select('Other', :from => 'form_title')
|
||||
@session.select('Other', from: 'form_title')
|
||||
expect(@session.find_field('form_title').value).not_to eq 'Other'
|
||||
end
|
||||
|
||||
it "should warn" do
|
||||
expect_any_instance_of(Capybara::Node::Element).to receive(:warn).once
|
||||
@session.select('Other', :from => 'form_title')
|
||||
@session.select('Other', from: 'form_title')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -127,28 +127,28 @@ Capybara::SpecHelper.spec "#select" do
|
|||
end
|
||||
|
||||
it "should return value of the selected options" do
|
||||
@session.select("Ruby", :from => 'Language')
|
||||
@session.select("Javascript", :from => 'Language')
|
||||
@session.select("Ruby", from: 'Language')
|
||||
@session.select("Javascript", from: 'Language')
|
||||
expect(@session.find_field('Language').value).to include('Ruby', 'Javascript')
|
||||
end
|
||||
|
||||
it "should select one option" do
|
||||
@session.select("Ruby", :from => 'Language')
|
||||
@session.select("Ruby", from: 'Language')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['languages']).to eq(['Ruby'])
|
||||
end
|
||||
|
||||
it "should select multiple options" do
|
||||
@session.select("Ruby", :from => 'Language')
|
||||
@session.select("Javascript", :from => 'Language')
|
||||
@session.select("Ruby", from: 'Language')
|
||||
@session.select("Javascript", from: 'Language')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
|
||||
end
|
||||
|
||||
it "should remain selected if already selected" do
|
||||
@session.select("Ruby", :from => 'Language')
|
||||
@session.select("Javascript", :from => 'Language')
|
||||
@session.select("Ruby", :from => 'Language')
|
||||
@session.select("Ruby", from: 'Language')
|
||||
@session.select("Javascript", from: 'Language')
|
||||
@session.select("Ruby", from: 'Language')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
|
||||
end
|
||||
|
@ -161,19 +161,19 @@ Capybara::SpecHelper.spec "#select" do
|
|||
context "with :exact option" do
|
||||
context "when `false`" do
|
||||
it "can match select box approximately" do
|
||||
@session.select("Finish", :from => "Loc", :exact => false)
|
||||
@session.select("Finish", from: "Loc", exact: false)
|
||||
@session.click_button("awesome")
|
||||
expect(extract_results(@session)["locale"]).to eq("fi")
|
||||
end
|
||||
|
||||
it "can match option approximately" do
|
||||
@session.select("Fin", :from => "Locale", :exact => false)
|
||||
@session.select("Fin", from: "Locale", exact: false)
|
||||
@session.click_button("awesome")
|
||||
expect(extract_results(@session)["locale"]).to eq("fi")
|
||||
end
|
||||
|
||||
it "can match option approximately when :from not given" do
|
||||
@session.select("made-up language", :exact => false)
|
||||
@session.select("made-up language", exact: false)
|
||||
@session.click_button("awesome")
|
||||
expect(extract_results(@session)["locale"]).to eq("jo")
|
||||
end
|
||||
|
@ -182,19 +182,19 @@ Capybara::SpecHelper.spec "#select" do
|
|||
context "when `true`" do
|
||||
it "can match select box approximately" do
|
||||
expect do
|
||||
@session.select("Finish", :from => "Loc", :exact => true)
|
||||
@session.select("Finish", from: "Loc", exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "can match option approximately" do
|
||||
expect do
|
||||
@session.select("Fin", :from => "Locale", :exact => true)
|
||||
@session.select("Fin", from: "Locale", exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "can match option approximately when :from not given" do
|
||||
expect do
|
||||
@session.select("made-up language", :exact => true)
|
||||
@session.select("made-up language", exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,14 +27,14 @@ Capybara::SpecHelper.spec "#uncheck" do
|
|||
|
||||
context "with :exact option" do
|
||||
it "should accept partial matches when false" do
|
||||
@session.uncheck('Ham', :exact => false)
|
||||
@session.uncheck('Ham', exact: false)
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['pets']).not_to include('hamster')
|
||||
end
|
||||
|
||||
it "should not accept partial matches when true" do
|
||||
expect do
|
||||
@session.uncheck('Ham', :exact => true)
|
||||
@session.uncheck('Ham', exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ Capybara::SpecHelper.spec "#unselect" do
|
|||
|
||||
context "with multiple select" do
|
||||
it "should unselect an option from a select box by id" do
|
||||
@session.unselect('Commando', :from => 'form_underwear')
|
||||
@session.unselect('Commando', from: 'form_underwear')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['underwear']).to include('Briefs', 'Boxerbriefs')
|
||||
expect(extract_results(@session)['underwear']).not_to include('Commando')
|
||||
|
@ -20,27 +20,27 @@ Capybara::SpecHelper.spec "#unselect" do
|
|||
end
|
||||
|
||||
it "should unselect an option from a select box by label" do
|
||||
@session.unselect('Commando', :from => 'Underwear')
|
||||
@session.unselect('Commando', from: 'Underwear')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['underwear']).to include('Briefs', 'Boxerbriefs')
|
||||
expect(extract_results(@session)['underwear']).not_to include('Commando')
|
||||
end
|
||||
|
||||
it "should favour exact matches to option labels" do
|
||||
@session.unselect("Briefs", :from => 'Underwear')
|
||||
@session.unselect("Briefs", from: 'Underwear')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['underwear']).to include('Commando', 'Boxerbriefs')
|
||||
expect(extract_results(@session)['underwear']).not_to include('Briefs')
|
||||
end
|
||||
|
||||
it "should escape quotes" do
|
||||
@session.unselect("Frenchman's Pantalons", :from => 'Underwear')
|
||||
@session.unselect("Frenchman's Pantalons", from: 'Underwear')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['underwear']).not_to include("Frenchman's Pantalons")
|
||||
end
|
||||
|
||||
it "casts to string" do
|
||||
@session.unselect(:"Briefs", :from => :'Underwear')
|
||||
@session.unselect(:"Briefs", from: :'Underwear')
|
||||
@session.click_button('awesome')
|
||||
expect(extract_results(@session)['underwear']).to include('Commando', 'Boxerbriefs')
|
||||
expect(extract_results(@session)['underwear']).not_to include('Briefs')
|
||||
|
@ -49,7 +49,7 @@ Capybara::SpecHelper.spec "#unselect" do
|
|||
|
||||
context "with single select" do
|
||||
it "should raise an error" do
|
||||
expect { @session.unselect("English", :from => 'form_locale') }.to raise_error(Capybara::UnselectNotAllowed)
|
||||
expect { @session.unselect("English", from: 'form_locale') }.to raise_error(Capybara::UnselectNotAllowed)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -57,7 +57,7 @@ Capybara::SpecHelper.spec "#unselect" do
|
|||
it "should raise an error" do
|
||||
msg = "Unable to find select box \"does not exist\""
|
||||
expect do
|
||||
@session.unselect('foo', :from => 'does not exist')
|
||||
@session.unselect('foo', from: 'does not exist')
|
||||
end.to raise_error(Capybara::ElementNotFound, msg)
|
||||
end
|
||||
end
|
||||
|
@ -66,7 +66,7 @@ Capybara::SpecHelper.spec "#unselect" do
|
|||
it "should raise an error" do
|
||||
msg = "Unable to find option \"Does not Exist\""
|
||||
expect do
|
||||
@session.unselect('Does not Exist', :from => 'form_underwear')
|
||||
@session.unselect('Does not Exist', from: 'form_underwear')
|
||||
end.to raise_error(Capybara::ElementNotFound, msg)
|
||||
end
|
||||
end
|
||||
|
@ -74,19 +74,19 @@ Capybara::SpecHelper.spec "#unselect" do
|
|||
context "with :exact option" do
|
||||
context "when `false`" do
|
||||
it "can match select box approximately" do
|
||||
@session.unselect("Boxerbriefs", :from => "Under", :exact => false)
|
||||
@session.unselect("Boxerbriefs", from: "Under", exact: false)
|
||||
@session.click_button("awesome")
|
||||
expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
|
||||
end
|
||||
|
||||
it "can match option approximately" do
|
||||
@session.unselect("Boxerbr", :from => "Underwear", :exact => false)
|
||||
@session.unselect("Boxerbr", from: "Underwear", exact: false)
|
||||
@session.click_button("awesome")
|
||||
expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
|
||||
end
|
||||
|
||||
it "can match option approximately when :from not given" do
|
||||
@session.unselect("Boxerbr", :exact => false)
|
||||
@session.unselect("Boxerbr", exact: false)
|
||||
@session.click_button("awesome")
|
||||
expect(extract_results(@session)["underwear"]).not_to include("Boxerbriefs")
|
||||
end
|
||||
|
@ -95,19 +95,19 @@ Capybara::SpecHelper.spec "#unselect" do
|
|||
context "when `true`" do
|
||||
it "can match select box approximately" do
|
||||
expect do
|
||||
@session.unselect("Boxerbriefs", :from => "Under", :exact => true)
|
||||
@session.unselect("Boxerbriefs", from: "Under", exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "can match option approximately" do
|
||||
expect do
|
||||
@session.unselect("Boxerbr", :from => "Underwear", :exact => true)
|
||||
@session.unselect("Boxerbr", from: "Underwear", exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
|
||||
it "can match option approximately when :from not given" do
|
||||
expect do
|
||||
@session.unselect("Boxerbr", :exact => true)
|
||||
@session.unselect("Boxerbr", exact: true)
|
||||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ Capybara::SpecHelper.spec '#visit' do
|
|||
expect(@session).to have_content('Hello world!')
|
||||
end
|
||||
|
||||
it "raises any errors caught inside the server", :requires => [:server] do
|
||||
it "raises any errors caught inside the server", requires: [:server] do
|
||||
quietly { @session.visit("/error") }
|
||||
expect do
|
||||
@session.visit("/")
|
||||
|
@ -65,7 +65,7 @@ Capybara::SpecHelper.spec '#visit' do
|
|||
end
|
||||
end
|
||||
|
||||
context "without a server", :requires => [:server] do
|
||||
context "without a server", requires: [:server] do
|
||||
it "should respect `app_host`" do
|
||||
serverless_session = Capybara::Session.new(@session.mode, nil)
|
||||
Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
|
||||
Capybara::SpecHelper.spec '#within_frame', requires: [:frames] do
|
||||
before(:each) do
|
||||
@session.visit('/within_frames')
|
||||
end
|
||||
|
@ -58,7 +58,7 @@ Capybara::SpecHelper.spec '#within_frame', :requires => [:frames] do
|
|||
end
|
||||
end
|
||||
|
||||
it "works if the frame is closed", :requires => [:frames, :js] do
|
||||
it "works if the frame is closed", requires: [:frames, :js] do
|
||||
@session.within_frame 'parentFrame' do
|
||||
@session.within_frame 'childFrame' do
|
||||
@session.click_link 'Close Window'
|
||||
|
|
|
@ -20,7 +20,7 @@ Capybara::SpecHelper.spec '#within' do
|
|||
end
|
||||
|
||||
it "should accept additional options" do
|
||||
@session.within(:css, "#for_bar li", :text => 'With Simple HTML') do
|
||||
@session.within(:css, "#for_bar li", text: 'With Simple HTML') do
|
||||
@session.click_link('Go')
|
||||
end
|
||||
expect(@session).to have_content('Bar')
|
||||
|
@ -114,7 +114,7 @@ Capybara::SpecHelper.spec '#within' do
|
|||
expect(extract_results(@session)['first_name']).to eq('Peter')
|
||||
@session.visit('/with_scope')
|
||||
@session.within("//li[contains(.,'Bar')]") do
|
||||
@session.fill_in('First Name', :with => 'Dagobert')
|
||||
@session.fill_in('First Name', with: 'Dagobert')
|
||||
@session.click_button('Go')
|
||||
end
|
||||
expect(extract_results(@session)['first_name']).to eq('Dagobert')
|
||||
|
@ -128,7 +128,7 @@ Capybara::SpecHelper.spec '#within_fieldset' do
|
|||
|
||||
it "should restrict scope to a fieldset given by id" do
|
||||
@session.within_fieldset("villain_fieldset") do
|
||||
@session.fill_in("Name", :with => 'Goldfinger')
|
||||
@session.fill_in("Name", with: 'Goldfinger')
|
||||
@session.click_button("Create")
|
||||
end
|
||||
expect(extract_results(@session)['villain_name']).to eq('Goldfinger')
|
||||
|
@ -136,7 +136,7 @@ Capybara::SpecHelper.spec '#within_fieldset' do
|
|||
|
||||
it "should restrict scope to a fieldset given by legend" do
|
||||
@session.within_fieldset("Villain") do
|
||||
@session.fill_in("Name", :with => 'Goldfinger')
|
||||
@session.fill_in("Name", with: 'Goldfinger')
|
||||
@session.click_button("Create")
|
||||
end
|
||||
expect(extract_results(@session)['villain_name']).to eq('Goldfinger')
|
||||
|
@ -150,7 +150,7 @@ Capybara::SpecHelper.spec '#within_table' do
|
|||
|
||||
it "should restrict scope to a fieldset given by id" do
|
||||
@session.within_table("girl_table") do
|
||||
@session.fill_in("Name", :with => 'Christmas')
|
||||
@session.fill_in("Name", with: 'Christmas')
|
||||
@session.click_button("Create")
|
||||
end
|
||||
expect(extract_results(@session)['girl_name']).to eq('Christmas')
|
||||
|
@ -158,7 +158,7 @@ Capybara::SpecHelper.spec '#within_table' do
|
|||
|
||||
it "should restrict scope to a fieldset given by legend" do
|
||||
@session.within_table("Villain") do
|
||||
@session.fill_in("Name", :with => 'Quantum')
|
||||
@session.fill_in("Name", with: 'Quantum')
|
||||
@session.click_button("Create")
|
||||
end
|
||||
expect(extract_results(@session)['villain_name']).to eq('Quantum')
|
||||
|
|
|
@ -19,7 +19,7 @@ module Capybara
|
|||
module SpecHelper
|
||||
class << self
|
||||
def configure(config)
|
||||
config.filter_run_excluding :requires => method(:filter).to_proc
|
||||
config.filter_run_excluding requires: method(:filter).to_proc
|
||||
config.before { Capybara::SpecHelper.reset! }
|
||||
config.after { Capybara::SpecHelper.reset! }
|
||||
# Test in 3.5+ where metadata doesn't autotrigger shared context inclusion - will be only behavior in RSpec 4
|
||||
|
|
|
@ -175,5 +175,5 @@ class TestApp < Sinatra::Base
|
|||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
Rack::Handler::WEBrick.run TestApp, :Port => 8070
|
||||
Rack::Handler::WEBrick.run TestApp, Port: 8070
|
||||
end
|
||||
|
|
|
@ -69,13 +69,13 @@ RSpec.describe Capybara do
|
|||
end
|
||||
|
||||
it "allows using matchers with text option" do
|
||||
expect(string).to have_css('h1', :text => 'Totally awesome')
|
||||
expect(string).not_to have_css('h1', :text => 'Not so awesome')
|
||||
expect(string).to have_css('h1', text: 'Totally awesome')
|
||||
expect(string).not_to have_css('h1', text: 'Not so awesome')
|
||||
end
|
||||
|
||||
it "allows finding only visible nodes" do
|
||||
expect(string.all(:css, '#secret', :visible => true)).to be_empty
|
||||
expect(string.all(:css, '#secret', :visible => false).size).to eq(1)
|
||||
expect(string.all(:css, '#secret', visible: true)).to be_empty
|
||||
expect(string.all(:css, '#secret', visible: false).size).to eq(1)
|
||||
end
|
||||
|
||||
it "allows finding elements and extracting text from them" do
|
||||
|
@ -101,7 +101,7 @@ RSpec.describe Capybara do
|
|||
|
||||
it "allows finding elements and checking if they are visible" do
|
||||
expect(string.find('//h1')).to be_visible
|
||||
expect(string.find(:css, "#secret", :visible => false)).not_to be_visible
|
||||
expect(string.find(:css, "#secret", visible: false)).not_to be_visible
|
||||
end
|
||||
|
||||
it "allows finding elements and checking if they are disabled" do
|
||||
|
|
|
@ -47,7 +47,7 @@ RSpec.describe Capybara do
|
|||
|
||||
it "should add a new server" do
|
||||
Capybara.register_server :blob do |app, port, host|
|
||||
Rack::Handler::WEBrick.run(app, :Host => host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
||||
Rack::Handler::WEBrick.run(app, Host: host, Port: port, AccessLog: [], Logger: WEBrick::Log::new(nil, 0))
|
||||
end
|
||||
Capybara.server = :blob
|
||||
session = Capybara::Session.new(:selenium, TestApp.dup)
|
||||
|
|
|
@ -6,7 +6,7 @@ class TestClass
|
|||
include Capybara::DSL
|
||||
end
|
||||
|
||||
Capybara::SpecHelper.run_specs TestClass.new, "DSL", :capybara_skip => [
|
||||
Capybara::SpecHelper.run_specs TestClass.new, "DSL", capybara_skip: [
|
||||
:js,
|
||||
:modals,
|
||||
:screenshot,
|
||||
|
|
|
@ -5,7 +5,7 @@ module TestSessions
|
|||
RackTest = Capybara::Session.new(:rack_test, TestApp)
|
||||
end
|
||||
|
||||
Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", :capybara_skip => [
|
||||
Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", capybara_skip: [
|
||||
:js,
|
||||
:modals,
|
||||
:screenshot,
|
||||
|
@ -122,27 +122,27 @@ RSpec.describe Capybara::RackTest::Driver do
|
|||
|
||||
describe ':headers option' do
|
||||
it 'should always set headers' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/get_header')
|
||||
expect(@driver.html).to include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on link clicks' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/header_links')
|
||||
@driver.find_xpath('.//a').first.click
|
||||
expect(@driver.html).to include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on form submit' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/header_links')
|
||||
@driver.find_xpath('.//input').first.click
|
||||
expect(@driver.html).to include('foobar')
|
||||
end
|
||||
|
||||
it 'should keep headers on redirects' do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, headers: {'HTTP_FOO' => 'foobar'})
|
||||
@driver.visit('/get_header_via_redirect')
|
||||
expect(@driver.html).to include('foobar')
|
||||
end
|
||||
|
@ -158,7 +158,7 @@ RSpec.describe Capybara::RackTest::Driver do
|
|||
end
|
||||
|
||||
it "is possible to not follow redirects" do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :follow_redirects => false)
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, follow_redirects: false)
|
||||
|
||||
@driver.visit('/redirect')
|
||||
expect(@driver.response.header['Location']).to match %r{/redirect_again$}
|
||||
|
@ -186,7 +186,7 @@ RSpec.describe Capybara::RackTest::Driver do
|
|||
|
||||
context "with 21 redirect limit" do
|
||||
before do
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, :redirect_limit => 21)
|
||||
@driver = Capybara::RackTest::Driver.new(TestApp, redirect_limit: 21)
|
||||
end
|
||||
|
||||
it "should follow 21 redirects" do
|
||||
|
|
|
@ -25,7 +25,7 @@ RSpec.describe Capybara::RSpecMatchers do
|
|||
end
|
||||
|
||||
it "passes if matched node count equals expected count" do
|
||||
expect("<h1>Text</h1>").to have_css('h1', :count => 1)
|
||||
expect("<h1>Text</h1>").to have_css('h1', count: 1)
|
||||
end
|
||||
|
||||
it "fails if matched node count does not equal expected count" do
|
||||
|
@ -66,12 +66,12 @@ RSpec.describe Capybara::RSpecMatchers do
|
|||
end
|
||||
|
||||
it "passes if matched node count does not equal expected count" do
|
||||
expect("<h1>Text</h1>").not_to have_css('h1', :count => 2)
|
||||
expect("<h1>Text</h1>").not_to have_css('h1', count: 2)
|
||||
end
|
||||
|
||||
it "fails if matched node count equals expected count" do
|
||||
expect do
|
||||
expect("<h1>Text</h1>").not_to have_css('h1', :count => 1)
|
||||
expect("<h1>Text</h1>").not_to have_css('h1', count: 1)
|
||||
end.to raise_error(/expected not to find css "h1"/)
|
||||
end
|
||||
end
|
||||
|
@ -220,7 +220,7 @@ RSpec.describe Capybara::RSpecMatchers do
|
|||
|
||||
context "with should" do
|
||||
it "passes if has_selector? returns true" do
|
||||
expect(page).to have_selector('//h1', :text => 'test')
|
||||
expect(page).to have_selector('//h1', text: 'test')
|
||||
end
|
||||
|
||||
it "fails if has_selector? returns false" do
|
||||
|
@ -231,7 +231,7 @@ RSpec.describe Capybara::RSpecMatchers do
|
|||
|
||||
it "includes text in error message" do
|
||||
expect do
|
||||
expect(page).to have_selector("//h1", :text => 'wrong text')
|
||||
expect(page).to have_selector("//h1", text: 'wrong text')
|
||||
end.to raise_error(%r(expected to find xpath "//h1" with text "wrong text" but there were no matches))
|
||||
end
|
||||
end
|
||||
|
@ -243,7 +243,7 @@ RSpec.describe Capybara::RSpecMatchers do
|
|||
|
||||
it "fails if has_no_selector? returns false" do
|
||||
expect do
|
||||
expect(page).not_to have_selector(:css, 'h1', :text => 'test')
|
||||
expect(page).not_to have_selector(:css, 'h1', text: 'test')
|
||||
end.to raise_error(%r(expected not to find css "h1" with text "test"))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ RSpec.describe 'capybara/rspec', :type => :feature do
|
|||
end
|
||||
end
|
||||
|
||||
it "switches to the javascript driver when giving it as metadata", :js => true do
|
||||
it "switches to the javascript driver when giving it as metadata", js: true do
|
||||
expect(Capybara.current_driver).to eq(Capybara.javascript_driver)
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ skipped_tests = [
|
|||
]
|
||||
skipped_tests << :windows if ENV['TRAVIS'] && !ENV['WINDOW_TEST']
|
||||
|
||||
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => skipped_tests
|
||||
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", capybara_skip: skipped_tests
|
||||
|
||||
RSpec.describe "Capybara::Session with firefox" do
|
||||
include_examples "Capybara::Session", TestSessions::Selenium, :selenium_focus
|
||||
|
|
|
@ -12,7 +12,7 @@ module TestSessions
|
|||
Chrome = Capybara::Session.new(:selenium_chrome, TestApp)
|
||||
end
|
||||
|
||||
Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", :capybara_skip => [
|
||||
Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", capybara_skip: [
|
||||
:response_headers,
|
||||
:status_code,
|
||||
:trigger
|
||||
|
|
|
@ -62,37 +62,37 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
|
|||
end
|
||||
end
|
||||
|
||||
context "#fill_in with { :clear => :backspace } fill_option", :requires => [:js] do
|
||||
context "#fill_in with { :clear => :backspace } fill_option", requires: [:js] do
|
||||
it 'should fill in a field, replacing an existing value' do
|
||||
@session.visit('/form')
|
||||
@session.fill_in('form_first_name', :with => 'Harry',
|
||||
@session.fill_in('form_first_name', with: 'Harry',
|
||||
fill_options: { clear: :backspace} )
|
||||
expect(@session.find(:fillable_field, 'form_first_name').value).to eq('Harry')
|
||||
end
|
||||
|
||||
it 'should only trigger onchange once' do
|
||||
@session.visit('/with_js')
|
||||
@session.fill_in('with_change_event', :with => 'some value',
|
||||
:fill_options => { :clear => :backspace })
|
||||
@session.fill_in('with_change_event', with: 'some value',
|
||||
fill_options: { :clear => :backspace })
|
||||
# click outside the field to trigger the change event
|
||||
@session.find(:css, 'body').click
|
||||
expect(@session.find(:css, '.change_event_triggered', :match => :one)).to have_text 'some value'
|
||||
expect(@session.find(:css, '.change_event_triggered', match: :one)).to have_text 'some value'
|
||||
end
|
||||
|
||||
it 'should trigger change when clearing field' do
|
||||
@session.visit('/with_js')
|
||||
@session.fill_in('with_change_event', :with => '',
|
||||
:fill_options => { :clear => :backspace })
|
||||
@session.fill_in('with_change_event', with: '',
|
||||
fill_options: { :clear => :backspace })
|
||||
# click outside the field to trigger the change event
|
||||
@session.find(:css, 'body').click
|
||||
expect(@session).to have_selector(:css, '.change_event_triggered', :match => :one)
|
||||
expect(@session).to have_selector(:css, '.change_event_triggered', match: :one)
|
||||
end
|
||||
end
|
||||
|
||||
context "#fill_in with { clear: :none } fill_options" do
|
||||
it 'should append to content in a field' do
|
||||
@session.visit('/form')
|
||||
@session.fill_in('form_first_name', :with => 'Harry',
|
||||
@session.fill_in('form_first_name', with: 'Harry',
|
||||
fill_options: { clear: :none} )
|
||||
expect(@session.find(:fillable_field, 'form_first_name').value).to eq('JohnHarry')
|
||||
end
|
||||
|
@ -102,7 +102,7 @@ RSpec.shared_examples "Capybara::Session" do |session, mode|
|
|||
it 'should pass the array through to the element' do
|
||||
#this is mainly for use with [[:ctrl, 'a'], :backspace] - however since that is platform dependant I'm testing with something less useful
|
||||
@session.visit('/form')
|
||||
@session.fill_in('form_first_name', :with => 'Harry',
|
||||
@session.fill_in('form_first_name', with: 'Harry',
|
||||
fill_options: { clear: [[:shift, 'abc'], :backspace] } )
|
||||
expect(@session.find(:fillable_field, 'form_first_name').value).to eq('JohnABHarry')
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue