|
1 |
| -# Upgrading from rspec-rails-1.x to rspec-rails-2. |
| 1 | +# Upgrading from rspec-rails-2.x to rspec-rails-3 |
| 2 | + |
| 3 | +For detailed information on the RSpec 3.x upgrade process see the [RSpec Upgrade |
| 4 | +docs](https://relishapp.com/rspec/docs/upgrade). |
| 5 | + |
| 6 | +There is another `rspec-rails` specific change to be aware of: |
| 7 | + |
| 8 | +```text |
| 9 | +The default helper files created in RSpec 3.x have changed |
| 10 | +``` |
| 11 | + |
| 12 | +In prior versions, only a single `spec_helper.rb` file was generated. This file |
| 13 | +has been moved to `rails_helper.rb`. The new `spec_helper.rb` is the same |
| 14 | +standard helper generated by running `rspec --init`. |
| 15 | + |
| 16 | +This change was made to accomplish two general goals: |
| 17 | + |
| 18 | +- Keep the installation process in sync with regular RSpec changes |
| 19 | + |
| 20 | +- Provide an out-of-the-box way to avoid loading Rails for those specs that do |
| 21 | + not require it |
| 22 | + |
| 23 | +## Upgrading an Existing App |
| 24 | + |
| 25 | +For most existing apps, one of the following upgrade paths is sufficient to |
| 26 | +switch to the new helpers: |
| 27 | + |
| 28 | +### I need to move things over in stages |
| 29 | + |
| 30 | +1. Create a new `rails_helper.rb` with the following content: |
| 31 | + |
| 32 | + ```ruby |
| 33 | + require 'spec_helper' |
| 34 | + ``` |
| 35 | + |
| 36 | +2. As necessary, replace `require 'spec_helper'` with `require 'rails_helper'` |
| 37 | + in the specs. |
| 38 | + |
| 39 | +3. When ready, move any Rails specific code and setup from `spec_helper.rb` to |
| 40 | + `rails_helper.rb`. |
| 41 | + |
| 42 | +### I'm ready to just switch completely |
| 43 | + |
| 44 | +1. Move the existing `spec_helper.rb` to `rails_helper.rb`: |
| 45 | + |
| 46 | + ```ruby |
| 47 | + git move spec/spec_helper.rb spec/rails_helper.rb |
| 48 | + ``` |
| 49 | + |
| 50 | +2. Run the installation rake task opting to not replace `rails_helper.rb`: |
| 51 | + |
| 52 | + ```console |
| 53 | + $ bin/rails generate rspec:install |
| 54 | + create .rspec |
| 55 | + exist spec |
| 56 | + create spec/spec_helper.rb |
| 57 | + conflict spec/rails_helper.rb |
| 58 | + Overwrite my_app/spec/rails_helper.rb? (enter "h"for help) [Ynaqdh] n |
| 59 | + skip spec/rails_helper.rb |
| 60 | + ``` |
| 61 | + |
| 62 | +3. Move any non-Rails RSpec configurations and customizations from your |
| 63 | + `rails_helper.rb` to `spec_helper.rb`. |
| 64 | + |
| 65 | +4. Find/replace instances of `require 'spec_helper'` with |
| 66 | + `require 'rails_helper'` in any specs which rely on Rails. |
| 67 | + |
| 68 | +## Generators |
| 69 | + |
| 70 | +Generators run in RSpec 3.x will use the `rails_helper` by default. |
| 71 | + |
| 72 | +# Upgrading from rspec-rails-1.x to rspec-rails-2 |
2 | 73 |
|
3 | 74 | This is a work in progress. Please submit errata, missing steps, or patches to
|
4 | 75 | the [rspec-rails issue tracker](https://github.com/rspec/rspec-rails/issues).
|
|
0 commit comments