Module: Mollie::SMS::TestHelper::Assertions

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

Overview

A couple of Test::Unit assertions, to test the amount of sent messages.

Instance Method Summary collapse

Instance Method Details

#assert_no_sms_messages { ... } ⇒ nil

Asserts that no SMS messages have been sent, for the duration of the given block.

def 
  assert_no_sms_messages do
    Account.create(:telephone_number => "invalid")
  end
end

Yields:

  • The context that will be used to check the number of sent messages.

Returns:

  • (nil)

See Also:


73
74
75
# File 'lib/mollie/sms/test_helper.rb', line 73

def assert_no_sms_messages
  assert_sms_messages(0) { yield }
end

#assert_sms_messages(number_of_messages) { ... } ⇒ nil

Asserts that a specific number of SMS messages have been sent, for the duration of the given block.

def test_invitation_message_is_sent
  assert_sms_messages(1) do
    Account.create(:telephone_number => "+31621212121")
  end
end

Yields:

  • The context that will be used to check the number of sent messages.

Returns:

  • (nil)

See Also:


50
51
52
53
54
55
# File 'lib/mollie/sms/test_helper.rb', line 50

def assert_sms_messages(number_of_messages)
  before = Mollie::SMS.deliveries.length
  yield
  diff = Mollie::SMS.deliveries.length - before
  assert(diff == number_of_messages, "expected `#{number_of_messages}' SMS messages to be sent, actually sent `#{diff}'")
end