Module: Napa::RspecExtensions::ResponseHelpers
- Defined in:
- lib/napa/rspec_extensions/response_helpers.rb
Instance Method Summary collapse
- #expect_count_of(count) ⇒ Object
- #expect_error_code(error_code) ⇒ Object
- #expect_only(object) ⇒ Object
- #expect_to_have(object) ⇒ Object
- #expect_to_not_have(object) ⇒ Object
- #first_result ⇒ Object
- #parsed_response ⇒ Object
- #response_body ⇒ Object
- #response_code ⇒ Object
- #result_count ⇒ Object
- #result_with_id(id) ⇒ Object
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_error_code(error_code) ⇒ Object
32 33 34 |
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 32 def expect_error_code(error_code) expect(parsed_response.error.code).to eq(error_code.to_s) end |
#expect_only(object) ⇒ Object
36 37 38 39 |
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 36 def expect_only(object) expect_count_of 1 expect(first_result.id).to eq(object.id) end |
#expect_to_have(object) ⇒ Object
41 42 43 |
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 41 def expect_to_have(object) expect(!result_with_id(object.id).nil?).to be_truthy end |
#expect_to_not_have(object) ⇒ Object
45 46 47 |
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 45 def expect_to_not_have(object) expect(!result_with_id(object.id).nil?).to be_falsy end |
#first_result ⇒ Object
20 21 22 |
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 20 def first_result parsed_response.data.first end |
#parsed_response ⇒ Object
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_body ⇒ Object
12 13 14 |
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 12 def response_body last_response.body end |
#response_code ⇒ Object
8 9 10 |
# File 'lib/napa/rspec_extensions/response_helpers.rb', line 8 def response_code last_response.status end |
#result_count ⇒ Object
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 |