File: clear_examples.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 (106 lines) | stat: -rw-r--r-- 2,775 bytes parent folder | download | duplicates (5)
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
Feature: Running specs multiple times with different runner options in the same process

  Use `clear_examples` command to clear all example groups between different
  runs in the same process. It:

  - clears all example groups
  - restores inclusion and exclusion filters set by configuration
  - clears inclusion and exclusion filters set by previous spec run (via runner)
  - resets all time counters (start time, load time, duration, etc.)
  - resets different counts of examples (all examples, pending and failed)

  ```ruby
  require "spec_helper"

  RSpec::Core::Runner.run([... some parameters ...])

  RSpec.clear_examples

  RSpec::Core::Runner.run([... different parameters ...])
  ```

  Background:
    Given a file named "spec/spec_helper.rb" with:
      """ruby
      RSpec.configure do |config|
        config.filter_run_when_matching :focus => true
        config.filter_run_excluding :slow => true
      end
      """
    Given a file named "spec/truth_spec.rb" with:
    """ruby
    require 'spec_helper'

    RSpec.describe "truth" do
      describe true do
        it "is truthy" do
          expect(true).to be_truthy
        end

        it "is not falsy" do
          expect(true).not_to be_falsy
        end
      end

      describe false do
        it "is falsy" do
          expect(false).to be_falsy
        end

        it "is truthy" do
          expect(false).not_to be_truthy
        end
      end
    end
    """

  Scenario: Running specs multiple times in the same process
    Given a file named "scripts/multiple_runs.rb" with:
      """ruby
      require 'rspec/core'

      RSpec::Core::Runner.run(['spec'])
      RSpec.clear_examples
      RSpec::Core::Runner.run(['spec'])
      """
    When I run `ruby scripts/multiple_runs.rb`
    Then the output should match:
      """
      4 examples, 0 failures
      .*
      4 examples, 0 failures
      """

  Scenario: Running specs multiple times in the same process with different parameters
    Given a file named "spec/bar_spec.rb" with:
      """ruby
      require 'spec_helper'

      RSpec.describe 'bar' do
        subject(:bar) { :focused }

        it 'is focused', :focus do
          expect(bar).to be(:focused)
        end
      end
      """
    Given a file named "scripts/different_parameters.rb" with:
      """ruby
      require 'rspec/core'

      RSpec::Core::Runner.run(['spec'])
      RSpec.clear_examples
      RSpec::Core::Runner.run(['spec/truth_spec.rb:4'])
      RSpec.clear_examples
      RSpec::Core::Runner.run(['spec', '-e', 'fals'])
      """
    When I run `ruby scripts/different_parameters.rb`
    Then the output should match:
      """
      1 example, 0 failures
      .*
      2 examples, 0 failures
      .*
      3 examples, 0 failures
      """