1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Fix Rubocop Issues

This commit is contained in:
Thomas Walpole 2019-10-15 17:40:27 -07:00
parent fbe8257fa6
commit 7ca1cdc828
11 changed files with 51 additions and 18 deletions

View file

@ -128,6 +128,7 @@ Capybara::SpecHelper.spec '#all' do
it 'should succeed when the number of elements founds matches the expectation' do
expect { @session.all(:css, 'h1, p', count: 4) }.not_to 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)
end
@ -137,6 +138,7 @@ Capybara::SpecHelper.spec '#all' do
it 'should succeed when the number of elements founds matches the expectation' do
expect { @session.all(:css, 'h1, p', minimum: 0) }.not_to 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)
end
@ -146,6 +148,7 @@ Capybara::SpecHelper.spec '#all' do
it 'should succeed when the number of elements founds matches the expectation' do
expect { @session.all(:css, 'h1, p', maximum: 4) }.not_to 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)
end
@ -155,6 +158,7 @@ Capybara::SpecHelper.spec '#all' do
it 'should succeed when the number of elements founds matches the expectation' do
expect { @session.all(:css, 'h1, p', between: 2..7) }.not_to 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)
end
@ -175,6 +179,7 @@ Capybara::SpecHelper.spec '#all' do
between: 0..3 }
expect { @session.all(:css, 'h1, p', o) }.not_to raise_error
end
context 'with no :count expectation' do
it 'fails if :minimum is not met' do
o = { minimum: 5,
@ -182,18 +187,21 @@ Capybara::SpecHelper.spec '#all' do
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 }
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 }
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,

View file

@ -159,6 +159,7 @@ Capybara::SpecHelper.spec '#assert_text' do
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,
@ -166,18 +167,21 @@ Capybara::SpecHelper.spec '#assert_text' do
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 }
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 }
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,

View file

@ -275,14 +275,17 @@ Capybara::SpecHelper.spec '#find' do
@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)
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')
end
it 'raises an error if there is no match' do
expect do
@session.find(:css, '.does-not-exist', match: :one)
@ -294,6 +297,7 @@ Capybara::SpecHelper.spec '#find' do
it 'returns the first matched element' do
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)
@ -308,19 +312,23 @@ Capybara::SpecHelper.spec '#find' do
@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)
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)
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)
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)
@ -334,20 +342,24 @@ Capybara::SpecHelper.spec '#find' do
@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)
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)
end.to raise_error(Capybara::ElementNotFound)
end
it 'raises an error when there is a single inexact matches' do
expect do
@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)
@ -362,18 +374,22 @@ Capybara::SpecHelper.spec '#find' do
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)
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)
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)
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)
@ -386,20 +402,24 @@ Capybara::SpecHelper.spec '#find' do
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)
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)
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)
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)

View file

@ -137,7 +137,7 @@ RSpec.describe Capybara::Result do
expect(result.instance_variable_get('@result_cache').size).to eq 4
end
context '#each' do
describe '#each' do
it 'lazily evaluates' do
skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround?
results = []

View file

@ -81,6 +81,7 @@ xfeature 'if xfeature aliases to pending then' do
scenario "this should be 'temporarily disabled with xfeature'" do
# dummy
end
scenario "this also should be 'temporarily disabled with xfeature'" do
# dummy
end

View file

@ -857,7 +857,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
session.visit('/with_js')
end
context '#and' do
describe '#and' do
it "should run 'concurrently'" do
Capybara.using_wait_time(2) do
matcher = have_text('this is not there').and have_text('neither is this')
@ -899,14 +899,14 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
end
end
context '#and_then' do
describe '#and_then' do
it 'should run sequentially' do
session.click_link('reload-link')
expect(el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
end
end
context '#or' do
describe '#or' do
it "should run 'concurrently'" do
session.using_wait_time(3) do
expect(Benchmark.realtime do

View file

@ -43,7 +43,7 @@ RSpec.describe 'capybara/rspec' do
expect(Capybara.current_driver).to eq(:culerity)
end
context '#all' do
describe '#all' do
it 'allows access to the Capybara finder' do
visit('/with_html')
found = all(:css, 'h2') { |element| element[:class] == 'head' }
@ -57,7 +57,7 @@ RSpec.describe 'capybara/rspec' do
end
end
context '#within' do
describe '#within' do
it 'allows access to the Capybara scoper' do
visit('/with_html')
expect do
@ -82,7 +82,7 @@ RSpec.describe 'capybara/rspec' do
end.new
end
context '#all' do
describe '#all' do
it 'allows access to the Capybara finder' do
test_class_instance.visit('/with_html')
expect(test_class_instance.all(:css, 'h2.head').size).to eq(5)
@ -95,7 +95,7 @@ RSpec.describe 'capybara/rspec' do
end
end
context '#within' do
describe '#within' do
it 'allows access to the Capybara scoper' do
test_class_instance.visit('/with_html')
expect do

View file

@ -182,7 +182,7 @@ RSpec.describe Capybara::Selenium::Driver do
end
RSpec.describe Capybara::Selenium::Node do
context '#click' do
describe '#click' do
it 'warns when attempting on a table row' do
session = TestSessions::SeleniumFirefox
session.visit('/tables')

View file

@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Capybara::Session do
context '#new' do
describe '#new' do
it 'should raise an error if passed non-existent driver' do
expect do
described_class.new(:quox, TestApp).driver

View file

@ -6,7 +6,7 @@ require 'selenium-webdriver'
RSpec.shared_examples 'Capybara::Node' do |session, _mode|
let(:session) { session }
context '#content_editable?' do
describe '#content_editable?' do
it 'returns true when the element is content editable' do
session.visit('/with_js')
expect(session.find(:css, '#existing_content_editable').base.content_editable?).to be true
@ -19,7 +19,7 @@ RSpec.shared_examples 'Capybara::Node' do |session, _mode|
end
end
context '#send_keys' do
describe '#send_keys' do
it 'should process space' do
session.visit('/form')
session.find(:css, '#address1_city').send_keys('ocean', [:shift, :space, 'side'])
@ -27,7 +27,7 @@ RSpec.shared_examples 'Capybara::Node' do |session, _mode|
end
end
context '#visible?' do
describe '#visible?' do
let(:bridge) do
session.driver.browser.send(:bridge)
end

View file

@ -72,7 +72,7 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
end
end
context '#fill_in_with empty string and no options' do
describe '#fill_in_with empty string and no options' do
it 'should trigger change when clearing a field' do
pending "safaridriver doesn't trigger change for clear" if safari?(session)
session.visit('/with_js')
@ -83,7 +83,7 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
end
end
context '#fill_in with { :clear => :backspace } fill_option', requires: [:js] do
describe '#fill_in with { :clear => :backspace } fill_option', requires: [:js] do
before do
# Firefox has an issue with change events if the main window doesn't think it's focused
session.execute_script('window.focus()')
@ -150,7 +150,7 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
end
end
context '#fill_in with { clear: :none } fill_options' do
describe '#fill_in with { clear: :none } fill_options' do
it 'should append to content in a field' do
pending 'Safari overwrites by default - need to figure out a workaround' if safari?(session)
@ -162,7 +162,7 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
end
end
context '#fill_in with Date' do
describe '#fill_in with Date' do
before do
session.visit('/form')
session.find(:css, '#form_date').execute_script <<-JS
@ -194,7 +194,7 @@ RSpec.shared_examples 'Capybara::Session' do |session, mode|
end
end
context '#fill_in with { clear: Array } fill_options' do
describe '#fill_in with { clear: Array } fill_options' do
it 'should pass the array through to the element' do
# this is mainly for use with [[:control, 'a'], :backspace] - however since that is platform dependant I'm testing with something less useful
session.visit('/form')