Sha256: f823b728645c26a372077911b5b5ba632098c556737a28aeae211a984cb075fd

Contents?: true

Size: 1.61 KB

Versions: 21

Compression:

Stored size: 1.61 KB

Contents

require 'calabash-cucumber/connection'

module Calabash
  module Cucumber

    # @!visibility private
    class ResponseError < RuntimeError ; end

    # @!visibility private
    module ConnectionHelpers

      # @!visibility private
      def http(*args)
        connection.http(*args)
      end

      # @!visibility private
      def connection
        Calabash::Cucumber::Connection.instance
      end

      # @!visibility private
      def response_body_to_hash(body)
        if body.nil? || body == ""
          raise ResponseError,
            "Server replied with an empty response.  Your app has probably crashed"
        end

        begin
          hash = JSON.parse(body)
        rescue TypeError, JSON::ParserError => e
          raise ResponseError,
%Q{Could not parse server response '#{body}':

#{e}

This usually means your app has crashed.
}
        end

        outcome = hash['outcome']

        case outcome
          when 'FAILURE'
            reason = hash['reason']
            if reason.nil? || reason.empty?
              hash['reason'] = 'Server provided no reason.'
            end

            details = hash['details']
            if details.nil? || details.empty?
              hash['details'] = 'Server provided no details.'
            end

          when 'SUCCESS'
            if !hash.has_key?('results')
              raise ResponseError,
%Q{Server responded with '#{outcome}'
but response #{hash} does not contain 'results' key
}
            end
          else
            raise ResponseError,
%Q{Server responded with an invalid outcome: '#{hash["outcome"]}'}
        end
        hash
      end

    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
calabash-cucumber-0.23.7 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.23.6 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.23.5 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.23.4 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.23.3 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.23.2 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.23.1 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.23.0 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.22.2 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.21.10 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.21.8 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.21.7 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.21.6 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.21.5 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.21.4 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.21.2 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.21.1 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.20.5 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.20.4 lib/calabash-cucumber/connection_helpers.rb
calabash-cucumber-0.20.3 lib/calabash-cucumber/connection_helpers.rb