Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSpec doc title #597

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,19 @@ And then configure RSpec in this way:
This way, when running in recording mode, only the tests that have been marked with the
``:show_in_doc`` metadata will be run, and hence only those will be used as examples.

If you want to distinguish your recorded examples from one another, you can provide a ``doc_title``
mathieujobin marked this conversation as resolved.
Show resolved Hide resolved
that will be displayed in the documentation later, like this:

.. code:: ruby

it 'works', :show_in_doc, doc_title: 'A working example' do
expect_it.to work
end

it 'wont work', :show_in_doc, doc_title: 'A failing example' do
expect_it.not_to work
end

Caveats
-------

Expand Down
5 changes: 5 additions & 0 deletions lib/apipie/extractor/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def record
if @controller
{:controller => @controller,
:action => @action,
:doc_title => doc_title,
:verb => @verb,
:path => @path,
:params => @params,
Expand All @@ -122,6 +123,10 @@ def record
def api_description
end

def doc_title
@doc_title ||= (RSpec.current_example.metadata[:doc_title] if 'RSpec'.safe_constantize)
end

class Middleware
def initialize(app)
@app = app
Expand Down
2 changes: 1 addition & 1 deletion lib/apipie/extractor/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def desc_to_s(description)
def ordered_call(call)
call = call.stringify_keys
ordered_call = OrderedHash.new
%w[title verb path versions query request_data response_data code show_in_doc recorded].each do |k|
%w[title verb path versions query doc_title request_data response_data code show_in_doc recorded].each do |k|
next unless call.has_key?(k)
ordered_call[k] = case call[k]
when ActiveSupport::HashWithIndifferentAccess
Expand Down