Sha256: c5eee2bbac3c9c5d9685fdc1d04edac37588cd507ad44446d060b32982ca1a5e

Contents?: true

Size: 733 Bytes

Versions: 6

Compression:

Stored size: 733 Bytes

Contents

require 'json'

module InfinumJsonApiSetup
  module RSpec
    module Matchers
      module Util
        class BodyParser
          # @param [String] attribute
          def initialize(attribute)
            @attribute = attribute
          end

          # @param [ActionDispatch::TestResponse] response
          # @return [Array]
          def process(response)
            [true, JSON.parse(response.body).fetch(attribute)]
          rescue JSON::ParserError => _e
            [false, 'Failed to parse response body']
          rescue KeyError => _e
            [false, "Failed to extract #{attribute} from response body"]
          end

          private

          attr_reader :attribute
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
infinum_json_api_setup-0.0.8 lib/infinum_json_api_setup/rspec/matchers/util/body_parser.rb
infinum_json_api_setup-0.0.7 lib/infinum_json_api_setup/rspec/matchers/util/body_parser.rb
infinum_json_api_setup-0.0.6 lib/infinum_json_api_setup/rspec/matchers/util/body_parser.rb
infinum_json_api_setup-0.0.5 lib/infinum_json_api_setup/rspec/matchers/util/body_parser.rb
infinum_json_api_setup-0.0.4 lib/infinum_json_api_setup/rspec/matchers/util/body_parser.rb
infinum_json_api_setup-0.0.3 spec/infinum_json_api_setup/rspec/matchers/util/body_parser.rb