Module: HaveAPI::SpecMethods

Includes:
Rack::Test::Methods
Defined in:
lib/haveapi/spec/helpers.rb

Overview

Helper methods for specs.

Defined Under Namespace

Classes: ApiResponse

Instance Method Summary collapse

Instance Method Details

#api(http_method, url, params = {}) ⇒ Object

Make API request. This method is a wrapper for Rack::Test::Methods. Input parameters are encoded into JSON and sent with correct Content-Type.



90
91
92
93
94
95
96
# File 'lib/haveapi/spec/helpers.rb', line 90

def api(http_method, url, params={})
  method(http_method).call(
      url,
      params.to_json,
      {'Content-Type' => 'application/json'}
  )
end

#api_responseObject

Return parsed API response.



99
100
101
# File 'lib/haveapi/spec/helpers.rb', line 99

def api_response
  @api_response ||= ApiResponse.new(last_response.body)
end

#appObject



73
74
75
76
77
78
79
80
# File 'lib/haveapi/spec/helpers.rb', line 73

def app
  api = HaveAPI::Server.new
  api.auth_chain << @auth_chain if @auth_chain
  api.use_version(@versions || :all)
  api.set_default_version(@default_version) if @default_version
  api.mount(@mount || '/')
  api.app
end

#login(*credentials) ⇒ Object

Login with HTTP basic auth.



83
84
85
# File 'lib/haveapi/spec/helpers.rb', line 83

def (*credentials)
  basic_authorize(*credentials)
end