File: transactional_examples.feature

package info (click to toggle)
ruby-rspec-rails 8.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,804 kB
  • sloc: ruby: 10,881; sh: 198; makefile: 6
file content (106 lines) | stat: -rw-r--r-- 2,845 bytes parent folder | download | duplicates (2)
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: Transactional examples

  By default rspec executes each individual example in a transaction.

  You can also explicitly enable/disable transactions the configuration
  property 'use_transactional_examples'.

  Scenario: Run in transactions (default)
    Given a file named "spec/models/widget_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe Widget, type: :model do
        it "has none to begin with" do
          expect(Widget.count).to eq 0
        end

        it "has one after adding one" do
          Widget.create
          expect(Widget.count).to eq 1
        end

        it "has none after one was created in a previous example" do
          expect(Widget.count).to eq 0
        end
      end
      """
    When I run `rspec spec/models/widget_spec.rb`
    Then the examples should all pass

  Scenario: Run in transactions (explicit)
    Given a file named "spec/models/widget_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.configure do |c|
        c.use_transactional_examples = true
      end

      RSpec.describe Widget, type: :model do
        it "has none to begin with" do
          expect(Widget.count).to eq 0
        end

        it "has one after adding one" do
          Widget.create
          expect(Widget.count).to eq 1
        end

        it "has none after one was created in a previous example" do
          expect(Widget.count).to eq 0
        end
      end
      """
    When I run `rspec spec/models/widget_spec.rb`
    Then the examples should all pass

  Scenario: Disable transactions (explicit)
    Given a file named "spec/models/widget_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.configure do |c|
        c.use_transactional_examples = false
        c.order = "defined"
      end

      RSpec.describe Widget, type: :model do
        it "has none to begin with" do
          expect(Widget.count).to eq 0
        end

        it "has one after adding one" do
          Widget.create
          expect(Widget.count).to eq 1
        end

        it "has one after one was created in a previous example" do
          expect(Widget.count).to eq 1
        end

        after(:all) { Widget.destroy_all }
      end
      """
    When I run `rspec spec/models/widget_spec.rb`
    Then the examples should all pass

  Scenario: Run in transactions with fixture
    Given a file named "spec/models/thing_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe Thing, type: :model do
        fixtures :things
        it "fixture method defined" do
          things(:one)
        end
      end
      """
    Given a file named "spec/fixtures/things.yml" with:
      """
      one:
        name: MyString
      """
    When I run `rspec spec/models/thing_spec.rb`
    Then the examples should all pass