| 1 |
Feature: `--format` option |
| 2 |
|
| 3 |
Use the `--format` option to tell RSpec how to format the output. |
| 4 |
|
| 5 |
RSpec ships with several formatters built in. By default, it uses the progress |
| 6 |
formatter, which generates output like this: |
| 7 |
|
| 8 |
....F.....*..... |
| 9 |
|
| 10 |
A '.' represents a passing example, 'F' is failing, and '*' is pending. |
| 11 |
|
| 12 |
Use the documentation formatter to see the documentation strings passed to |
| 13 |
`describe`, `it`, and their aliases: |
| 14 |
|
| 15 |
```bash |
| 16 |
$ rspec spec --format documentation |
| 17 |
``` |
| 18 |
|
| 19 |
You can also specify an output target (`$stdout` by default) with an `--out` |
| 20 |
option immediately following the `--format` option: |
| 21 |
|
| 22 |
```bash |
| 23 |
$ rspec spec --format documentation --out rspec.txt |
| 24 |
``` |
| 25 |
|
| 26 |
Run `rspec --help` to see a listing of available formatters. |
| 27 |
|
| 28 |
Background: |
| 29 |
Given a file named "example_spec.rb" with: |
| 30 |
"""ruby |
| 31 |
RSpec.describe "something" do |
| 32 |
it "does something that passes" do |
| 33 |
expect(5).to eq(5) |
| 34 |
end |
| 35 |
|
| 36 |
it "does something that fails" do |
| 37 |
expect(5).to eq(4) |
| 38 |
end |
| 39 |
|
| 40 |
it "does something that is pending", :pending => true do |
| 41 |
expect(5).to be < 3 |
| 42 |
end |
| 43 |
|
| 44 |
it "does something that is skipped", :skip => true do |
| 45 |
expect(5).to be < 3 |
| 46 |
end |
| 47 |
end |
| 48 |
""" |
| 49 |
|
| 50 |
Scenario: Progress bar format (default) |
| 51 |
When I run `rspec --format progress example_spec.rb` |
| 52 |
Then the output should contain ".F**" |
| 53 |
|
| 54 |
Scenario: Documentation format |
| 55 |
When I run `rspec example_spec.rb --format documentation` |
| 56 |
Then the output should contain: |
| 57 |
""" |
| 58 |
something |
| 59 |
does something that passes |
| 60 |
does something that fails (FAILED - 1) |
| 61 |
does something that is pending (PENDING: No reason given) |
| 62 |
does something that is skipped (PENDING: No reason given) |
| 63 |
""" |
| 64 |
|
| 65 |
Scenario: Documentation format saved to a file |
| 66 |
When I run `rspec example_spec.rb --format documentation --out rspec.txt` |
| 67 |
Then the file "rspec.txt" should contain: |
| 68 |
""" |
| 69 |
something |
| 70 |
does something that passes |
| 71 |
does something that fails (FAILED - 1) |
| 72 |
does something that is pending (PENDING: No reason given) |
| 73 |
does something that is skipped (PENDING: No reason given) |
| 74 |
""" |
| 75 |
|
| 76 |
Scenario: Multiple formats and output targets |
| 77 |
When I run `rspec example_spec.rb --format progress --format documentation --out rspec.txt` |
| 78 |
Then the output should contain ".F**" |
| 79 |
And the file "rspec.txt" should contain: |
| 80 |
""" |
| 81 |
something |
| 82 |
does something that passes |
| 83 |
does something that fails (FAILED - 1) |
| 84 |
does something that is pending (PENDING: No reason given) |
| 85 |
does something that is skipped (PENDING: No reason given) |
| 86 |
""" |