Skip to content

Commit dc5d3e3

Browse files
committed
Relax maximum capybara version constraint
fixes #1095
1 parent ba6e397 commit dc5d3e3

File tree

8 files changed

+17
-93
lines changed

8 files changed

+17
-93
lines changed

Capybara.md

+5-54
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,19 @@
11
rspec-rails supports integration with Capybara out of the box by adding
22
its Capybara::DSL (visit/page) and Capybara::RSpecMatchers to the
3-
examples in the applicable directories, which differ slightly between
4-
Capybara 1.x and Capybara >= 2.x.
3+
examples in the applicable directories.
54

65
## Capybara::DSL
76

87
Adds the `visit` and `page` methods, which work together to simulate a
98
GET request and provide access to the result (via `page`).
109

11-
## Capybara::RSpecMatchers
12-
13-
Exposes matchers used to specify expected HTML content (e.g. `should_not have_selector` will work correctly).
14-
15-
## Capybara 1.x
16-
17-
Capybara::DSL is added to examples in:
18-
19-
* spec/requests # included by Capybara
20-
* spec/controllers
21-
22-
Capybara::RSpecMatchers is added to examples in:
23-
24-
* spec/requests # included by Capybara
25-
* spec/controllers
26-
* spec/views
27-
* spec/helpers
28-
* spec/mailers
29-
30-
## Capybara 2.0
31-
32-
To use Capybara 2.0, you need rspec-rails-2.11.1 or greater.
33-
3410
Capybara::DSL is added to examples in:
3511

3612
* spec/features
3713

38-
Capybara::RSpecMatchers is added to examples in:
39-
40-
* spec/features
41-
* spec/controllers
42-
* spec/views
43-
* spec/helpers
44-
* spec/mailers
45-
46-
## Upgrading to Capybara-2.0
47-
48-
Many users have been confused by the co-existence of the the
49-
Capybara::DSL (visit/page) alongside the rack-test DSL
50-
(get|post|put|delete|head/response.body) in examples in spec/requests
51-
and spec/controllers. As of rspec-rails-2.11.1 and capybara-2.0.0.beta2, these
52-
are separated as follows:
14+
## Capybara::RSpecMatchers
5315

54-
* Capybara::DSL is included `spec/features`
55-
* rack-test DSL is included in `spec/requests` and `spec/controllers`
16+
Exposes matchers used to specify expected HTML content (e.g. `should_not have_selector` will work correctly).
5617

5718
Capybara::RSpecMatchers is added to examples in:
5819

@@ -62,16 +23,6 @@ Capybara::RSpecMatchers is added to examples in:
6223
* spec/helpers
6324
* spec/mailers
6425

65-
If you're upgrading to Capybara-2.0 and you used visit/page in
66-
spec/requests you'll want to move those examples to spec/features and
67-
they should just work.
68-
69-
If you want to leave those examples in spec/requests, you can include
70-
Capybara::DSL in those examples yourself as follows, but this is
71-
absolutely not recommended as you will be overriding the intended
72-
behavior and accepting the risks associated with doing so:
26+
## Upgrading to Capybara-3.x
7327

74-
# not recommended!
75-
RSpec.configure do |c|
76-
c.include Capybara::DSL, file_path: "spec/requests"
77-
end
28+
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.

Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Bug Fixes:
88
* Allow changing `ActiveJob::Base.queue_adapter` inside a system spec.
99
(Jonathan Rochkind, #2242)
1010
* `rails generate generator` command now creates related spec file (Joel Azemar, #2217)
11+
* Relax upper `capybara` version constraint to allow for Capybara 3.x (Phil Pirozhkov, #2281)
1112

1213
### 4.0.0.beta4
1314
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta3...v4.0.0.beta4)

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ gem 'rake', '~> 12'
4848

4949
gem 'mime-types', "~> 3"
5050

51-
gem 'capybara', '~> 2.13', require: false
51+
gem 'capybara', '>= 2.13', '< 4.0', require: false
5252

5353
if MAJOR < 6
5454
gem 'nokogiri', '1.9.1'

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ you can run the specs and Cucumber features, or submit a pull request.
366366
### Recommended third-party extensions
367367

368368
* [FactoryBot](https://github.com/thoughtbot/factory_bot)
369-
* [Capybara](https://github.com/jnicklas/capybara)
369+
* [Capybara](https://github.com/teamcapybara/capybara)
370370
(Included by default in Rails 5.1+.
371371
Note that [additional configuration is required][] to use the Capybara DSL
372372
anywhere other than system specs and feature specs.)

features/feature_specs/feature_spec.feature

+4-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ Feature: Feature spec
88
`config.infer_spec_type_from_file_location!` by placing them in
99
`spec/features`.
1010

11-
Feature specs require the [Capybara](https://github.com/jnicklas/capybara) gem, version 2.2.0 or later. We recommend
12-
version 2.4.0 or later to avoid some deprecation warnings and have support for
13-
[`config.expose_dsl_globally = false`](/rspec/rspec-core/docs/configuration/global-namespace-dsl). Refer to the [capybara API<br />
14-
documentation](https://rubydoc.info/github/jnicklas/capybara/master) for more information on the methods and matchers that can be
15-
used in feature specs. Capybara is intended to simulate browser requests with
16-
HTTP. It will primarily send HTML content.
11+
Feature specs require the [Capybara](https://github.com/teamcapybara/capybara) gem, version 2.13.0 or later.
12+
Refer to the [capybara API documentation](https://rubydoc.info/github/teamcapybara/capybara/master) for more information on the methods and matchers that can be
13+
used in feature specs. Capybara is intended to simulate browser requests with HTTP. It will primarily send HTML content.
1714

1815
The `feature` and `scenario` DSL correspond to `describe` and `it`, respectively.
1916
These methods are simply aliases that allow feature specs to read more as
@@ -45,7 +42,7 @@ Feature: Feature spec
4542
Pending: (Failures listed here are expected and do not affect your suite's status)
4643
4744
1) Widget management User creates a new widget
48-
# 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`.
45+
# Feature specs require the Capybara (https://github.com/teamcapybara/capybara) gem, version 2.13.0 or later.
4946
# ./spec/features/widget_management_spec.rb:4
5047
"""
5148

features/request_specs/request_spec.feature

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ Feature: request spec
2222

2323
Check the Rails docs for details on these methods as well.
2424

25-
[Capybara](https://github.com/jnicklas/capybara) is no longer supported in
26-
request specs as of Capybara 2.0.0. The recommended way to use Capybara is
27-
with [feature specs](../feature-specs/feature-spec).
25+
[Capybara](https://github.com/teamcapybara/capybara) is not supported in
26+
request specs. The recommended way to use Capybara is with
27+
[feature specs](../feature-specs/feature-spec).
2828

2929
Scenario: specify managing a Widget with Rails integration methods
3030
Given a file named "spec/requests/widget_management_spec.rb" with:

lib/rspec/rails/example/feature_example_group.rb

+2-22
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,14 @@ def visit(*)
4040
capybara_feature: true,
4141
type: :feature,
4242
skip: <<-EOT.squish
43-
Feature specs require the Capybara (https://github.com/jnicklas/capybara)
44-
gem, version 2.2.0 or later. We recommend version 2.4.0 or later to avoid
45-
some deprecation warnings and have support for
46-
`config.expose_dsl_globally = false`.
43+
Feature specs require the Capybara (https://github.com/teamcapybara/capybara)
44+
gem, version 2.13.0 or later.
4745
EOT
4846
}
4947

50-
# Capybara's monkey patching causes us to have to jump through some hoops
51-
top_level = self
52-
main_feature = nil
53-
if defined?(Capybara) && ::Capybara::VERSION.to_f < 2.4
54-
# Capybara 2.2 and 2.3 do not use `alias_example_xyz`
55-
opts[:skip] = <<-EOT.squish
56-
Capybara < 2.4.0 does not support RSpec's namespace or
57-
`config.expose_dsl_globally = false`. Upgrade to Capybara >= 2.4.0.
58-
EOT
59-
main_feature = top_level.method(:feature) if top_level.respond_to?(:feature)
60-
end
61-
6248
RSpec.configure do |c|
63-
main_feature = nil unless c.expose_dsl_globally?
6449
c.alias_example_group_to :feature, opts
6550
c.alias_example_to :scenario
6651
c.alias_example_to :xscenario, skip: 'Temporarily skipped with xscenario'
6752
end
68-
69-
# Due to load order issues and `config.expose_dsl_globally?` defaulting to
70-
# `true` we need to put Capybara's monkey patch method back. Otherwise,
71-
# app upgrades have a high likelyhood of having all feature specs skipped.
72-
top_level.define_singleton_method(:feature, &main_feature) if main_feature
7353
end

lib/rspec/rails/vendor/capybara.rb

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
end
1010

1111
if defined?(Capybara)
12-
require 'rspec/support/comparable_version'
13-
unless RSpec::Support::ComparableVersion.new(Capybara::VERSION) >= '2.2.0'
14-
raise "You are using capybara #{Capybara::VERSION}. RSpec requires >= 2.2.0."
15-
end
16-
1712
RSpec.configure do |c|
1813
if defined?(Capybara::DSL)
1914
c.include Capybara::DSL, type: :feature

0 commit comments

Comments
 (0)