Skip to content

Commit 1e8d7df

Browse files
authored
Merge pull request #2342 from rspec/drop-rails-3-docs
Drop outdated documentation
2 parents 9ce4e65 + fe67624 commit 1e8d7df

File tree

5 files changed

+14
-184
lines changed

5 files changed

+14
-184
lines changed

features/.nav

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
- upgrade:
2-
- from_1x_to_2x.md (From rspec-rails-1.x to rspec-rails-2)
31
- GettingStarted.md (Start from scratch)
42
- Generators.md (Generators)
53
- Transactions.md

features/GettingStarted.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
Install Rails-3
1+
Install Rails 6
22

3-
$ gem install rails -v "~> 3.0.0"
3+
$ gem install rails -v "~> 6.0.0"
44

55
### Generate an app
66

7-
$ rails new example
8-
$ cd example
7+
$ rails new example_app
8+
$ cd example_app
99

1010
### Add rspec-rails to the Gemfile
1111

12-
$ echo 'gem "rspec-rails", :group => [:development, :test]' >> Gemfile
12+
$ echo 'gem "rspec-rails", group: [:development, :test]' >> Gemfile
1313

1414
### Install the bundle
1515

@@ -29,7 +29,7 @@ the files in the `spec` directory to RSpec.
2929

3030
### Run migrations
3131

32-
$ rake db:migrate && rake db:test:prepare
32+
$ rails db:migrate && rails db:test:prepare
3333

3434
### Run RSpec
3535

features/RailsVersions.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
rails version | rspec-rails version
2+
------------- | -------------------
23
2.3 | 1.3.4
34
3.0 | >= 2.0
45
3.1 | >= 2.6
@@ -8,3 +9,5 @@
89
4.2 | >= 3.1
910
5.0 | >= 3.5
1011
5.1 | >= 3.6
12+
5.2 | >= 3.8
13+
6.0 | >= 4.0

features/directory_structure.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Feature: Directory Structure
6363
their location on the filesystem. This was both confusing to new users and not
6464
desirable for some veteran users.
6565

66-
In RSpec 3, this behavior must be explicitly enabled:
66+
This behaviour must be explicitly enabled:
6767

6868
```ruby
6969
# spec/rails_helper.rb

features/upgrade/README.md

+4-175
Original file line numberDiff line numberDiff line change
@@ -1,178 +1,7 @@
1-
# Upgrading from rspec-rails-2.x to rspec-rails-3
1+
# Upgrading from rspec-rails 3.x to version 4
22

3-
For detailed information on the general RSpec 3.x upgrade process see the [RSpec
4-
Upgrade docs](https://relishapp.com/rspec/docs/upgrade).
3+
RSpec Rails 4 is a major version under semantic versioning, it allowed us to change the supported Rails versions to 5 and 6 only. There are no changes required to upgrade to RSpec Rails 4 if you are using Rails 5 or 6.
54

6-
There are several changes specific to `rspec-rails` to be aware of:
5+
If you are using Rails 4.2 you can use RSpec Rails 4, but note that support for it is not maintained, we consider this a breaking change hence the version change, and you must be on Ruby 2.2 as a minimum.
76

8-
- [Default helper files created in RSpec 3.x have changed](#default-helper-files)
9-
10-
- [File-type inference disabled by default](#file-type-inference-disabled)
11-
12-
- [Rails 4.x `ActiveRecord::Migration` pending migration checks](#pending-migration-checks)
13-
14-
- [Extraction of `stub_model` and `mock_model` to `rspec-activemodel-mocks`](#extract-stub-model)
15-
16-
<a name="default-helper-files"></a>
17-
## Default helper files created in RSpec 3.x have changed
18-
19-
In prior versions, only a single `spec_helper.rb` file was generated. This file
20-
has been moved to `rails_helper.rb`. The new `spec_helper.rb` is the same
21-
standard helper generated by running `rspec --init`.
22-
23-
This change was made to accomplish two general goals:
24-
25-
- Keep the installation process in sync with regular RSpec changes
26-
27-
- Provide an out-of-the-box way to avoid loading Rails for those specs that do
28-
not require it
29-
30-
<a name="generators"></a>
31-
### Generators
32-
33-
Generators run in RSpec 3.x will require `rails_helper` and not `spec_helper`.
34-
35-
<a name="upgrading-an-existing-app"></a>
36-
### Upgrading an Existing App
37-
38-
For most existing apps, one of the following upgrade paths is sufficient to
39-
switch to the new helpers:
40-
41-
#### I need to move things over in stages
42-
43-
1. Create a new `rails_helper.rb` with the following content:
44-
45-
```ruby
46-
require 'spec_helper'
47-
```
48-
49-
2. As necessary, replace `require 'spec_helper'` with `require 'rails_helper'`
50-
in the specs.
51-
52-
3. When ready, move any Rails specific code and setup from `spec_helper.rb` to
53-
`rails_helper.rb`.
54-
55-
#### I'm ready to just switch completely
56-
57-
1. Move the existing `spec_helper.rb` to `rails_helper.rb`:
58-
59-
```ruby
60-
git mv spec/spec_helper.rb spec/rails_helper.rb
61-
```
62-
63-
2. Run the installation rake task opting to not replace `rails_helper.rb`:
64-
65-
```console
66-
$ bin/rails generate rspec:install
67-
create .rspec
68-
exist spec
69-
create spec/spec_helper.rb
70-
conflict spec/rails_helper.rb
71-
Overwrite my_app/spec/rails_helper.rb? (enter "h"for help) [Ynaqdh] n
72-
skip spec/rails_helper.rb
73-
```
74-
75-
3. Move any non-Rails RSpec configurations and customizations from your
76-
`rails_helper.rb` to `spec_helper.rb`.
77-
78-
4. Find/replace instances of `require 'spec_helper'` with
79-
`require 'rails_helper'` in any specs which rely on Rails.
80-
81-
<a name="file-type-inference-disabled"></a>
82-
## File-type inference disabled by default
83-
84-
Previously we automatically inferred spec type from a file location, this
85-
was a surprising behaviour for new users and undesirable for some veteran users
86-
so from RSpec 3 onwards this behaviour must be explicitly opted into with:
87-
88-
```Ruby
89-
RSpec.configure do |config|
90-
config.infer_spec_type_from_file_location!
91-
end
92-
```
93-
94-
This change was made to accomplish our general goals of acting with the principle
95-
of least surprise and making RSpec configuration more explicit. See [the
96-
directory structure documentation](https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/directory-structure) for more details.
97-
98-
<a name="pending-migration-checks"></a>
99-
## Rails 4.x `ActiveRecord::Migration` pending migration checks
100-
101-
If you are not using `ActiveRecord` you do not need to worry about these
102-
settings.
103-
104-
Users of Rails 4.x can now take advantage of improved schema migration and sync
105-
abilities. Prior to RSpec 3, users were required to manually run migrations in
106-
both the development and test environments. Additionally, the behavior differed
107-
depending on if the specs were run via `rake` or via the standalone `rspec`
108-
command.
109-
110-
With the release of Rails 4, new APIs have been exposed on
111-
`ActiveRecord::Migration`. This allows RSpec to take advantage of these new
112-
standard migration checks, mirroring behavior across the board.
113-
114-
- Rails 4.0.x
115-
116-
Add the following to the top of the `rails_helper` file after Rails has
117-
been required:
118-
119-
```ruby
120-
ActiveRecord::Migration.check_pending!
121-
```
122-
123-
This will raise an exception if there are any pending schema changes. Users
124-
will still be required to manually keep the development and test
125-
environments in sync.
126-
127-
- Rails 4.1+
128-
129-
With this release there was an exciting new feature. Users no longer need
130-
to keep the development and test environments in sync. To take advantage of
131-
this add the following to the top of the `rails_helper` file after Rails
132-
has been required:
133-
134-
```ruby
135-
ActiveRecord::Migration.maintain_test_schema!
136-
```
137-
138-
What this does is that rather than just raising when the test schema has
139-
pending migrations, Rails will try to load the schema. An exception will
140-
now only be raised if there are pending migrations afterwards the schema
141-
has been loaded.
142-
143-
There are a few caveates to be aware of when using this:
144-
145-
- Migrations still need to be run manually; although now this only has to
146-
be done in the 'development' environment
147-
- An exception will be raised If the schema has not been initialized. The
148-
exception will provide instructions stating `rake db:migrate` needs to
149-
be run.
150-
151-
It is possible to opt-out of checking for pending migrations. Since this is
152-
actually a feature of Rails, the change needs to be done as part of the Rails
153-
configuration. To do this, add the following to your
154-
`config/environments/test.rb` file:
155-
156-
```ruby
157-
config.active_record.maintain_test_schema = false
158-
```
159-
160-
New RSpec projects don't need to worry about these commands as the `rails
161-
generate rspec:install` will add them automatically.
162-
163-
<a name="extract-stub-model"></a>
164-
## Extraction of `stub_model` and `mock_model` to [`rspec-activemodel-mocks`](https://github.com/rspec/rspec-activemodel-mocks)
165-
166-
Historically, `stub_model` and `mock_model` have been difficult to maintain.
167-
They are tightly coupled to `ActiveRecord` which isn't always the ORM of choice.
168-
This maintainence coupling has lead to delays with previous releases.
169-
Additionally, the objects generated by these methods hide important
170-
`ActiveRecord` behavior complexity which would otherwise be good to expose.
171-
172-
Some alternatives are:
173-
174-
- Wrap calls to `ActiveRecord` objects in more specific domain models and
175-
services
176-
- Use new unsaved `ActiveRecord` instances (e.g. `Model.new`)
177-
- Consider [partial mocks](https://www.relishapp.com/rspec/rspec-mocks/docs/basics/partial-test-doubles) on an `ActiveRecord` instance
178-
- Let the specs hit database directly where appropriate
7+
If you are upgrading from an earlier version of RSpec Rails, please consult [the upgrading 2.x to 3.x guide](https://relishapp.com/rspec/rspec-rails/v/3-9/docs/upgrade).

0 commit comments

Comments
 (0)