module Calabash::Cucumber::ConnectionHelpers

@!visibility private

Public Instance Methods

connection() click to toggle source

@!visibility private

# File lib/calabash-cucumber/connection_helpers.rb, line 18
def connection
  Calabash::Cucumber::Connection.instance
end
http(*args) click to toggle source

@!visibility private

# File lib/calabash-cucumber/connection_helpers.rb, line 13
def http(*args)
  connection.http(*args)
end
response_body_to_hash(body) click to toggle source

@!visibility private

# File lib/calabash-cucumber/connection_helpers.rb, line 23
      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