|
1 | 1 | # rspec-rails [](http://travis-ci.org/rspec/rspec-rails) [](https://codeclimate.com/github/rspec/rspec-rails)
|
2 | 2 |
|
3 |
| -**rspec-rails 2** is a testing framework for Rails 3.x and 4.x. |
| 3 | +**rspec-rails** is a testing framework for Rails 3.x and 4.x. |
4 | 4 |
|
5 |
| -Use **[rspec-rails 1](http://github.com/dchelimsky/rspec-rails)** for Rails 2.x. |
| 5 | +Use **[rspec-rails 1.x](http://github.com/dchelimsky/rspec-rails)** for Rails |
| 6 | +2.x. |
6 | 7 |
|
7 |
| -## Install |
| 8 | +## Installation |
8 | 9 |
|
9 |
| -Add `rspec-rails` to the `:test` and `:development` groups in the Gemfile: |
| 10 | +Add `rspec-rails` to **both** the `:development` and `:test` groups in the |
| 11 | +`Gemfile`: |
10 | 12 |
|
11 | 13 | ```ruby
|
12 |
| -group :test, :development do |
13 |
| - gem "rspec-rails", "~> 2.0" |
| 14 | +group :development, :test do |
| 15 | + gem 'rspec-rails', '~> 2.0' |
14 | 16 | end
|
15 | 17 | ```
|
16 | 18 |
|
17 |
| -It needs to be in the `:development` group to expose generators and rake |
18 |
| -tasks without having to type `RAILS_ENV=test`. |
| 19 | +Download and install by running: |
19 | 20 |
|
20 |
| -Now you can run: |
| 21 | +``` |
| 22 | +bundle install |
| 23 | +``` |
| 24 | + |
| 25 | +Initialize the `spec/` directory (where specs will reside) with: |
21 | 26 |
|
22 | 27 | ```
|
23 | 28 | rails generate rspec:install
|
24 | 29 | ```
|
25 | 30 |
|
26 |
| -This adds the spec directory and some skeleton files, including |
27 |
| -the "rake spec" task. |
| 31 | +To run your specs, use the `rspec` command: |
| 32 | + |
| 33 | +``` |
| 34 | +bundle exec rspec |
| 35 | +
|
| 36 | +# Run only model specs |
| 37 | +bundle exec rspec spec/models |
| 38 | +
|
| 39 | +# Run only specs for AccountsController |
| 40 | +bundle exec rspec spec/controllers/accounts_controller_spec.rb |
| 41 | +``` |
| 42 | + |
| 43 | +Specs can also be run via `rake spec`, though this command may be slower to |
| 44 | +start than the `rspec` command. |
| 45 | + |
| 46 | +In Rails 4, you may want to create a binstub for the `rspec` command so it can |
| 47 | +be run via `bin/rspec`: |
| 48 | + |
| 49 | +``` |
| 50 | +bundle binstubs rspec-core |
| 51 | +``` |
28 | 52 |
|
29 | 53 | ### Generators
|
30 | 54 |
|
31 |
| -Once installed, RSpec will generate spec file instead of Test::Unit test files |
| 55 | +Once installed, RSpec will generate spec files instead of Test::Unit test files |
32 | 56 | when commands like `rails generate model` and `rails generate controller` are
|
33 | 57 | used.
|
34 | 58 |
|
|
0 commit comments