From 05945bf2d983a89a5ddb6e02e2a7c613bac012a5 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Wed, 17 Aug 2016 11:41:40 -0700 Subject: [PATCH] remove conditionals for no longer supported versions of gems/rubies --- .travis.yml | 19 ----- History.md | 3 + README.md | 4 +- capybara.gemspec | 20 +++-- gemfiles/Gemfile.base-versions | 14 ++-- lib/capybara/rails.rb | 7 +- lib/capybara/result.rb | 10 +-- lib/capybara/rspec/features.rb | 74 ++++++------------- lib/capybara/rspec/matchers.rb | 7 +- .../session/element/matches_selector_spec.rb | 2 +- lib/capybara/spec/session/node_spec.rb | 18 +---- spec/rspec/features_spec.rb | 22 +++--- spec/rspec/scenarios_spec.rb | 8 +- spec/rspec/shared_spec_matchers.rb | 28 +++---- spec/spec_helper.rb | 1 - 15 files changed, 78 insertions(+), 159 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67815cbb..fa1a7207 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,25 +36,6 @@ matrix: - gemfile: Gemfile rvm: 2.4.3 env: HEADLESS=true - - gemfile: gemfiles/Gemfile.ruby-20 - env: - - CAPYBARA_LEGACY_FF=true - rvm: 2.0.0 - addons: - firefox: 47.0.1 - apt: - packages: - - awesome - - gemfile: gemfiles/Gemfile.base-versions - env: - - CAPYBARA_LEGACY_FF=true - - SKIP_WINDOW=true - rvm: 1.9.3 - addons: - firefox: 47.0.1 - apt: - packages: - - awesome - gemfile: gemfiles/Gemfile.beta-versions rvm: 2.5.0 env: CAPYBARA_FF=true diff --git a/History.md b/History.md index 2177cc7f..e5eb89f5 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,6 @@ +# Version 3.0.0 +Release date: unreleased + # Version 2.17.0 Release date: 2018-01-02 diff --git a/README.md b/README.md index 14be47d7..e69f0c10 100644 --- a/README.md +++ b/README.md @@ -71,15 +71,13 @@ GitHub): http://groups.google.com/group/ruby-capybara ## Setup -Capybara requires Ruby 1.9.3 or later. To install, add this line to your +Capybara requires Ruby 2.0.0 or later. To install, add this line to your `Gemfile` and run `bundle install`: ```ruby gem 'capybara' ``` -**Note:** If using Ruby < 2.0 you will also need to limit the version of rack to < 2.0 - If the application that you are testing is a Rails app, add this line to your test helper file: ```ruby diff --git a/capybara.gemspec b/capybara.gemspec index 6e32503e..e90dbfd9 100644 --- a/capybara.gemspec +++ b/capybara.gemspec @@ -7,7 +7,7 @@ require 'capybara/version' Gem::Specification.new do |s| s.name = "capybara" s.version = Capybara::VERSION - s.required_ruby_version = ">= 1.9.3" + s.required_ruby_version = ">= 2.0.0" s.license = "MIT" s.authors = ["Thomas Walpole", "Jonas Nicklas"] @@ -21,24 +21,22 @@ Gem::Specification.new do |s| s.rubygems_version = "1.3.6" s.summary = "Capybara aims to simplify the process of integration testing Rack applications, such as Rails, Sinatra or Merb" - s.add_runtime_dependency("nokogiri", [">= 1.3.3"]) - s.add_runtime_dependency("mini_mime", [">= 0.1.3"]) - s.add_runtime_dependency("rack", [">= 1.0.0"]) - s.add_runtime_dependency("rack-test", [">= 0.5.4"]) + s.add_runtime_dependency("nokogiri", [">= 1.6.7"]) + s.add_runtime_dependency("mime-types", [">= 3.0"]) + s.add_runtime_dependency("rack", [">= 1.6.0"]) + s.add_runtime_dependency("rack-test", [">= 0.6.3"]) s.add_runtime_dependency("xpath", [">= 2.0", "< 4.0"]) s.add_runtime_dependency("addressable") - s.add_development_dependency("selenium-webdriver", [">= 2.0", "< 4.0", "!=3.4.1"]) - s.add_development_dependency("sinatra", [">= 0.9.4"]) - s.add_development_dependency("rspec", [">= 2.2.0"]) + s.add_development_dependency("selenium-webdriver", [">= 3.0", "< 4.0", "!=3.4.1"]) + s.add_development_dependency("sinatra", [">= 1.4.0"]) + s.add_development_dependency("rspec", [">= 3.4.0"]) s.add_development_dependency("launchy", [">= 2.0.4"]) s.add_development_dependency("yard", [">= 0.5.8"]) s.add_development_dependency("fuubar", [">= 0.0.1"]) - s.add_development_dependency("cucumber", [">= 0.10.5"]) - s.add_development_dependency("minitest") + s.add_development_dependency("cucumber", [">= 2.3.0"]) s.add_development_dependency("rake") s.add_development_dependency("puma") - s.add_development_dependency("pry") s.add_development_dependency("erubi") # dependency specification needed by rbx if RUBY_ENGINE == 'rbx' then diff --git a/gemfiles/Gemfile.base-versions b/gemfiles/Gemfile.base-versions index 899090d4..bdbf05b1 100644 --- a/gemfiles/Gemfile.base-versions +++ b/gemfiles/Gemfile.base-versions @@ -5,13 +5,13 @@ gemspec :path => '..' gem 'xpath', '~> 2.1.0' -gem 'rack', '= 1.3.0' # cannot go lower because referer tests need aa7ce77cd0 -gem 'rack-test', '= 0.5.4' -gem 'nokogiri', '= 1.3.3' -gem 'rspec', '= 2.2.0' -gem 'cucumber', '= 0.10.5' -gem 'tins', '= 1.6.0' # 1.7.0 requires ruby 2.0 -gem 'addressable', '< 2.4.0' # 2.4.0 allows require 'addressable' previous don't +gem 'rack', '~> 1.6.0' +gem 'rack-test', '= 0.6.3' +gem 'nokogiri', '= 1.6.7' +gem 'rspec', '= 3.4.0' +gem 'cucumber', '= 2.3.0' +gem 'mime-types', '= 3.0' +gem 'addressable', '2.4.0' gem 'json', '< 2.0' gem 'rake', '< 11.0' diff --git a/lib/capybara/rails.rb b/lib/capybara/rails.rb index 8f686610..9a283b36 100644 --- a/lib/capybara/rails.rb +++ b/lib/capybara/rails.rb @@ -3,12 +3,7 @@ require 'capybara/dsl' Capybara.app = Rack::Builder.new do map "/" do - if Gem::Version.new(Rails.version) >= Gem::Version.new("3.0") - run Rails.application - else # Rails 2 - use Rails::Rack::Static - run ActionController::Dispatcher.new - end + run Rails.application end end.to_app diff --git a/lib/capybara/result.rb b/lib/capybara/result.rb index 5d17fc28..13bf5f9e 100644 --- a/lib/capybara/result.rb +++ b/lib/capybara/result.rb @@ -26,7 +26,7 @@ module Capybara def initialize(elements, query) @elements = elements @result_cache = [] - @results_enum = lazy_select_elements { |node| query.matches_filters?(node) } + @results_enum = @elements.lazy_select_elements { |node| query.matches_filters?(node) } @query = query end @@ -138,14 +138,8 @@ module Capybara # https://github.com/jruby/jruby/issues/4212 if RUBY_PLATFORM == 'java' @elements.select(&block).to_enum # non-lazy evaluation - elsif @elements.respond_to? :lazy #Ruby 2.0+ - @elements.lazy.select(&block) else - Enumerator.new do |yielder| - @elements.each do |val| - yielder.yield(val) if block.call(val) - end - end + @elements.lazy.select(&block) end end end diff --git a/lib/capybara/rspec/features.rb b/lib/capybara/rspec/features.rb index f6a9c3dc..c416c554 100644 --- a/lib/capybara/rspec/features.rb +++ b/lib/capybara/rspec/features.rb @@ -1,56 +1,24 @@ # frozen_string_literal: true -if RSpec::Core::Version::STRING.to_f >= 3.0 - RSpec.shared_context "Capybara Features", capybara_feature: true do - instance_eval do - alias background before - alias given let - alias given! let! - end - end - - # ensure shared_context is included if default shared_context_metadata_behavior is changed - if RSpec::Core::Version::STRING.to_f >= 3.5 - RSpec.configure do |config| - config.include_context "Capybara Features", capybara_feature: true - end - end - - RSpec.configure do |config| - config.alias_example_group_to :feature, capybara_feature: true, type: :feature - config.alias_example_group_to :xfeature, capybara_feature: true, type: :feature, skip: "Temporarily disabled with xfeature" - config.alias_example_group_to :ffeature, capybara_feature: true, type: :feature, focus: true - config.alias_example_to :scenario - config.alias_example_to :xscenario, skip: "Temporarily disabled with xscenario" - config.alias_example_to :fscenario, focus: true - end -else - module Capybara - module Features - def self.included(base) - base.instance_eval do - alias :background :before - alias :scenario :it - alias :xscenario :xit - alias :given :let - alias :given! :let! - alias :feature :describe - end - end - end - end - - def self.feature(*args, &block) - options = if args.last.is_a?(Hash) then args.pop else {} end - options[:capybara_feature] = true - options[:type] = :feature - options[:caller] ||= caller - args.push(options) - - #call describe on RSpec in case user has expose_dsl_globally set to false - RSpec.describe(*args, &block) - end - - RSpec.configure do |config| - config.include(Capybara::Features, capybara_feature: true) +RSpec.shared_context "Capybara Features", capybara_feature: true do + instance_eval do + alias background before + alias given let + alias given! let! end end + +# ensure shared_context is included if default shared_context_metadata_behavior is changed +if RSpec::Core::Version::STRING.to_f >= 3.5 + RSpec.configure do |config| + config.include_context "Capybara Features", capybara_feature: true + end +end + +RSpec.configure do |config| + config.alias_example_group_to :feature, capybara_feature: true, type: :feature + config.alias_example_group_to :xfeature, capybara_feature: true, type: :feature, skip: "Temporarily disabled with xfeature" + config.alias_example_group_to :ffeature, capybara_feature: true, type: :feature, focus: true + config.alias_example_to :scenario + config.alias_example_to :xscenario, skip: "Temporarily disabled with xscenario" + config.alias_example_to :fscenario, focus: true +end diff --git a/lib/capybara/rspec/matchers.rb b/lib/capybara/rspec/matchers.rb index 29092627..eadfe54f 100644 --- a/lib/capybara/rspec/matchers.rb +++ b/lib/capybara/rspec/matchers.rb @@ -2,7 +2,7 @@ module Capybara module RSpecMatchers class Matcher - if defined?(::RSpec::Expectations::Version) && (Gem::Version.new(RSpec::Expectations::Version::STRING) >= Gem::Version.new('3.0')) + if defined?(::RSpec::Expectations::Version) require 'capybara/rspec/compound' include ::Capybara::RSpecMatchers::Compound end @@ -265,9 +265,8 @@ module Capybara def match_selector(*args, &optional_filter_block) MatchSelector.new(*args, &optional_filter_block) end - # defined_negated_matcher was added in RSpec 3.1 - it's syntactic sugar only since a user can do - # expect(page).not_to match_selector, so not sure we really need to support not_match_selector for prior to RSpec 3.1 - ::RSpec::Matchers.define_negated_matcher :not_match_selector, :match_selector if defined?(::RSpec::Expectations::Version) && (Gem::Version.new(RSpec::Expectations::Version::STRING) >= Gem::Version.new('3.1')) + + ::RSpec::Matchers.define_negated_matcher :not_match_selector, :match_selector # RSpec matcher for whether elements(s) matching a given xpath selector exist diff --git a/lib/capybara/spec/session/element/matches_selector_spec.rb b/lib/capybara/spec/session/element/matches_selector_spec.rb index ed1cdf80..9076d25e 100644 --- a/lib/capybara/spec/session/element/matches_selector_spec.rb +++ b/lib/capybara/spec/session/element/matches_selector_spec.rb @@ -103,4 +103,4 @@ Capybara::SpecHelper.spec '#not_matches_selector?' do expect(@element.not_matches_xpath?("//span", text: "42")).to be false expect(@element.not_matches_xpath?("//span", text: "Doesnotexist")).to be true end -end if Gem::Version.new(RSpec::Expectations::Version::STRING) >= Gem::Version.new('3.1') +end diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index 1216939c..dc2e296c 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -102,26 +102,14 @@ Capybara::SpecHelper.spec "node" do expect(@session.first('//input').value).to eq('') end - it "should not set if the text field is readonly" do - expect(@session.first('//input[@readonly]').value).to eq('should not change') - @session.first('//input[@readonly]').set('changed') - expect(@session.first('//input[@readonly]').value).to eq('should not change') + it "should raise if the text field is readonly" do + expect { @session.first('//input[@readonly]').set('changed') }.to raise_error(Capybara::ReadOnlyElementError) end it "should raise if the text field is readonly" do - expect(@session.first('//input[@readonly]').set('changed')).to raise_error(Capybara::ReadOnlyElementError) - end if Capybara::VERSION.to_f > 3.0 - - it "should not set if the textarea is readonly" do - expect(@session.first('//textarea[@readonly]').value).to eq('textarea should not change') - @session.first('//textarea[@readonly]').set('changed') - expect(@session.first('//textarea[@readonly]').value).to eq('textarea should not change') + expect { @session.first('//textarea[@readonly]').set('changed') }.to raise_error(Capybara::ReadOnlyElementError) end - it "should raise if the text field is readonly" do - expect(@session.first('//textarea[@readonly]').set('changed')).to raise_error(Capybara::ReadOnlyElementError) - end if Capybara::VERSION.to_f > 3.0 - context "with a contenteditable element", requires: [:js] do it 'should allow me to change the contents' do @session.visit('/with_js') diff --git a/spec/rspec/features_spec.rb b/spec/rspec/features_spec.rb index 3ff97694..d0da2141 100644 --- a/spec/rspec/features_spec.rb +++ b/spec/rspec/features_spec.rb @@ -77,19 +77,17 @@ feature "Capybara's feature DSL with driver", :driver => :culerity do end end -if RSpec::Core::Version::STRING.to_f >= 3.0 - xfeature "if xfeature aliases to pending then" do - scenario "this should be 'temporarily disabled with xfeature'" do; end - scenario "this also should be 'temporarily disabled with xfeature'" do; end +xfeature "if xfeature aliases to pending then" do + scenario "this should be 'temporarily disabled with xfeature'" do; end + scenario "this also should be 'temporarily disabled with xfeature'" do; end +end + +ffeature "if ffeature aliases focused tag then" do + scenario "scenario inside this feature has metatag focus tag" do |example| + expect(example.metadata[:focus]).to eq true end - ffeature "if ffeature aliases focused tag then" do - scenario "scenario inside this feature has metatag focus tag" do |example| - expect(example.metadata[:focus]).to eq true - end - - scenario "other scenarios also has metatag focus tag " do |example| - expect(example.metadata[:focus]).to eq true - end + scenario "other scenarios also has metatag focus tag " do |example| + expect(example.metadata[:focus]).to eq true end end diff --git a/spec/rspec/scenarios_spec.rb b/spec/rspec/scenarios_spec.rb index 1c158784..5b8e412a 100644 --- a/spec/rspec/scenarios_spec.rb +++ b/spec/rspec/scenarios_spec.rb @@ -6,11 +6,9 @@ RSpec.configuration.before(:each, { file_path: "./spec/rspec/scenarios_spec.rb" @in_filtered_hook = true end -if RSpec::Core::Version::STRING.to_f >= 3.0 - feature "if fscenario aliases focused tag then" do - fscenario "scenario should have focused meta tag" do |example| - expect(example.metadata[:focus]).to eq true - end +feature "if fscenario aliases focused tag then" do + fscenario "scenario should have focused meta tag" do |example| + expect(example.metadata[:focus]).to eq true end end diff --git a/spec/rspec/shared_spec_matchers.rb b/spec/rspec/shared_spec_matchers.rb index 63058c25..44071373 100644 --- a/spec/rspec/shared_spec_matchers.rb +++ b/spec/rspec/shared_spec_matchers.rb @@ -81,7 +81,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect("

Text

Text

").to have_css('h1').and have_css('h2') expect("

Text

Text

").to have_css('h3').or have_css('h1') - end if RSpec::Version::STRING.to_f >= 3.0 + end end context "on a page or node" do @@ -148,7 +148,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect("

Text

Text

").to have_xpath('//h1').and have_xpath('//h2') expect("

Text

Text

").to have_xpath('//h3').or have_xpath('//h1') - end if RSpec::Version::STRING.to_f >= 3.0 + end end context "on a page or node" do @@ -254,7 +254,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect("

Text

Text

").to have_selector('//h1').and have_selector('//h2') expect("

Text

Text

").to have_selector('//h3').or have_selector('//h1') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_content matcher" do @@ -343,7 +343,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect("

Text

And

").to have_content('Text').and have_content('And') expect("

Text

Or

").to have_content('XYZ').or have_content('Or') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_text matcher" do @@ -477,7 +477,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect("

Text

And

").to have_text('Text').and have_text('And') expect("

Text

Or

").to have_text('Not here').or have_text('Or') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_link matcher" do @@ -500,7 +500,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect(html).to have_link('Just a link').and have_link('Another link') expect(html).to have_link('Not a link').or have_link('Another link') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_title matcher" do @@ -565,7 +565,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect("I compound").to have_title('I dont compound').or have_title('I compound') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_current_path matcher" do @@ -611,7 +611,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do visit('/with_html') expect(page).to have_current_path('/not_with_html').or have_current_path('/with_html') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_button matcher" do @@ -633,7 +633,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect(html).to have_button('Not this button').or have_button('A button') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_field matcher" do @@ -678,7 +678,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect(html).to have_field('Not this one').or have_field('Text field') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_checked_field matcher" do @@ -727,7 +727,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect(html).to have_checked_field('not this one').or have_checked_field('it is checked') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_unchecked_field matcher" do @@ -776,7 +776,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect(html).to have_unchecked_field('it is checked').or have_unchecked_field('unchecked field') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_select matcher" do @@ -802,7 +802,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect(html).to have_select('Not this one').or have_select('Select Box') - end if RSpec::Version::STRING.to_f >= 3.0 + end end describe "have_table matcher" do @@ -831,7 +831,7 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, mode| it "supports compounding" do expect(html).to have_table('nope').or have_table('Lovely table') - end if RSpec::Version::STRING.to_f >= 3.0 + end end if RSpec::Version::STRING.to_f >= 3.0 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b83be449..06071b1e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'rspec/expectations' require "capybara/spec/spec_helper" -require "pry" RSpec.configure do |config| Capybara::SpecHelper.configure(config)