Class: RspecApiDocs::Dsl::RequestStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_api_docs/dsl/request_store.rb

Overview

Used to store request/response pairs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ RequestStore


7
8
9
# File 'lib/rspec_api_docs/dsl/request_store.rb', line 7

def initialize(example)
   = example.
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata


5
6
7
# File 'lib/rspec_api_docs/dsl/request_store.rb', line 5

def 
  
end

Instance Method Details

#<<(value) ⇒ void

This method returns an undefined value.

Only needed if you need to store multiple requests for a single example.

Usage:

it 'stores the requests a character' do
  doc do
    explanation 'Creating and requesting a character'
  end

  post '/characters', {name: 'Finn The Human'}

  doc << [last_request, last_response]

  get '/characters/1'

  # The last request/response pair is stored automatically
end

31
32
33
34
# File 'lib/rspec_api_docs/dsl/request_store.rb', line 31

def <<(value)
  [][:requests] ||= []
  [][:requests] << value.sort_by { |v| v.class.name }.reverse
end