File: profile.feature

package info (click to toggle)
ruby-rspec 3.13.0c0e0m0s1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,856 kB
  • sloc: ruby: 70,868; sh: 1,423; makefile: 99
file content (245 lines) | stat: -rw-r--r-- 8,459 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
Feature: Profiling examples (`--profile`)

  The `--profile` command line option (available from `RSpec.configure` as
  `#profile_examples`), when set, will cause RSpec to dump out a list of your
  slowest examples. By default, it prints the 10 slowest examples, but you can
  set it to a different value to have it print more or fewer slow examples. If
  `--fail-fast` option is used together with `--profile` and there is a failure,
  slow examples are not shown.

  Background:
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      """
    And a file named "spec/example_spec.rb" with:
      """ruby
      require "spec_helper"

      RSpec.describe "something" do
        it "sleeps for 0.1 seconds (example 1)" do
          sleep 0.1
          expect(1).to eq(1)
        end

        it "sleeps for 0 seconds (example 2)" do
          expect(2).to eq(2)
        end

        it "sleeps for 0.15 seconds (example 3)" do
          sleep 0.15
          expect(3).to eq(3)
        end

        it "sleeps for 0.05 seconds (example 4)" do
          sleep 0.05
          expect(4).to eq(4)
        end

        it "sleeps for 0.05 seconds (example 5)" do
          sleep 0.05
          expect(5).to eq(5)
        end

        it "sleeps for 0.05 seconds (example 6)" do
          sleep 0.05
          expect(6).to eq(6)
        end

        it "sleeps for 0.05 seconds (example 7)" do
          sleep 0.05
          expect(7).to eq(7)
        end

        it "sleeps for 0.05 seconds (example 8)" do
          sleep 0.05
          expect(8).to eq(8)
        end

        it "sleeps for 0.05 seconds (example 9)" do
          sleep 0.05
          expect(9).to eq(9)
        end

        it "sleeps for 0.05 seconds (example 10)" do
          sleep 0.05
          expect(10).to eq(10)
        end

        it "sleeps for 0.05 seconds (example 11)" do
          sleep 0.05
          expect(11).to eq(11)
        end
      end
      """

  Scenario: By default does not show profile
    When I run `rspec spec`
    Then the examples should all pass
    And the output should not contain "example 1"
    And the output should not contain "example 2"
    And the output should not contain "example 3"
    And the output should not contain "example 4"
    And the output should not contain "example 5"
    And the output should not contain "example 6"
    And the output should not contain "example 7"
    And the output should not contain "example 8"
    And the output should not contain "example 9"
    And the output should not contain "example 10"
    And the output should not contain "example 11"

  Scenario: Setting `profile_examples` to true shows 10 examples
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      RSpec.configure { |c| c.profile_examples = true }
      """
    When I run `rspec spec`
    Then the examples should all pass
    And the output should contain "Top 10 slowest examples"
    And the output should contain "example 1"
    And the output should not contain "example 2"
    And the output should contain "example 3"
    And the output should contain "example 4"
    And the output should contain "example 5"
    And the output should contain "example 6"
    And the output should contain "example 7"
    And the output should contain "example 8"
    And the output should contain "example 9"
    And the output should contain "example 10"
    And the output should contain "example 11"

  Scenario: Setting `profile_examples` to 2 shows 2 examples
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      RSpec.configure { |c| c.profile_examples = 2 }
      """
    When I run `rspec spec`
    Then the examples should all pass
    And the output should contain "Top 2 slowest examples"
    And the output should contain "example 1"
    And the output should not contain "example 2"
    And the output should contain "example 3"
    And the output should not contain "example 4"
    And the output should not contain "example 5"
    And the output should not contain "example 6"
    And the output should not contain "example 7"
    And the output should not contain "example 8"
    And the output should not contain "example 9"
    And the output should not contain "example 10"
    And the output should not contain "example 11"

  Scenario: Setting profile examples through CLI using `--profile`
    When I run `rspec spec --profile 2`
    Then the examples should all pass
    And the output should contain "Top 2 slowest examples"
    And the output should contain "example 1"
    And the output should not contain "example 2"
    And the output should contain "example 3"
    And the output should not contain "example 4"
    And the output should not contain "example 5"
    And the output should not contain "example 6"
    And the output should not contain "example 7"
    And the output should not contain "example 8"
    And the output should not contain "example 9"
    And the output should not contain "example 10"
    And the output should not contain "example 11"

  Scenario: Using `--no-profile` overrules config options
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      RSpec.configure { |c| c.profile_examples = true }
      """
    When I run `rspec spec --no-profile`
    Then the examples should all pass
    And the output should not contain "example 1"
    And the output should not contain "example 2"
    And the output should not contain "example 3"
    And the output should not contain "example 4"
    And the output should not contain "example 5"
    And the output should not contain "example 6"
    And the output should not contain "example 7"
    And the output should not contain "example 8"
    And the output should not contain "example 9"
    And the output should not contain "example 10"
    And the output should not contain "example 11"

  Scenario: Using `--profile` with `--fail-fast` shows slow examples if everything passes
    When I run `rspec spec --fail-fast --profile`
    Then the examples should all pass
    And the output should contain "Top 10 slowest examples"
    And the output should contain "example 1"
    And the output should not contain "example 2"
    And the output should contain "example 3"
    And the output should contain "example 4"
    And the output should contain "example 5"
    And the output should contain "example 6"
    And the output should contain "example 7"
    And the output should contain "example 8"
    And the output should contain "example 9"
    And the output should contain "example 10"
    And the output should contain "example 11"

  Scenario: Using `--profile` shows slow examples even in case of failures
    Given a file named "spec/example_spec.rb" with:
      """ruby
      require "spec_helper"

      RSpec.describe "something" do
        it "sleeps for 0.1 seconds (example 1)" do
          sleep 0.1
          expect(1).to eq(1)
        end

        it "fails" do
          fail
        end
      end
      """
    When I run `rspec spec --profile`
    Then the output should contain "2 examples, 1 failure"
    And the output should contain "Top 2 slowest examples"
    And the output should contain "example 1"

  Scenario: Using `--profile` with `--fail-fast` doesn't show slow examples in case of failures
    Given a file named "spec/example_spec.rb" with:
      """ruby
      require "spec_helper"

      RSpec.describe "something" do
        it "sleeps for 0.1 seconds (example 1)" do
          sleep 0.1
          expect(1).to eq(1)
        end

        it "fails" do
          fail
        end
      end
      """
    When I run `rspec spec --fail-fast --profile`
    Then the output should not contain "Top 2 slowest examples"
    And the output should not contain "example 1"

  Scenario: Using `--profile` with slow before hooks includes hook execution time
    Given a file named "spec/example_spec.rb" with:
      """ruby
      RSpec.describe "slow before context hook" do
        before(:context) do
          sleep 0.2
        end

        context "nested" do
          it "example" do
            expect(10).to eq(10)
          end
        end
      end

      RSpec.describe "slow example" do
        it "slow example" do
          sleep 0.1
          expect(10).to eq(10)
        end
      end
      """
    When I run `rspec spec --profile 1`
    Then the output should report "slow before context hook" as the slowest example group