Module: Mollie::SMS::TestHelper::SMSExt::ClassMethods

Defined in:
lib/mollie/sms/test_helper.rb

Instance Method Summary collapse

Instance Method Details

#deliveriesArray<Mollie::SMS>

Returns A list of sent SMS messages.

Returns:

  • (Array<Mollie::SMS>)

    A list of sent SMS messages.

See Also:


118
119
120
# File 'lib/mollie/sms/test_helper.rb', line 118

def deliveries
  @deliveries ||= []
end

#gateway_failure!Response

Stubs a ‘gateway failure’ Response instance.

This means that any following calls to Mollie::SMS#deliver will fail at the gateway and return the stubbed ‘gateway failure’ Response instance.

Mollie::SMS.gateway_failure!
response = Mollie::SMS.new(number, body).deliver
response.success? # => false
response.result_code # => 20
response.message # => "No username given."

Returns:

  • (Response)

    The stubbed ‘gateway failure’ Response instance.


165
166
167
168
169
170
171
# File 'lib/mollie/sms/test_helper.rb', line 165

def gateway_failure!
  http_response = Net::HTTPOK.new('1.1', '200', 'OK')
  http_response.add_field('Content-type', 'application/xml')
  # @private
  def http_response.read_body; TestHelper::FAILURE_BODY; end
  @stubbed_response = Mollie::SMS::Response.new(http_response)
end

#http_failure!Response

Stubs a ‘HTTP failure’ Response instance.

This means that any following calls to Mollie::SMS#deliver will fail at the HTTP level and return the stubbed ‘HTTP failure’ Response instance.

Mollie::SMS.http_failure!
response = Mollie::SMS.new(number, body).deliver
response.success? # => false
response.result_code # => 400
response.message # => "[HTTP: 400] Bad request"

Returns:

  • (Response)

    The stubbed ‘HTTP failure’ Response instance.


187
188
189
# File 'lib/mollie/sms/test_helper.rb', line 187

def http_failure!
  @stubbed_response = Mollie::SMS::Response.new(Net::HTTPBadRequest.new('1.1', '400', 'Bad request'))
end

#reset!Response

Clears the deliveries list and stubs a ‘success’ Response instance.

Returns:

  • (Response)

    The stubbed ‘success’ Response instance.


126
127
128
129
# File 'lib/mollie/sms/test_helper.rb', line 126

def reset!
  @deliveries = []
  success!
end

#stubbed_responseResponse

The stubbed Response instance that will be returned for all requests from Mollie::SMS#deliver.

Returns:


194
195
196
# File 'lib/mollie/sms/test_helper.rb', line 194

def stubbed_response
  @stubbed_response || success!
end

#success!Response

Stubs a ‘success’ Response instance.

This means that any following calls to Mollie::SMS#deliver will succeed and return the stubbed ‘success’ Response instance.

Mollie::SMS.success!
response = Mollie::SMS.new(number, body).deliver
response.success? # => true
response.result_code # => 10
response.message # => "Message successfully sent."

Returns:

  • (Response)

    The stubbed ‘success’ Response instance.


143
144
145
146
147
148
149
# File 'lib/mollie/sms/test_helper.rb', line 143

def success!
  http_response = Net::HTTPOK.new('1.1', '200', 'OK')
  http_response.add_field('Content-type', 'application/xml')
  # @private
  def http_response.read_body; TestHelper::SUCCESS_BODY; end
  @stubbed_response = Mollie::SMS::Response.new(http_response)
end