Module: ServiceResponseHelpers

Defined in:
lib/rspec/helpers/response_service_helper.rb

Overview

Lesli

Copyright © 2023, Lesli Technologies, S. A.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see www.gnu.org/licenses/.

Lesli · Ruby on Rails Development Platform.

Made with ♥ by www.lesli.tech Building a better future, one line of code at a time.

// · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ // ·

Constant Summary collapse

@@service_response =

container for the response body parsed as JSON

nil

Instance Method Summary collapse

Instance Method Details

#expect_service_response_with_error(response) ⇒ Object

test a standard error response



55
56
57
58
59
60
61
62
63
64
# File 'lib/rspec/helpers/response_service_helper.rb', line 55

def expect_service_response_with_error(response)
    @@service_response = nil
    expect(response.success?).to eq(false)
    expect(response.successful?).to eq(false)

    # If the response is not successful, the error could be present, but the payload should be nil
    expect(response.payload).to be_nil

    @@service_response = response.error
end

#expect_service_response_with_successful(response) ⇒ Object

test a standard successful response



43
44
45
46
47
48
49
50
51
52
# File 'lib/rspec/helpers/response_service_helper.rb', line 43

def expect_service_response_with_successful(response)
    @@service_response = nil
    expect(response.success?).to eq(true)
    expect(response.successful?).to eq(true)

    # If the response is successful, the payload could be present, but the error should be nil
    expect(response.error).to be_nil

    @@service_response = response.payload
end

#service_response_bodyObject



38
39
40
# File 'lib/rspec/helpers/response_service_helper.rb', line 38

def service_response_body
    @@service_response
end