-
-
Notifications
You must be signed in to change notification settings - Fork 763
/
shared_context.feature
74 lines (61 loc) · 2.31 KB
/
shared_context.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
Feature: shared context
Use `shared_context` to define a block that will be evaluated in the context
of example groups either explicitly, using `include_context`, or implicitly by
matching metadata.
Background:
Given a file named "shared_stuff.rb" with:
"""
shared_context "shared stuff", :a => :b do
before { @some_var = :some_value }
def shared_method
"it works"
end
let(:shared_let) { {'arbitrary' => 'object'} }
subject do
'this is the subject'
end
end
"""
Scenario: declare shared context and include it with include_context
Given a file named "shared_context_example.rb" with:
"""
require "./shared_stuff.rb"
describe "group that includes a shared context using 'include_context'" do
include_context "shared stuff"
it "has access to methods defined in shared context" do
shared_method.should eq("it works")
end
it "has access to methods defined with let in shared context" do
shared_let['arbitrary'].should eq('object')
end
it "runs the before hooks defined in the shared context" do
@some_var.should be(:some_value)
end
it "accesses the subject defined in the shared context" do
subject.should eq('this is the subject')
end
end
"""
When I run `rspec shared_context_example.rb`
Then the examples should all pass
Scenario: declare shared context and include it with metadata
Given a file named "shared_context_example.rb" with:
"""
require "./shared_stuff.rb"
describe "group that includes a shared context using metadata", :a => :b do
it "has access to methods defined in shared context" do
shared_method.should eq("it works")
end
it "has access to methods defined with let in shared context" do
shared_let['arbitrary'].should eq('object')
end
it "runs the before hooks defined in the shared context" do
@some_var.should be(:some_value)
end
it "accesses the subject defined in the shared context" do
subject.should eq('this is the subject')
end
end
"""
When I run `rspec shared_context_example.rb`
Then the examples should all pass