From 5b9a7ce1b7358f7262bd7c9454e83ac93a571b4a Mon Sep 17 00:00:00 2001 From: Paul Martensen Date: Wed, 17 Jan 2018 09:45:12 +0100 Subject: [PATCH 1/4] Added doc_title to recorder. --- lib/apipie/extractor/recorder.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/apipie/extractor/recorder.rb b/lib/apipie/extractor/recorder.rb index 552b384b3..7e224e3d4 100644 --- a/lib/apipie/extractor/recorder.rb +++ b/lib/apipie/extractor/recorder.rb @@ -105,6 +105,7 @@ def record if @controller {:controller => @controller, :action => @action, + :doc_title => doc_title, :verb => @verb, :path => @path, :params => @params, @@ -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 From d563ee8c4a8d4b1a15f24136dac10881788905fa Mon Sep 17 00:00:00 2001 From: Paul Martensen Date: Wed, 17 Jan 2018 09:45:30 +0100 Subject: [PATCH 2/4] Added doc title to writer. --- lib/apipie/extractor/writer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/apipie/extractor/writer.rb b/lib/apipie/extractor/writer.rb index e180143a5..cadb2a203 100644 --- a/lib/apipie/extractor/writer.rb +++ b/lib/apipie/extractor/writer.rb @@ -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 From 297a2603d524f838fabbe34be424c4e1ee1d4d51 Mon Sep 17 00:00:00 2001 From: Paul Martensen Date: Wed, 17 Jan 2018 11:08:39 +0100 Subject: [PATCH 3/4] Added doc_title description to readme. --- README.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.rst b/README.rst index 0092e8852..95978adc5 100644 --- a/README.rst +++ b/README.rst @@ -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`` +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 ------- From f2c5b51c3ad39a9c027d4f7deed8f8d3c6e82f51 Mon Sep 17 00:00:00 2001 From: Paul Martensen Date: Thu, 18 Jan 2018 09:25:01 +0100 Subject: [PATCH 4/4] Empty commit to trigger travis build.