Class: Adalog::MockLoggingAdapter::Base
- Inherits:
-
Object
- Object
- Adalog::MockLoggingAdapter::Base
- Defined in:
- lib/adalog/mock_logging_adapter.rb
Overview
Used as the superclass of all logging classes returned from ::new
Class Method Summary collapse
Instance Method Summary collapse
-
#_received_messages ⇒ Object
In case the service needs to stub-out a method named ‘messages’, we have this more direct, internal method name.
-
#initialize(**stub_method_overrides) ⇒ Base
constructor
Allows for overriding stubbed methods which were initially built into the mock adapter.
-
#messages ⇒ Object
Reader for the messages received by this mock, perhaps for use in testing details of particular calls.
-
#received?(message, exactly: :none, at_least: :none, at_most: :none) ⇒ Boolean
For use in simple boolean asserts, if all you need to test is the number of times a message was received.
- #repo ⇒ Object
-
#service_name ⇒ Object
Convenience instance method versions of class-level storage of service_name and repo.
Constructor Details
#initialize(**stub_method_overrides) ⇒ Base
Allows for overriding stubbed methods which were initially built into the mock adapter. Does not explicitly restrict “overriding” to existing stubs, and so can be used to add additional stubs to a specific instance.
77 78 79 80 81 |
# File 'lib/adalog/mock_logging_adapter.rb', line 77 def initialize(**stub_method_overrides) stub_method_overrides.each do |, value| define_singleton_method(, &MockLoggingAdapter.stub_method(, value)) end end |
Class Method Details
.repo ⇒ Object
70 |
# File 'lib/adalog/mock_logging_adapter.rb', line 70 def repo ; @repo ; end |
.service_name ⇒ Object
69 |
# File 'lib/adalog/mock_logging_adapter.rb', line 69 def service_name; @service_name ; end |
Instance Method Details
#_received_messages ⇒ Object
In case the service needs to stub-out a method named ‘messages’, we have this more direct, internal method name.
135 136 137 |
# File 'lib/adalog/mock_logging_adapter.rb', line 135 def @_received_messages ||= [] end |
#messages ⇒ Object
Reader for the messages received by this mock, perhaps for use in testing details of particular calls.
91 92 93 |
# File 'lib/adalog/mock_logging_adapter.rb', line 91 def end |
#received?(message, exactly: :none, at_least: :none, at_most: :none) ⇒ Boolean
For use in simple boolean asserts, if all you need to test is the number of times a message was received. Flexible keyword arguments, which the the following precedence and details:
-
If :exactly is specified, will return true only if the message count is exactly the value of :exactly.
-
When :exactly is specified, :at_least and :at_most are ignored.
-
If :at_least is specified, will return true only if the message count is equal to or greater than the value of :at_least.
-
If :at_most is specified, will return true only if the message count is equal to or less than the value of :at_most.
-
:at_least and :at_most can be used simultaneously, and will return true if the message count falls in the range (at_least..at_most), that is, inclusive.
-
If no keyword options are specified, the default behavior is equivalent to calling with the option ‘at_least: 1`.
Consequently, this method is as flexible as possible, to allow for expressive assertions in tests, such as:
received?('unsubscribe', at_least: 1)
received?('generate', exactly: 3)
received?('toggle', at_least: 2, at_most: 4)
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/adalog/mock_logging_adapter.rb', line 117 def received?(, exactly: :none, at_least: :none, at_most: :none) recv_count = .select { |recv| recv. == }.count return recv_count == exactly unless :none == exactly # Substitute a default "at_least: 1" behavior for no options given. if :none == at_least and :none == at_most at_least = 1 end result = true result = result && recv_count >= at_least unless :none == at_least result = result && recv_count <= at_most unless :none == at_most result end |
#repo ⇒ Object
86 |
# File 'lib/adalog/mock_logging_adapter.rb', line 86 def repo ; self.class.repo ; end |
#service_name ⇒ Object
Convenience instance method versions of class-level storage of service_name and repo.
85 |
# File 'lib/adalog/mock_logging_adapter.rb', line 85 def service_name; self.class.service_name ; end |