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

remove conditionals for no longer supported RSpec versions

This commit is contained in:
Thomas Walpole 2018-01-02 18:13:39 -08:00
parent b5e5fd308f
commit c7874b3f7f
5 changed files with 77 additions and 94 deletions

View file

@ -131,7 +131,6 @@ Capybara::SpecHelper.spec '#has_no_selector?' do
end end
it "should accept a filter block" do 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" } expect(@session).to have_no_selector(:css, "a#foo") { |el| el[:id] != "foo" }
end end

View file

@ -108,10 +108,6 @@ module Capybara
def marionette?(session) def marionette?(session)
session.driver.respond_to?(:marionette?, true) && session.driver.send(:marionette?) session.driver.respond_to?(:marionette?, true) && session.driver.send(:marionette?)
end end
def rspec2?
!defined?(::RSpec::Expectations::Version) || (Gem::Version.new(RSpec::Expectations::Version::STRING) < Gem::Version.new('3.0'))
end
end end
end end

View file

@ -834,97 +834,95 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode|
end end
end end
if RSpec::Version::STRING.to_f >= 3.0 context "compounding", requires: [:js] do
context "compounding", requires: [:js] do before(:each) do
before(:each) do @session = session
@session = session @session.visit('/with_js')
@session.visit('/with_js') @el = @session.find(:css, '#reload-me')
@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 end
context "#and" do it "should run 'concurrently' and retry" do
it "should run 'concurrently'" do @session.click_link('reload-link')
Capybara.using_wait_time(2) do @session.using_wait_time(2) do
matcher = have_text('this is not there').and have_text('neither is this') expect(Benchmark.realtime do
expect(Benchmark.realtime do expect {
expect { expect(@el).to have_text('waiting to be reloaded').and(have_text('has been reloaded'))
expect(@el).to matcher }.to raise_error RSpec::Expectations::ExpectationNotMetError, /expected to find text "waiting to be reloaded" in "has been reloaded"/
}.to raise_error RSpec::Expectations::ExpectationNotMetError end).to be_between(2,3)
end).to be_between(2,3)
end
end 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.click_link('reload-link')
@session.using_wait_time(2) do expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded')
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 end
end
end
it "should ignore :wait options" do context "#and_then" do
@session.using_wait_time(2) do it "should run sequentially" do
matcher = have_text('this is not there', wait: 5).and have_text('neither is this', wait: 6) @session.click_link('reload-link')
expect(Benchmark.realtime do expect(@el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded')
expect { end
expect(@el).to matcher end
}.to raise_error RSpec::Expectations::ExpectationNotMetError
end).to be_between(2,3)
end
end
it "should work on the session" do context "#or" do
@session.using_wait_time(2) do it "should run 'concurrently'" do
@session.click_link('reload-link') @session.using_wait_time(3) do
expect(@session).to have_selector(:css, 'h1', text: 'FooBar').and have_text('has been reloaded') expect(Benchmark.realtime do
end expect(@el).to have_text('has been reloaded').or have_text('waiting to be reloaded')
end).to be < 1
end end
end end
context "#and_then" do it "should retry" do
it "should run sequentially" 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') @session.click_link('reload-link')
expect(@el).to have_text('waiting to be reloaded').and_then have_text('has been reloaded') expect(@session).to have_selector(:css, 'h1', text: 'Not on the page').or 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
end end
end end
end end

View file

@ -48,8 +48,6 @@ RSpec.describe 'capybara/rspec', :type => :feature do
end end
it "allows access to the RSpec matcher" do it "allows access to the RSpec matcher" do
skip "RSpec < 3 doesn't have an `all` matcher" if rspec2?
visit('/with_html') visit('/with_html')
expect(["test1", "test2"]).to all(be_a(String)) expect(["test1", "test2"]).to all(be_a(String))
end end
@ -64,7 +62,6 @@ RSpec.describe 'capybara/rspec', :type => :feature do
end end
it "allows access to the RSpec matcher" do 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') visit('/with_html')
# This reads terribly, but must call #within # This reads terribly, but must call #within
expect(find(:css, 'span.number').text.to_i).to within(1).of(41) 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 end
it "allows access to the RSpec matcher" do 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') @test_class_instance.visit('/with_html')
expect(["test1", "test2"]).to @test_class_instance.all(be_a(String)) expect(["test1", "test2"]).to @test_class_instance.all(be_a(String))
end end
@ -106,7 +101,6 @@ RSpec.describe 'capybara/rspec', :type => :other do
end end
it "allows access to the RSpec matcher" do 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') @test_class_instance.visit('/with_html')
# This reads terribly, but must call #within # 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) expect(@test_class_instance.find(:css, 'span.number').text.to_i).to @test_class_instance.within(1).of(41)

View file

@ -7,7 +7,3 @@ RSpec.configure do |config|
config.filter_run_including focus_: true unless ENV['TRAVIS'] config.filter_run_including focus_: true unless ENV['TRAVIS']
config.run_all_when_everything_filtered = true config.run_all_when_everything_filtered = true
end end
def rspec2?
!defined?(::RSpec::Expectations::Version) || (Gem::Version.new(RSpec::Expectations::Version::STRING) < Gem::Version.new('3.0'))
end