diff --git a/Capybara.md b/Capybara.md index 2936a242cf..1b878d7319 100644 --- a/Capybara.md +++ b/Capybara.md @@ -1,58 +1,19 @@ rspec-rails supports integration with Capybara out of the box by adding its Capybara::DSL (visit/page) and Capybara::RSpecMatchers to the -examples in the applicable directories, which differ slightly between -Capybara 1.x and Capybara >= 2.x. +examples in the applicable directories. ## Capybara::DSL Adds the `visit` and `page` methods, which work together to simulate a GET request and provide access to the result (via `page`). -## Capybara::RSpecMatchers - -Exposes matchers used to specify expected HTML content (e.g. `should_not have_selector` will work correctly). - -## Capybara 1.x - -Capybara::DSL is added to examples in: - -* spec/requests # included by Capybara -* spec/controllers - -Capybara::RSpecMatchers is added to examples in: - -* spec/requests # included by Capybara -* spec/controllers -* spec/views -* spec/helpers -* spec/mailers - -## Capybara 2.0 - -To use Capybara 2.0, you need rspec-rails-2.11.1 or greater. - Capybara::DSL is added to examples in: * spec/features -Capybara::RSpecMatchers is added to examples in: - -* spec/features -* spec/controllers -* spec/views -* spec/helpers -* spec/mailers - -## Upgrading to Capybara-2.0 - -Many users have been confused by the co-existence of the the -Capybara::DSL (visit/page) alongside the rack-test DSL -(get|post|put|delete|head/response.body) in examples in spec/requests -and spec/controllers. As of rspec-rails-2.11.1 and capybara-2.0.0.beta2, these -are separated as follows: +## Capybara::RSpecMatchers -* Capybara::DSL is included `spec/features` -* rack-test DSL is included in `spec/requests` and `spec/controllers` +Exposes matchers used to specify expected HTML content (e.g. `should_not have_selector` will work correctly). Capybara::RSpecMatchers is added to examples in: @@ -62,16 +23,6 @@ Capybara::RSpecMatchers is added to examples in: * spec/helpers * spec/mailers -If you're upgrading to Capybara-2.0 and you used visit/page in -spec/requests you'll want to move those examples to spec/features and -they should just work. - -If you want to leave those examples in spec/requests, you can include -Capybara::DSL in those examples yourself as follows, but this is -absolutely not recommended as you will be overriding the intended -behavior and accepting the risks associated with doing so: +## Upgrading to Capybara-3.x - # not recommended! - RSpec.configure do |c| - c.include Capybara::DSL, file_path: "spec/requests" - end +Consult the official [Upgrading from Capybara 2.x to 3.x](https://github.com/teamcapybara/capybara/blob/master/UPGRADING.md#upgrading-from-capybara-2x-to-3x) guide. diff --git a/Changelog.md b/Changelog.md index 09cdf602a3..b9bb293b09 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ Bug Fixes: * Allow changing `ActiveJob::Base.queue_adapter` inside a system spec. (Jonathan Rochkind, #2242) * `rails generate generator` command now creates related spec file (Joel Azemar, #2217) +* Relax upper `capybara` version constraint to allow for Capybara 3.x (Phil Pirozhkov, #2281) ### 4.0.0.beta4 [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta3...v4.0.0.beta4) diff --git a/Gemfile b/Gemfile index 355ed6d391..08e770fc7a 100644 --- a/Gemfile +++ b/Gemfile @@ -48,7 +48,7 @@ gem 'rake', '~> 12' gem 'mime-types', "~> 3" -gem 'capybara', '~> 2.13', require: false +gem 'capybara', '>= 2.13', '< 4.0', require: false if MAJOR < 6 gem 'nokogiri', '1.9.1' diff --git a/README.md b/README.md index 7dea4d00ac..b095bbb055 100644 --- a/README.md +++ b/README.md @@ -366,7 +366,7 @@ you can run the specs and Cucumber features, or submit a pull request. ### Recommended third-party extensions * [FactoryBot](https://github.com/thoughtbot/factory_bot) -* [Capybara](https://github.com/jnicklas/capybara) +* [Capybara](https://github.com/teamcapybara/capybara) (Included by default in Rails 5.1+. Note that [additional configuration is required][] to use the Capybara DSL anywhere other than system specs and feature specs.) diff --git a/features/feature_specs/feature_spec.feature b/features/feature_specs/feature_spec.feature index 59558d72d7..d9c28bdbbd 100644 --- a/features/feature_specs/feature_spec.feature +++ b/features/feature_specs/feature_spec.feature @@ -8,12 +8,9 @@ Feature: Feature spec `config.infer_spec_type_from_file_location!` by placing them in `spec/features`. - Feature specs require the [Capybara](https://github.com/jnicklas/capybara) gem, version 2.2.0 or later. We recommend - version 2.4.0 or later to avoid some deprecation warnings and have support for - [`config.expose_dsl_globally = false`](/rspec/rspec-core/docs/configuration/global-namespace-dsl). Refer to the [capybara API
- documentation](https://rubydoc.info/github/jnicklas/capybara/master) for more information on the methods and matchers that can be - used in feature specs. Capybara is intended to simulate browser requests with - HTTP. It will primarily send HTML content. + Feature specs require the [Capybara](https://github.com/teamcapybara/capybara) gem, version 2.13.0 or later. + Refer to the [capybara API documentation](https://rubydoc.info/github/teamcapybara/capybara/master) for more information on the methods and matchers that can be + used in feature specs. Capybara is intended to simulate browser requests with HTTP. It will primarily send HTML content. The `feature` and `scenario` DSL correspond to `describe` and `it`, respectively. These methods are simply aliases that allow feature specs to read more as @@ -45,7 +42,7 @@ Feature: Feature spec Pending: (Failures listed here are expected and do not affect your suite's status) 1) Widget management User creates a new widget - # Feature specs require the Capybara (https://github.com/jnicklas/capybara) gem, version 2.2.0 or later. We recommend version 2.4.0 or later to avoid some deprecation warnings and have support for `config.expose_dsl_globally = false`. + # Feature specs require the Capybara (https://github.com/teamcapybara/capybara) gem, version 2.13.0 or later. # ./spec/features/widget_management_spec.rb:4 """ diff --git a/features/request_specs/request_spec.feature b/features/request_specs/request_spec.feature index 78aaae4fed..5be1b37f23 100644 --- a/features/request_specs/request_spec.feature +++ b/features/request_specs/request_spec.feature @@ -22,9 +22,9 @@ Feature: request spec Check the Rails docs for details on these methods as well. - [Capybara](https://github.com/jnicklas/capybara) is no longer supported in - request specs as of Capybara 2.0.0. The recommended way to use Capybara is - with [feature specs](../feature-specs/feature-spec). + [Capybara](https://github.com/teamcapybara/capybara) is not supported in + request specs. The recommended way to use Capybara is with + [feature specs](../feature-specs/feature-spec). Scenario: specify managing a Widget with Rails integration methods Given a file named "spec/requests/widget_management_spec.rb" with: diff --git a/lib/rspec/rails/example/feature_example_group.rb b/lib/rspec/rails/example/feature_example_group.rb index 9cee0120e0..f92ae13f14 100644 --- a/lib/rspec/rails/example/feature_example_group.rb +++ b/lib/rspec/rails/example/feature_example_group.rb @@ -39,35 +39,15 @@ def visit(*) opts = { capybara_feature: true, type: :feature, - skip: <<-EOT.squish - Feature specs require the Capybara (https://github.com/jnicklas/capybara) - gem, version 2.2.0 or later. We recommend version 2.4.0 or later to avoid - some deprecation warnings and have support for - `config.expose_dsl_globally = false`. + skip: <<~EOT + Feature specs require the Capybara (https://github.com/teamcapybara/capybara) + gem, version 2.13.0 or later. EOT } - # Capybara's monkey patching causes us to have to jump through some hoops - top_level = self - main_feature = nil - if defined?(Capybara) && ::Capybara::VERSION.to_f < 2.4 - # Capybara 2.2 and 2.3 do not use `alias_example_xyz` - opts[:skip] = <<-EOT.squish - Capybara < 2.4.0 does not support RSpec's namespace or - `config.expose_dsl_globally = false`. Upgrade to Capybara >= 2.4.0. - EOT - main_feature = top_level.method(:feature) if top_level.respond_to?(:feature) - end - RSpec.configure do |c| - main_feature = nil unless c.expose_dsl_globally? c.alias_example_group_to :feature, opts c.alias_example_to :scenario c.alias_example_to :xscenario, skip: 'Temporarily skipped with xscenario' end - - # Due to load order issues and `config.expose_dsl_globally?` defaulting to - # `true` we need to put Capybara's monkey patch method back. Otherwise, - # app upgrades have a high likelyhood of having all feature specs skipped. - top_level.define_singleton_method(:feature, &main_feature) if main_feature end diff --git a/lib/rspec/rails/vendor/capybara.rb b/lib/rspec/rails/vendor/capybara.rb index 1d3124c79a..c6c735869a 100644 --- a/lib/rspec/rails/vendor/capybara.rb +++ b/lib/rspec/rails/vendor/capybara.rb @@ -9,11 +9,6 @@ end if defined?(Capybara) - require 'rspec/support/comparable_version' - unless RSpec::Support::ComparableVersion.new(Capybara::VERSION) >= '2.2.0' - raise "You are using capybara #{Capybara::VERSION}. RSpec requires >= 2.2.0." - end - RSpec.configure do |c| if defined?(Capybara::DSL) c.include Capybara::DSL, type: :feature