diff --git a/.rubocop.yml b/.rubocop.yml index ba75512c..5b3a55ba 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,7 +6,6 @@ AllCops: DisabledByDefault: false TargetRubyVersion: 2.4 Exclude: - - 'capybara.gemspec' - 'vendor/**/*' - 'gemfiles/vendor/**/*' @@ -29,6 +28,7 @@ Metrics/BlockLength: Exclude: - 'spec/**/*' - 'lib/capybara/spec/**/*' + - 'capybara.gemspec' Metrics/AbcSize: Enabled: false @@ -107,6 +107,10 @@ Style/NumericLiterals: - 'lib/capybara/spec/**/*' - 'spec/**/*' +Style/SpecialGlobalVars: + Exclude: + - 'capybara.gemspec' + Layout/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true @@ -148,9 +152,6 @@ RSpec/NestedGroups: RSpec/DescribeClass: Enabled: false -RSpec/AnyInstance: - Enabled: false - RSpec/FilePath: Enabled: false diff --git a/capybara.gemspec b/capybara.gemspec index 7024d0b7..dee36538 100644 --- a/capybara.gemspec +++ b/capybara.gemspec @@ -13,7 +13,8 @@ Gem::Specification.new do |s| s.authors = ['Thomas Walpole', 'Jonas Nicklas'] s.email = ['twalpole@gmail.com', 'jonas.nicklas@gmail.com'] - s.description = 'Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website' + s.description = 'Capybara is an integration testing tool for rack based web applications. '\ + 'It simulates how a user would interact with a website' s.files = Dir.glob('{lib,spec}/**/*') + %w[README.md History.md License.txt] @@ -23,7 +24,8 @@ Gem::Specification.new do |s| 'source_code_uri' => 'https://github.com/teamcapybara/capybara' } s.require_paths = ['lib'] - s.summary = 'Capybara aims to simplify the process of integration testing Rack applications, such as Rails, Sinatra or Merb' + s.summary = 'Capybara aims to simplify the process of integration testing Rack applications, '\ + 'such as Rails, Sinatra or Merb' s.add_runtime_dependency('addressable') s.add_runtime_dependency('mini_mime', ['>= 0.1.3']) diff --git a/lib/capybara/spec/session/assert_current_path_spec.rb b/lib/capybara/spec/session/assert_current_path_spec.rb index b532c094..9f80342d 100644 --- a/lib/capybara/spec/session/assert_current_path_spec.rb +++ b/lib/capybara/spec/session/assert_current_path_spec.rb @@ -37,7 +37,9 @@ Capybara::SpecHelper.spec '#assert_current_path' do end it 'should not cause an exception when current_url is nil' do - allow_any_instance_of(Capybara::Session).to receive(:current_url).and_return(nil) + allow(@session).to receive(:current_url).and_return(nil) + allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page + expect { @session.assert_current_path(nil) }.not_to raise_error end end @@ -65,7 +67,8 @@ Capybara::SpecHelper.spec '#assert_no_current_path?' do end it 'should not cause an exception when current_url is nil' do - allow_any_instance_of(Capybara::Session).to receive(:current_url).and_return(nil) + allow(@session).to receive(:current_url).and_return(nil) + allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page expect { @session.assert_no_current_path('/with_html') }.not_to raise_error end diff --git a/lib/capybara/spec/session/find_spec.rb b/lib/capybara/spec/session/find_spec.rb index 8378285d..75a2d57c 100644 --- a/lib/capybara/spec/session/find_spec.rb +++ b/lib/capybara/spec/session/find_spec.rb @@ -107,8 +107,8 @@ Capybara::SpecHelper.spec '#find' do end it 'should warn if passed a non-valid locator type' do - expect_any_instance_of(Kernel).to receive(:warn).with(/must respond to to_xpath or be an instance of String/) - expect { @session.find(:xpath, 123) }.to raise_error Exception # The exact error is not yet well defined + expect { @session.find(:xpath, 123) }.to raise_error(Exception) # The exact error is not yet well defined + .and output(/must respond to to_xpath or be an instance of String/).to_stderr end end @@ -263,9 +263,8 @@ Capybara::SpecHelper.spec '#find' do end it 'warns when the option has no effect' do - expect_any_instance_of(Kernel).to receive(:warn) - .with('The :exact option only has an effect on queries using the XPath#is method. Using it with the query "#test_field" has no effect.') - @session.find(:css, '#test_field', exact: true) + expect { @session.find(:css, '#test_field', exact: true) }.to \ + output(/^The :exact option only has an effect on queries using the XPath#is method. Using it with the query "#test_field" has no effect/).to_stderr end end diff --git a/lib/capybara/spec/session/has_current_path_spec.rb b/lib/capybara/spec/session/has_current_path_spec.rb index e41b2653..3c1cf956 100644 --- a/lib/capybara/spec/session/has_current_path_spec.rb +++ b/lib/capybara/spec/session/has_current_path_spec.rb @@ -81,7 +81,8 @@ Capybara::SpecHelper.spec '#has_current_path?' do end it 'should not raise an exception if the current_url is nil' do - allow_any_instance_of(Capybara::Session).to receive(:current_url).and_return(nil) + allow(@session).to receive(:current_url).and_return(nil) + allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page # Without ignore_query option expect do @@ -121,7 +122,8 @@ Capybara::SpecHelper.spec '#has_no_current_path?' do end it 'should not raise an exception if the current_url is nil' do - allow_any_instance_of(Capybara::Session).to receive(:current_url).and_return(nil) + allow(@session).to receive(:current_url).and_return(nil) + allow(@session.page).to receive(:current_url).and_return(nil) if @session.respond_to? :page # Without ignore_query option expect do diff --git a/lib/capybara/spec/session/matches_style_spec.rb b/lib/capybara/spec/session/matches_style_spec.rb index 3d514c9c..ec8a7a47 100644 --- a/lib/capybara/spec/session/matches_style_spec.rb +++ b/lib/capybara/spec/session/matches_style_spec.rb @@ -24,8 +24,8 @@ Capybara::SpecHelper.spec '#matches_style?', requires: [:css] do end it 'deprecated has_style?' do - expect_any_instance_of(Kernel).to receive(:warn).once - have_style(display: /^bl/) + expect { have_style(display: /^bl/) }.to \ + output(/have_style is deprecated/).to_stderr el = @session.find(:css, '#first') allow(el).to receive(:warn).and_return(nil) diff --git a/lib/capybara/spec/session/select_spec.rb b/lib/capybara/spec/session/select_spec.rb index 40735275..cb6c5ae5 100644 --- a/lib/capybara/spec/session/select_spec.rb +++ b/lib/capybara/spec/session/select_spec.rb @@ -143,8 +143,8 @@ Capybara::SpecHelper.spec '#select' do end it 'should warn' do - expect_any_instance_of(Capybara::Node::Element).to receive(:warn).once - @session.select('Other', from: 'form_title') + expect { @session.select('Other', from: 'form_title') }.to \ + output(/^Attempt to select disabled option: Other/).to_stderr end end diff --git a/spec/rack_test_spec.rb b/spec/rack_test_spec.rb index f0827892..18321876 100644 --- a/spec/rack_test_spec.rb +++ b/spec/rack_test_spec.rb @@ -80,11 +80,11 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes describe '#fill_in' do it 'should warn that :fill_options are not supported' do - allow_any_instance_of(Capybara::RackTest::Node).to receive(:warn) session.visit '/with_html' - field = session.fill_in 'test_field', with: 'not_monkey', fill_options: { random: true } + + expect { session.fill_in 'test_field', with: 'not_monkey', fill_options: { random: true } }.to \ + output(/^Options passed to Node#set but the RackTest driver doesn't support any - ignoring/).to_stderr expect(session).to have_field('test_field', with: 'not_monkey') - expect(field.base).to have_received(:warn).with("Options passed to Node#set but the RackTest driver doesn't support any - ignoring") end end diff --git a/spec/result_spec.rb b/spec/result_spec.rb index a0048ae0..f5f79001 100644 --- a/spec/result_spec.rb +++ b/spec/result_spec.rb @@ -85,25 +85,6 @@ RSpec.describe Capybara::Result do expect(result.size).to eq 1 end - it 'should catch invalid element errors during filtering' do - allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError) - allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return( - instance_double('Capybara::Session', driver: instance_double('Capybara::Driver::Base', invalid_element_errors: [StandardError], wait?: false)) - ) - result = string.all('//li', text: 'Alpha') - expect(result.size).to eq 0 - end - - it 'should return non-invalid element errors during filtering' do - allow_any_instance_of(Capybara::Node::Simple).to receive(:text).and_raise(StandardError) - allow_any_instance_of(Capybara::Node::Simple).to receive(:session).and_return( - instance_double('Capybara::Session', driver: instance_double('Capybara::Driver::Base', invalid_element_errors: [ArgumentError], wait?: false)) - ) - expect do - string.all('//li', text: 'Alpha').to_a - end.to raise_error(StandardError) - end - # Not a great test but it indirectly tests what is needed it 'should evaluate filters lazily for idx' do skip 'JRuby has an issue with lazy enumerator evaluation' if jruby_lazy_enumerator_workaround? diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0ef0403a..de674ce4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -67,6 +67,9 @@ RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.syntax = :expect end + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end config.filter_run_including focus_: true unless ENV['CI'] config.run_all_when_everything_filtered = true config.after(:suite) { SeleniumStatistics.print_results }