Sha256: a0235f15ac4077eb8c35bede06c7e033ebd191562b5fa870ea9e765c7bb7b113

Contents?: true

Size: 953 Bytes

Versions: 3

Compression:

Stored size: 953 Bytes

Contents

module Napa
  module RspecExtensions
    module ResponseHelpers
      def parsed_response
        Hashie::Mash.new(JSON.parse(last_response.body))
      end

      def response_code
        last_response.status
      end

      def response_body
        last_response.body
      end
      
      def result_count
        parsed_response.data.count
      end

      def first_result
        parsed_response.data.first
      end

      def result_with_id(id)
        parsed_response.data.select { |r| r.id == id }.first
      end

      def expect_count_of(count)
        expect(result_count).to eq(count)
      end

      def expect_only(object)
        expect_count_of 1
        expect(first_result.id).to eq(object.id)
      end

      def expect_to_have(object)
        expect(!!result_with_id(object.id)).to be_truthy
      end

      def expect_to_not_have(object)
        expect(!!result_with_id(object.id)).to be_falsy
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
napa-0.4.3 lib/napa/rspec_extensions/response_helpers.rb
napa-0.4.1 lib/napa/rspec_extensions/response_helpers.rb
napa-0.4.0 lib/napa/rspec_extensions/response_helpers.rb