Skip to content

Commit

Permalink
Relax maximum capybara version constraint
Browse files Browse the repository at this point in the history
fixes #1095
  • Loading branch information
pirj committed Mar 4, 2020
1 parent ba6e397 commit 4700c5f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 94 deletions.
59 changes: 5 additions & 54 deletions 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:

Expand All @@ -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.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.)
Expand Down
11 changes: 4 additions & 7 deletions features/feature_specs/feature_spec.feature
Expand Up @@ -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<br />
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
Expand Down Expand Up @@ -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
"""

Expand Down
6 changes: 3 additions & 3 deletions features/request_specs/request_spec.feature
Expand Up @@ -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:
Expand Down
26 changes: 3 additions & 23 deletions lib/rspec/rails/example/feature_example_group.rb
Expand Up @@ -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
5 changes: 0 additions & 5 deletions lib/rspec/rails/vendor/capybara.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4700c5f

Please sign in to comment.