Module: EvelpidonTestHelpers::ActiveModel::Observers::Assertions

Included in:
ActiveSupport::TestCase
Defined in:
lib/evelpidon_test_helpers/active_model/observers.rb

Instance Method Summary collapse

Instance Method Details

#assert_observer_not_notified(observer, notification, options = {}) ⇒ Object

Asserts that the given observer class will never receive the notification.

Parameters:

  • observer (Class)

    the observer class

  • notification (Symbol)

    the notification

  • options (Hash) (defaults to: {})

    extra options



24
25
26
# File 'lib/evelpidon_test_helpers/active_model/observers.rb', line 24

def assert_observer_not_notified(observer, notification, options = {})
  observer.instance.expects(notification).never
end

#assert_observer_notified(observer, notification, options = {}) ⇒ Object

Asserts that the given observer class will receive the notification.

Parameters:

  • observer (Class)

    the observer class

  • notification (Symbol)

    the notification

  • options (Hash) (defaults to: {})

    extra options :

    • :object [Object, Mocha::ParameterMatchers::Base] the object that should be passed to the observer.

    • :times [Integer] the number of times that the notification should be sent to the observer.



13
14
15
16
# File 'lib/evelpidon_test_helpers/active_model/observers.rb', line 13

def assert_observer_notified(observer, notification, options = {})
  options.reverse_merge!(:times => 1, :object => anything)
  observer.instance.expects(notification).with(options[:object]).times(options[:times])
end