Sha256: 4363554499d30a898d57246f565fd51397a3dabb0e44aa1d372e6fb5f4879aa0

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

require 'fitting/report/response'

module Fitting
  module Report
    class Responses
      def initialize(responses)
        @responses = responses
        @responses = []
        responses.to_a.map do |response|
          @responses.push(Fitting::Report::Response.new(response))
        end
      end

      def to_a
        @responses
      end

      def join(tests)
        tests.to_a.map do |test|
          if there_a_suitable_response?(test)
            cram_into_the_appropriate_response(test)
            test.mark_response
          end
        end
      end

      def there_a_suitable_response?(test)
        return false if @responses.nil?

        @responses.map do |response|
          return true if response.status.to_s == test.status &&
                         JSON::Validator.fully_validate(response.body, test.body) == []
        end

        false
      end

      def cram_into_the_appropriate_response(test)
        @responses.map do |response|
          next unless response.status.to_s == test.status &&
                      JSON::Validator.fully_validate(response.body, test.body) == []

          response.add_test(test)
          break
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fitting-3.0.2 lib/fitting/report/responses.rb
fitting-3.0.1 lib/fitting/report/responses.rb
fitting-3.0.0 lib/fitting/report/responses.rb
fitting-2.18.3 lib/fitting/report/responses.rb
fitting-2.18.2 lib/fitting/report/responses.rb
fitting-2.18.1 lib/fitting/report/responses.rb
fitting-2.18.0 lib/fitting/report/responses.rb