Debian Codegraph @

rspec-core/features/command_line/order.feature

raw
1 Feature: Using the `--order` option
2
3 Use the `--order` option to tell RSpec how to order the files, groups, and
4 examples. The available ordering schemes are `defined` and `rand`.
5
6 `defined` is the default, which executes groups and examples in the order they
7 are defined as the spec files are loaded, with the caveat that each group
8 runs its examples before running its nested example groups, even if the
9 nested groups are defined before the examples.
10
11 Use `rand` to randomize the order of groups and examples within the groups.
12 Nested groups are always run from top-level to bottom-level in order to avoid
13 executing `before(:context)` and `after(:context)` hooks more than once, but the
14 order of groups at each level is randomized.
15
16 With `rand` you can also specify a seed.
17
18 Use `recently-modified` to run the most recently modified files first. You can
19 combine it with `--only-failures` to find the most recent failing specs. Note
20 that `recently-modified` and `rand` are mutually exclusive.
21
22 ** Example usage **
23
24 The `defined` option is only necessary when you have `--order rand` stored in a
25 config file (e.g. `.rspec`) and you want to override it from the command line.
26
27 <pre><code class="bash">--order defined
28 --order rand
29 --order rand:123
30 --seed 123 # same as --order rand:123
31 --order recently-modified
32 </code></pre>
33
34 Scenario: Default order is `defined`
35 Given a file named "example_spec.rb" with:
36 """ruby
37 RSpec.describe "something" do
38 it "does something" do
39 end
40
41 it "in order" do
42 end
43 end
44 """
45 When I run `rspec example_spec.rb --format documentation`
46 Then the output should contain:
47 """
48 something
49 does something
50 in order
51 """
52
53 Scenario: Order can be psuedo randomised (seed used here to fix the ordering for tests)
54 Given a file named "example_spec.rb" with:
55 """ruby
56 RSpec.describe "something" do
57 it "does something" do
58 end
59
60 it "in order" do
61 end
62 end
63 """
64 When I run `rspec example_spec.rb --format documentation --order rand:123`
65 Then the output should contain:
66 """
67 something
68 in order
69 does something
70 """
71
72 Scenario: Configure custom ordering
73 Given a file named "example_spec.rb" with:
74 """ruby
75 RSpec.configure do |config|
76 config.register_ordering(:reverse) do |examples|
77 examples.reverse
78 end
79 config.order = :reverse
80 end
81
82 RSpec.describe "something" do
83 it "does something" do
84 end
85
86 it "in order" do
87 end
88 end
89 """
90 When I run `rspec example_spec.rb --format documentation --order reverse`
91 Then the output should contain:
92 """
93 something
94 in order
95 does something
96 """
97
98 Scenario: Override order to `defined` when another order is set
99 Given a file named "example_spec.rb" with:
100 """ruby
101 RSpec.configure do |config|
102 config.order = :random
103 config.seed = 123
104 end
105 RSpec.describe "something" do
106 it "does something" do
107 end
108
109 it "in order" do
110 end
111 end
112 """
113 When I run `rspec example_spec.rb --format documentation --order defined`
114 Then the output should contain:
115 """
116 something
117 does something
118 in order
119 """