Sha256: 7ee1576e559d9dc6c2fbaf7f350b1633d94c75182f8190e3ef6f3782076f705b

Contents?: true

Size: 1.04 KB

Versions: 15

Compression:

Stored size: 1.04 KB

Contents

module RspecApiDocs
  module Dsl
    # Used to store request/response pairs.
    class RequestStore
      attr_reader :metadata

      def initialize(example)
        @metadata = example.metadata
      end

      # 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
      #
      # @param value [Array<Rack::Request, Rack::Response>] an array of a request and response object
      # @return [void]
      def <<(value)
        metadata[METADATA_NAMESPACE][:requests] ||= []
        metadata[METADATA_NAMESPACE][:requests] << value.sort_by { |v| v.class.name }.reverse
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rspec-api-docs-1.1.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-1.0.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.14.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.13.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.12.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.11.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.10.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.9.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.8.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.7.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.6.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.5.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.4.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.3.0 lib/rspec_api_docs/dsl/request_store.rb
rspec-api-docs-0.2.0 lib/rspec_api_docs/dsl/request_store.rb