Sha256: 25ecf570b8551a196a0bec56d5e59932578ce8df1f57f8c7e71677eb235aebe2

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

module TestsDoc

  module RecordSpecHelper

    def recording_api_interaction(path: nil, key: nil, description: nil, whitelist: nil)
      TestsDoc.recorded_api_interaction = true
      TestsDoc.interaction_options      = OpenStruct.new(path: path, key: key, description: description, whitelist: whitelist)

      yield TestsDoc.interaction_options
    ensure
      TestsDoc.interaction_options = nil
    end

    def get(*)
      record_interaction { super }
    end

    def post(*)
      record_interaction { super }
    end

    def put(*)
      record_interaction { super }
    end

    def delete(*)
      record_interaction { super }
    end

    private

      def record_interaction
        result = yield

        if TestsDoc.interaction_options
          TestsDoc::Interaction.new(
            RSpec.respond_to?(:current_example) ? RSpec.current_example : example,
            request,
            response,
            TestsDoc.interaction_options
          ).record
        end

        result
      end

    # /private

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tests_doc-0.0.6 lib/tests_doc/record_spec_helper.rb
tests_doc-0.0.5 lib/tests_doc/record_spec_helper.rb
tests_doc-0.0.4 lib/tests_doc/record_spec_helper.rb
tests_doc-0.0.3 lib/tests_doc/record_spec_helper.rb
tests_doc-0.0.2 lib/tests_doc/record_spec_helper.rb