/
transactional_examples.feature
108 lines (86 loc) · 2.62 KB
/
transactional_examples.feature
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
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:
"""
require "spec_helper"
describe Widget do
it "has none to begin with" do
Widget.count.should == 0
end
it "has one after adding one" do
Widget.create
Widget.count.should == 1
end
it "has none after one was created in a previous example" do
Widget.count.should == 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:
"""
require "spec_helper"
RSpec.configure do |c|
c.use_transactional_examples = true
end
describe Widget do
it "has none to begin with" do
Widget.count.should == 0
end
it "has one after adding one" do
Widget.create
Widget.count.should == 1
end
it "has none after one was created in a previous example" do
Widget.count.should == 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:
"""
require "spec_helper"
RSpec.configure do |c|
c.use_transactional_examples = false
end
describe Widget do
it "has none to begin with" do
Widget.count.should == 0
end
it "has one after adding one" do
Widget.create
Widget.count.should == 1
end
it "has one after one was created in a previous example" do
Widget.count.should == 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:
"""
require "spec_helper"
describe Thing 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