Module: Airborne

Includes:
RequestExpectations
Defined in:
lib/airborne/base.rb,
lib/airborne/path_matcher.rb,
lib/airborne/rack_test_requester.rb,
lib/airborne/request_expectations.rb,
lib/airborne/rest_client_requester.rb,
lib/airborne/optional_hash_type_expectations.rb

Defined Under Namespace

Modules: PathMatcher, RackTestRequester, RequestExpectations, RestClientRequester Classes: ExpectationError, InvalidJsonError, OptionalHashTypeExpectations, PathError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RequestExpectations

#date, #expect_header, #expect_header_contains, #expect_json, #expect_json_keys, #expect_json_sizes, #expect_json_types, #expect_status, #optional, #regex

Methods included from PathMatcher

#get_by_path

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



10
11
12
# File 'lib/airborne/base.rb', line 10

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



10
11
12
# File 'lib/airborne/base.rb', line 10

def headers
  @headers
end

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/airborne/base.rb', line 10

def response
  @response
end

Class Method Details

.configurationObject



28
29
30
# File 'lib/airborne/base.rb', line 28

def self.configuration
  RSpec.configuration
end

.configureObject



12
13
14
15
16
# File 'lib/airborne/base.rb', line 12

def self.configure
  RSpec.configure do |config|
    yield config
  end
end

.included(base) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/airborne/base.rb', line 18

def self.included(base)
  if !Airborne.configuration.requester_module.nil?
    base.send(:include, Airborne.configuration.requester_module)
  elsif !Airborne.configuration.rack_app.nil?
    base.send(:include, RackTestRequester)
  else
    base.send(:include, RestClientRequester)
  end
end

Instance Method Details

#delete(url, delete_body = nil, headers = nil, timeout = base_timeout) ⇒ Object



48
49
50
# File 'lib/airborne/base.rb', line 48

def delete(url, delete_body = nil, headers = nil, timeout = base_timeout)
  @response = make_request(:delete, url, body: delete_body, headers: headers, timeout: timeout)
end

#get(url, headers = nil, timeout = base_timeout) ⇒ Object



32
33
34
# File 'lib/airborne/base.rb', line 32

def get(url, headers = nil, timeout = base_timeout)
  @response = make_request(:get, url, headers: headers, timeout: timeout)
end

#head(url, headers = nil, timeout = base_timeout) ⇒ Object



52
53
54
# File 'lib/airborne/base.rb', line 52

def head(url, headers = nil, timeout = base_timeout)
  @response = make_request(:head, url, headers: headers, timeout: timeout)
end

#json_bodyObject



72
73
74
# File 'lib/airborne/base.rb', line 72

def json_body
  JSON.parse(response.body, symbolize_names: true) rescue fail InvalidJsonError, 'Api request returned invalid json'
end

#options(url, headers = nil, timeout = base_timeout) ⇒ Object



56
57
58
# File 'lib/airborne/base.rb', line 56

def options(url, headers = nil, timeout = base_timeout)
  @response = make_request(:options, url, headers: headers, timeout: timeout)
end

#patch(url, patch_body = nil, headers = nil, timeout = base_timeout) ⇒ Object



40
41
42
# File 'lib/airborne/base.rb', line 40

def patch(url, patch_body = nil, headers = nil, timeout = base_timeout)
  @response = make_request(:patch, url, body: patch_body, headers: headers, timeout: timeout)
end

#post(url, post_body = nil, headers = nil, timeout = base_timeout) ⇒ Object



36
37
38
# File 'lib/airborne/base.rb', line 36

def post(url, post_body = nil, headers = nil, timeout = base_timeout)
  @response = make_request(:post, url, body: post_body, headers: headers, timeout: timeout)
end

#put(url, put_body = nil, headers = nil, timeout = base_timeout) ⇒ Object



44
45
46
# File 'lib/airborne/base.rb', line 44

def put(url, put_body = nil, headers = nil, timeout = base_timeout)
  @response = make_request(:put, url, body: put_body, headers: headers, timeout: timeout)
end