From 7ca1cdc828e97c4da6199be17387762e7f9f3dd9 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Tue, 15 Oct 2019 17:40:27 -0700 Subject: [PATCH] Fix Rubocop Issues --- lib/capybara/spec/session/all_spec.rb | 8 ++++++++ lib/capybara/spec/session/assert_text_spec.rb | 4 ++++ lib/capybara/spec/session/find_spec.rb | 20 +++++++++++++++++++ spec/result_spec.rb | 2 +- spec/rspec/features_spec.rb | 1 + spec/rspec/shared_spec_matchers.rb | 6 +++--- spec/rspec_spec.rb | 8 ++++---- spec/selenium_spec_firefox.rb | 2 +- spec/session_spec.rb | 2 +- spec/shared_selenium_node.rb | 6 +++--- spec/shared_selenium_session.rb | 10 +++++----- 11 files changed, 51 insertions(+), 18 deletions(-) diff --git a/lib/capybara/spec/session/all_spec.rb b/lib/capybara/spec/session/all_spec.rb index 851952ed..c919dd5e 100644 --- a/lib/capybara/spec/session/all_spec.rb +++ b/lib/capybara/spec/session/all_spec.rb @@ -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, diff --git a/lib/capybara/spec/session/assert_text_spec.rb b/lib/capybara/spec/session/assert_text_spec.rb index 27d86777..081343a0 100644 --- a/lib/capybara/spec/session/assert_text_spec.rb +++ b/lib/capybara/spec/session/assert_text_spec.rb @@ -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, diff --git a/lib/capybara/spec/session/find_spec.rb b/lib/capybara/spec/session/find_spec.rb index ed2f5530..2dc09aba 100644 --- a/lib/capybara/spec/session/find_spec.rb +++ b/lib/capybara/spec/session/find_spec.rb @@ -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) diff --git a/spec/result_spec.rb b/spec/result_spec.rb index 15b6f598..1e26c7d3 100644 --- a/spec/result_spec.rb +++ b/spec/result_spec.rb @@ -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 = [] diff --git a/spec/rspec/features_spec.rb b/spec/rspec/features_spec.rb index ca03277c..946f5765 100644 --- a/spec/rspec/features_spec.rb +++ b/spec/rspec/features_spec.rb @@ -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 diff --git a/spec/rspec/shared_spec_matchers.rb b/spec/rspec/shared_spec_matchers.rb index 072785aa..c7050aaa 100644 --- a/spec/rspec/shared_spec_matchers.rb +++ b/spec/rspec/shared_spec_matchers.rb @@ -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 diff --git a/spec/rspec_spec.rb b/spec/rspec_spec.rb index d13e3374..d0d73c19 100644 --- a/spec/rspec_spec.rb +++ b/spec/rspec_spec.rb @@ -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 diff --git a/spec/selenium_spec_firefox.rb b/spec/selenium_spec_firefox.rb index 2b75f3ed..bb6b47d2 100644 --- a/spec/selenium_spec_firefox.rb +++ b/spec/selenium_spec_firefox.rb @@ -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') diff --git a/spec/session_spec.rb b/spec/session_spec.rb index 9367f683..0436d8b2 100644 --- a/spec/session_spec.rb +++ b/spec/session_spec.rb @@ -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 diff --git a/spec/shared_selenium_node.rb b/spec/shared_selenium_node.rb index 62ffba38..3e490eae 100644 --- a/spec/shared_selenium_node.rb +++ b/spec/shared_selenium_node.rb @@ -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 diff --git a/spec/shared_selenium_session.rb b/spec/shared_selenium_session.rb index 40ed7642..b693ceae 100644 --- a/spec/shared_selenium_session.rb +++ b/spec/shared_selenium_session.rb @@ -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')