From c7874b3f7f8f5a0c19f67e551b0e9c5a1413207f Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Tue, 2 Jan 2018 18:13:39 -0800 Subject: [PATCH] remove conditionals for no longer supported RSpec versions --- .../spec/session/has_selector_spec.rb | 1 - lib/capybara/spec/spec_helper.rb | 4 - spec/rspec/shared_spec_matchers.rb | 156 +++++++++--------- spec/rspec_spec.rb | 6 - spec/spec_helper.rb | 4 - 5 files changed, 77 insertions(+), 94 deletions(-) diff --git a/lib/capybara/spec/session/has_selector_spec.rb b/lib/capybara/spec/session/has_selector_spec.rb index 85106941..3c1e94cc 100644 --- a/lib/capybara/spec/session/has_selector_spec.rb +++ b/lib/capybara/spec/session/has_selector_spec.rb @@ -131,7 +131,6 @@ Capybara::SpecHelper.spec '#has_no_selector?' do end it "should accept a filter block" do - skip "RSpec < 3 doesn't pass the block along to the matcher for the Builtin::Has matcher" if rspec2? expect(@session).to have_no_selector(:css, "a#foo") { |el| el[:id] != "foo" } end diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 8e1d945f..721ad97e 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -108,10 +108,6 @@ module Capybara def marionette?(session) session.driver.respond_to?(:marionette?, true) && session.driver.send(:marionette?) end - - def rspec2? - !defined?(::RSpec::Expectations::Version) || (Gem::Version.new(RSpec::Expectations::Version::STRING) < Gem::Version.new('3.0')) - end end end diff --git a/spec/rspec/shared_spec_matchers.rb b/spec/rspec/shared_spec_matchers.rb index 44071373..d9dd81e0 100644 --- a/spec/rspec/shared_spec_matchers.rb +++ b/spec/rspec/shared_spec_matchers.rb @@ -834,97 +834,95 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| end end - if RSpec::Version::STRING.to_f >= 3.0 - context "compounding", requires: [:js] do - before(:each) do - @session = session - @session.visit('/with_js') - @el = @session.find(:css, '#reload-me') + context "compounding", requires: [:js] do + before(:each) do + @session = session + @session.visit('/with_js') + @el = @session.find(:css, '#reload-me') + end + + context "#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') + expect(Benchmark.realtime do + expect { + expect(@el).to matcher + }.to raise_error RSpec::Expectations::ExpectationNotMetError + end).to be_between(2,3) + end end - context "#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') - expect(Benchmark.realtime do - expect { - expect(@el).to matcher - }.to raise_error RSpec::Expectations::ExpectationNotMetError - end).to be_between(2,3) - end + it "should run 'concurrently' and retry" do + @session.click_link('reload-link') + @session.using_wait_time(2) do + expect(Benchmark.realtime do + expect { + expect(@el).to have_text('waiting to be reloaded').and(have_text('has been reloaded')) + }.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/ + end).to be_between(2,3) end + end - it "should run 'concurrently' and retry" do + it "should ignore :wait options" do + @session.using_wait_time(2) do + matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6) + expect(Benchmark.realtime do + expect { + expect(@el).to matcher + }.to raise_error RSpec::Expectations::ExpectationNotMetError + end).to be_between(2,3) + end + end + + it "should work on the session" do + @session.using_wait_time(2) do @session.click_link('reload-link') - @session.using_wait_time(2) do - expect(Benchmark.realtime do - expect { - expect(@el).to have_text('waiting to be reloaded').and(have_text('has been reloaded')) - }.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/ - end).to be_between(2,3) - end + expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded') end + end + end - it "should ignore :wait options" do - @session.using_wait_time(2) do - matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6) - expect(Benchmark.realtime do - expect { - expect(@el).to matcher - }.to raise_error RSpec::Expectations::ExpectationNotMetError - end).to be_between(2,3) - end - end + context "#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 - it "should work on the session" do - @session.using_wait_time(2) do - @session.click_link('reload-link') - expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded') - end + context "#or" do + it "should run 'concurrently'" do + @session.using_wait_time(3) do + expect(Benchmark.realtime do + expect(@el).to have_text('has been reloaded').or have_text('waiting to be reloaded') + end).to be < 1 end end - context "#and_then" do - it "should run sequentially" do + it "should retry" do + @session.using_wait_time(3) do + expect(Benchmark.realtime do + expect { + expect(@el).to have_text('has been reloaded').or have_text('random stuff') + }.to raise_error RSpec::Expectations::ExpectationNotMetError + end).to be > 3 + end + end + + it "should ignore :wait options" do + @session.using_wait_time(2) do + expect(Benchmark.realtime do + expect { + expect(@el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15) + }.to raise_error RSpec::Expectations::ExpectationNotMetError + end).to be_between(2,3) + end + end + + it "should work on the session" do + @session.using_wait_time(2) 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 - it "should run 'concurrently'" do - @session.using_wait_time(3) do - expect(Benchmark.realtime do - expect(@el).to have_text('has been reloaded').or have_text('waiting to be reloaded') - end).to be < 1 - end - end - - it "should retry" do - @session.using_wait_time(3) do - expect(Benchmark.realtime do - expect { - expect(@el).to have_text('has been reloaded').or have_text('random stuff') - }.to raise_error RSpec::Expectations::ExpectationNotMetError - end).to be > 3 - end - end - - it "should ignore :wait options" do - @session.using_wait_time(2) do - expect(Benchmark.realtime do - expect { - expect(@el).to have_text('this is not there', wait: 10).or have_text('neither is this', wait: 15) - }.to raise_error RSpec::Expectations::ExpectationNotMetError - end).to be_between(2,3) - end - end - - it "should work on the session" do - @session.using_wait_time(2) do - @session.click_link('reload-link') - expect(@session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded') - end + expect(@session).to have_selector(:css, 'h1', text: 'Not on the page').or have_text('has been reloaded') end end end diff --git a/spec/rspec_spec.rb b/spec/rspec_spec.rb index 91b69230..5b1d0d32 100644 --- a/spec/rspec_spec.rb +++ b/spec/rspec_spec.rb @@ -48,8 +48,6 @@ RSpec.describe 'capybara/rspec', :type => :feature do end it "allows access to the RSpec matcher" do - skip "RSpec < 3 doesn't have an `all` matcher" if rspec2? - visit('/with_html') expect(["test1", "test2"]).to all(be_a(String)) end @@ -64,7 +62,6 @@ RSpec.describe 'capybara/rspec', :type => :feature do end it "allows access to the RSpec matcher" do - skip "RSpec version doesn't have a 'within' matcher" unless ::RSpec::Matchers.instance_methods.include?(:within) visit('/with_html') # This reads terribly, but must call #within expect(find(:css, 'span.number').text.to_i).to within(1).of(41) @@ -90,8 +87,6 @@ RSpec.describe 'capybara/rspec', :type => :other do end it "allows access to the RSpec matcher" do - skip "RSpec < 3 doesn't have an `all` matcher" if rspec2? - @test_class_instance.visit('/with_html') expect(["test1", "test2"]).to @test_class_instance.all(be_a(String)) end @@ -106,7 +101,6 @@ RSpec.describe 'capybara/rspec', :type => :other do end it "allows access to the RSpec matcher" do - skip "RSpec version doesn't have a 'within' matcher" unless ::RSpec::Matchers.instance_methods.include?(:within) @test_class_instance.visit('/with_html') # This reads terribly, but must call #within expect(@test_class_instance.find(:css, 'span.number').text.to_i).to @test_class_instance.within(1).of(41) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 06071b1e..71f549ab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,7 +7,3 @@ RSpec.configure do |config| config.filter_run_including focus_: true unless ENV['TRAVIS'] config.run_all_when_everything_filtered = true end - -def rspec2? - !defined?(::RSpec::Expectations::Version) || (Gem::Version.new(RSpec::Expectations::Version::STRING) < Gem::Version.new('3.0')) -end