This repository was archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 393
/
Copy pathimplicit_docstrings.feature
51 lines (42 loc) · 2.17 KB
/
implicit_docstrings.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
Feature: Implicit docstrings
When you use rspec-expectations with rspec-core, RSpec is able to auto-generate the
docstrings for examples for you based on the last expectation in the example. This can be
handy when the matcher expresses exactly what you would write in your example docstring,
but it can also be easily abused. We find that the freeform nature of the docstring provides
a lot of value when used well (e.g. to document the "why" of a particular behavior), and you
lose that kind of flexibility when you rely on the matcher to generate the docstring for you.
In general, we recommend only using this feature when the matcher aligns _exactly_ with the
docstring you would write. Even then, many users prefer the explicitness of the full
docstring, so use this feature with care (if at all).
Scenario: Run passing examples
Given a file named "implicit_docstrings_spec.rb" with:
"""ruby
RSpec.describe "Examples with no docstrings generate their own:" do
specify { expect(3).to be < 5 }
specify { expect([1,2,3]).to include(2) }
specify { expect([1,2,3]).to respond_to(:size) }
end
"""
When I run `rspec ./implicit_docstrings_spec.rb -fdoc`
Then the output should contain "is expected to be < 5"
And the output should contain "is expected to include 2"
And the output should contain "is expected to respond to #size"
Scenario: Run failing examples
Given a file named "failing_implicit_docstrings_spec.rb" with:
"""ruby
RSpec.describe "Failing examples with no descriptions" do
# description is auto-generated per the last executed expectation
specify do
expect(3).to equal(2)
expect(5).to equal(5)
end
specify { expect(3).to be > 5 }
specify { expect([1,2,3]).to include(4) }
specify { expect([1,2,3]).not_to respond_to(:size) }
end
"""
When I run `rspec ./failing_implicit_docstrings_spec.rb -fdoc`
Then the output should contain "is expected to equal 2"
And the output should contain "is expected to be > 5"
And the output should contain "is expected to include 4"
And the output should contain "is expected not to respond to #size"