| 1 |
Feature: `<file>:<line_number>` (line number appended to file path) |
| 2 |
|
| 3 |
To run one or more examples or groups, you can append the line number to the |
| 4 |
path, e.g. |
| 5 |
|
| 6 |
```bash |
| 7 |
$ rspec path/to/example_spec.rb:37 |
| 8 |
``` |
| 9 |
|
| 10 |
Background: |
| 11 |
Given a file named "example_spec.rb" with: |
| 12 |
"""ruby |
| 13 |
RSpec.describe "outer group" do |
| 14 |
|
| 15 |
it "first example in outer group" do |
| 16 |
|
| 17 |
end |
| 18 |
|
| 19 |
it "second example in outer group" do |
| 20 |
|
| 21 |
end |
| 22 |
|
| 23 |
describe "nested group" do |
| 24 |
|
| 25 |
it "example in nested group" do |
| 26 |
|
| 27 |
end |
| 28 |
|
| 29 |
end |
| 30 |
|
| 31 |
end |
| 32 |
""" |
| 33 |
And a file named "example2_spec.rb" with: |
| 34 |
"""ruby |
| 35 |
RSpec.describe "yet another group" do |
| 36 |
it "first example in second file" do |
| 37 |
end |
| 38 |
it "second example in second file" do |
| 39 |
end |
| 40 |
end |
| 41 |
""" |
| 42 |
And a file named "one_liner_spec.rb" with: |
| 43 |
"""ruby |
| 44 |
RSpec.describe 9 do |
| 45 |
|
| 46 |
it { is_expected.to be > 8 } |
| 47 |
|
| 48 |
it { is_expected.to be < 10 } |
| 49 |
|
| 50 |
end |
| 51 |
""" |
| 52 |
|
| 53 |
Scenario: Nested groups - outer group on declaration line |
| 54 |
When I run `rspec example_spec.rb:1 --format doc` |
| 55 |
Then the examples should all pass |
| 56 |
And the output should contain "second example in outer group" |
| 57 |
And the output should contain "first example in outer group" |
| 58 |
And the output should contain "example in nested group" |
| 59 |
|
| 60 |
Scenario: Nested groups - outer group inside block before example |
| 61 |
When I run `rspec example_spec.rb:2 --format doc` |
| 62 |
Then the examples should all pass |
| 63 |
And the output should contain "second example in outer group" |
| 64 |
And the output should contain "first example in outer group" |
| 65 |
And the output should contain "example in nested group" |
| 66 |
|
| 67 |
Scenario: Nested groups - inner group on declaration line |
| 68 |
When I run `rspec example_spec.rb:11 --format doc` |
| 69 |
Then the examples should all pass |
| 70 |
And the output should contain "example in nested group" |
| 71 |
And the output should not contain "second example in outer group" |
| 72 |
And the output should not contain "first example in outer group" |
| 73 |
|
| 74 |
Scenario: Nested groups - inner group inside block before example |
| 75 |
When I run `rspec example_spec.rb:12 --format doc` |
| 76 |
Then the examples should all pass |
| 77 |
And the output should contain "example in nested group" |
| 78 |
And the output should not contain "second example in outer group" |
| 79 |
And the output should not contain "first example in outer group" |
| 80 |
|
| 81 |
Scenario: Two examples - first example on declaration line |
| 82 |
When I run `rspec example_spec.rb:3 --format doc` |
| 83 |
Then the examples should all pass |
| 84 |
And the output should contain "first example in outer group" |
| 85 |
But the output should not contain "second example in outer group" |
| 86 |
And the output should not contain "example in nested group" |
| 87 |
|
| 88 |
Scenario: Two examples - first example inside block |
| 89 |
When I run `rspec example_spec.rb:4 --format doc` |
| 90 |
Then the examples should all pass |
| 91 |
And the output should contain "first example in outer group" |
| 92 |
But the output should not contain "second example in outer group" |
| 93 |
And the output should not contain "example in nested group" |
| 94 |
|
| 95 |
Scenario: Two examples - first example on end |
| 96 |
When I run `rspec example_spec.rb:5 --format doc` |
| 97 |
Then the examples should all pass |
| 98 |
And the output should contain "first example in outer group" |
| 99 |
But the output should not contain "second example in outer group" |
| 100 |
And the output should not contain "example in nested group" |
| 101 |
|
| 102 |
Scenario: Two examples - first example after end but before next example |
| 103 |
When I run `rspec example_spec.rb:6 --format doc` |
| 104 |
Then the examples should all pass |
| 105 |
And the output should contain "first example in outer group" |
| 106 |
But the output should not contain "second example in outer group" |
| 107 |
And the output should not contain "example in nested group" |
| 108 |
|
| 109 |
Scenario: Two examples - second example on declaration line |
| 110 |
When I run `rspec example_spec.rb:7 --format doc` |
| 111 |
Then the examples should all pass |
| 112 |
And the output should contain "second example in outer group" |
| 113 |
But the output should not contain "first example in outer group" |
| 114 |
And the output should not contain "example in nested group" |
| 115 |
|
| 116 |
Scenario: Two examples - second example inside block |
| 117 |
When I run `rspec example_spec.rb:7 --format doc` |
| 118 |
Then the examples should all pass |
| 119 |
And the output should contain "second example in outer group" |
| 120 |
But the output should not contain "first example in outer group" |
| 121 |
And the output should not contain "example in nested group" |
| 122 |
|
| 123 |
Scenario: Two examples - second example on end |
| 124 |
When I run `rspec example_spec.rb:7 --format doc` |
| 125 |
Then the examples should all pass |
| 126 |
And the output should contain "second example in outer group" |
| 127 |
But the output should not contain "first example in outer group" |
| 128 |
And the output should not contain "example in nested group" |
| 129 |
|
| 130 |
Scenario: Specified multiple times for different files |
| 131 |
When I run `rspec example_spec.rb:7 example2_spec.rb:4 --format doc` |
| 132 |
Then the examples should all pass |
| 133 |
And the output should contain "second example in outer group" |
| 134 |
And the output should contain "second example in second file" |
| 135 |
But the output should not contain "first example in outer group" |
| 136 |
And the output should not contain "nested group" |
| 137 |
And the output should not contain "first example in second file" |
| 138 |
|
| 139 |
Scenario: Specified multiple times for the same file with multiple arguments |
| 140 |
When I run `rspec example_spec.rb:7 example_spec.rb:11 --format doc` |
| 141 |
Then the examples should all pass |
| 142 |
And the output should contain "second example in outer group" |
| 143 |
And the output should contain "nested group" |
| 144 |
But the output should not contain "first example in outer group" |
| 145 |
And the output should not contain "second file" |
| 146 |
|
| 147 |
Scenario: Specified multiple times for the same file with a single argument |
| 148 |
When I run `rspec example_spec.rb:7:11 --format doc` |
| 149 |
Then the examples should all pass |
| 150 |
And the output should contain "second example in outer group" |
| 151 |
And the output should contain "nested group" |
| 152 |
But the output should not contain "first example in outer group" |
| 153 |
And the output should not contain "second file" |
| 154 |
|
| 155 |
Scenario: Matching one-liners |
| 156 |
When I run `rspec one_liner_spec.rb:3 --format doc` |
| 157 |
Then the examples should all pass |
| 158 |
Then the output should contain "is expected to be > 8" |
| 159 |
But the output should not contain "is expected to be < 10" |