Sha256: bb1879f66e964c78589b4f08d7f5fb81a761803212c2093441e03f5f39ce6052

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

module Gris
  module RspecExtensions
    module ResponseHelpers
      def response_code
        last_response.status
      end

      def response_body
        last_response.body
      end

      def parsed_response
        Hashie::Mash.new(JSON.parse(last_response.body))
      end

      def result
        parsed_response
      end

      def embedded_results(klass)
        parsed_response[:_embedded][klass.name.tableize.to_sym]
      end

      def embedded_results_count(klass)
        embedded_results(klass).count
      end

      def expect_embedded_results_count_of(count, klass)
        expect(embedded_results_count(klass)).to eq(count)
      end

      def first_embedded_result(klass)
        embedded_results(klass).first
      end

      def embedded_result_with_id(id, klass)
        embedded_results(klass).select { |r| r.id == id }.first
      end

      def links
        parsed_response['_links']
      end

      def link_to_self
        links['self']
      end

      def link_to_next
        links['next']
      end

      def link_to_previous
        links['prev']
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gris-0.1.0 lib/gris/rspec_extensions/response_helpers.rb
gris-0.0.9 lib/gris/rspec_extensions/response_helpers.rb
gris-0.0.8 lib/gris/rspec_extensions/response_helpers.rb
gris-0.0.7 lib/gris/rspec_extensions/response_helpers.rb
gris-0.0.6 lib/gris/rspec_extensions/response_helpers.rb
gris-0.0.5 lib/gris/rspec_extensions/response_helpers.rb
gris-0.0.4 lib/gris/rspec_extensions/response_helpers.rb
gris-0.0.3 lib/gris/rspec_extensions/response_helpers.rb
gris-0.0.2 lib/gris/rspec_extensions/response_helpers.rb