Module: RspecApiDocs::Dsl

Defined in:
lib/rspec_api_docs/dsl.rb,
lib/rspec_api_docs/dsl/doc_proxy.rb,
lib/rspec_api_docs/dsl/request_store.rb

Overview

This module is intended to be included in your RSpec specs to expose the #doc method.

Defined Under Namespace

Classes: DocProxy, RequestStore

Instance Method Summary collapse

Instance Method Details

#doc(should_document = true, &block) ⇒ RequestStore?

DSL method for use in your RSpec examples.

Usage:

it 'returns a character' do
  doc do
    title 'Returns a Character'
    description 'Allows you to return a single character.'
    path '/characters/:id'

    param :id, 'The id of a character', required: true

    field :id, 'The id of a character', scope: :character
    field :name, "The character's name", scope: :character
  end

  get '/characters/1'
end

For more info on the methods available in the block, see DocProxy.

Parameters:

  • should_document (true, false) (defaults to: true)

    clear documentation metadata for the example

Returns:

  • (RequestStore, nil)

    an object to store request/response pairs


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rspec_api_docs/dsl.rb', line 32

def doc(should_document = true, &block)
  if should_document
    example.[METADATA_NAMESPACE] ||= {}

    if block
      DocProxy.new(example).instance_eval(&block)
    end

    RequestStore.new(example)
  else
    example.[METADATA_NAMESPACE] = nil
  end
end