Sha256: 1cb770104939a14cdaa491554fa3869bb674c7e9b6c91625929b9323c219d979

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

module EvelpidonTestHelpers
  module ActiveModel
    module Observers
      module Assertions
        # Asserts that the given +observer+ class will receive the +notification+.
        #
        # @param observer [Class] the observer class
        # @param notification [Symbol] the notification
        # @param options [Hash] 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.
        #
        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

        # Asserts that the given +observer+ class will never receive the +notification+.
        #
        # @param observer [Class] the observer class
        # @param notification [Symbol] the notification
        # @param options [Hash] extra options
        #
        def assert_observer_not_notified(observer, notification, options = {})
          observer.instance.expects(notification).never
        end
      end
    end
  end
end

module ActiveSupport
  class TestCase
    include EvelpidonTestHelpers::ActiveModel::Observers::Assertions
  end
end if defined?(ActiveModel)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
evelpidon_test_helpers-0.3.1 lib/evelpidon_test_helpers/active_model/observers.rb
evelpidon_test_helpers-0.3.0 lib/evelpidon_test_helpers/active_model/observers.rb
evelpidon_test_helpers-0.2.0 lib/evelpidon_test_helpers/active_model/observers.rb