/
current_example.feature
56 lines (45 loc) · 1.63 KB
/
current_example.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
Feature: current example
You can reference the example object, and access its metadata, using
a block argument to it, before and after hooks, let, and subject.
Scenario: access the example object from within an example
Given a file named "spec/example_spec.rb" with:
"""ruby
describe "example as block arg to it, before, and after" do
before do |example|
expect(example.description).to eq("is the example object")
end
after do |example|
expect(example.description).to eq("is the example object")
end
it "is the example object" do |example|
expect(example.description).to eq("is the example object")
end
end
describe "example as block arg to let" do
let(:the_description) do |example|
example.description
end
it "is the example object" do |example|
expect(the_description).to eq("is the example object")
end
end
describe "example as block arg to subject" do
subject do |example|
example.description
end
it "is the example object" do |example|
expect(subject).to eq("is the example object")
end
end
describe "example as block arg to subject with a name" do
subject(:the_subject) do |example|
example.description
end
it "is the example object" do |example|
expect(the_subject).to eq("is the example object")
expect(subject).to eq("is the example object")
end
end
"""
When I run `rspec spec/example_spec.rb`
Then the example should pass