Module: Napa::RspecExtensions::ResponseHelpers

Defined in:
lib/napa/rspec_extensions/response_helpers.rb

Instance Method Summary collapse

Instance Method Details

#expect_count_of(count) ⇒ Object



28
29
30
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 28

def expect_count_of(count)
  expect(result_count).to eq(count)
end

#expect_only(object) ⇒ Object



32
33
34
35
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 32

def expect_only(object)
  expect_count_of 1
  expect(first_result.id).to eq(object.id)
end

#expect_to_have(object) ⇒ Object



37
38
39
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 37

def expect_to_have(object)
  expect(!!result_with_id(object.id)).to be_truthy
end

#expect_to_not_have(object) ⇒ Object



41
42
43
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 41

def expect_to_not_have(object)
  expect(!!result_with_id(object.id)).to be_falsy
end

#first_resultObject



20
21
22
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 20

def first_result
  parsed_response.data.first
end

#parsed_responseObject



4
5
6
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 4

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

#response_bodyObject



12
13
14
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 12

def response_body
  last_response.body
end

#response_codeObject



8
9
10
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 8

def response_code
  last_response.status
end

#result_countObject



16
17
18
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 16

def result_count
  parsed_response.data.count
end

#result_with_id(id) ⇒ Object



24
25
26
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 24

def result_with_id(id)
  parsed_response.data.select { |r| r.id == id }.first
end