Module: Outbacker
- Includes:
- Configurations
- Included in:
- OutbackerStub
- Defined in:
- lib/test_support/outbacker_stub.rb,
lib/outbacker.rb,
lib/outbacker/version.rb
Overview
Provides a simple means to stub “Outbacked” methods. Specifically, it lets you specify what outcome callback you want invoked on your stubbed method.
Usage: stubbed_object = OutbackerStub.new stubbed_object.stub(‘stubbed_method_name’,
:desired_outcome,
block_arg1, block_arg2, ...)
Alternatively, combine instantiation and stubbing: stubbed_object = OutbackerStub.new(‘stubbed_method_name’,
:desired_outcome,
block_arg1, block_arg2, ...)
Note that this only provides stubbing functionality, no mocking functionality (i.e., ability to verify that a method was invoked on a test double) is provided. This should be sufficient for your test needs, as you can/should write separate tests to verify that the expected methods were invoked on your double.
Defined Under Namespace
Classes: OutbackerStub, OutcomeHandlerSet
Constant Summary collapse
- DEFAULT_BLACKLIST =
[ActiveRecord::Base, ActionController::Base]
- DEFAULT_WHITELIST =
[]
- VERSION =
"0.1.2"
Class Method Summary collapse
- .apply_blacklist(target_module) ⇒ Object
- .apply_whitelist(target_module) ⇒ Object
-
.included(target_module) ⇒ Object
Restrict where Outbacker can be included.
Instance Method Summary collapse
-
#with(outcome_handlers) {|outcome_handler_set| ... } ⇒ Object
DSL-ish factory method to create an instance of OutcomeHandlerSet given a block of outcome handlers.
Class Method Details
.apply_blacklist(target_module) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/outbacker.rb', line 123 def self.apply_blacklist(target_module) Outbacker.configuration.blacklist.each do |blacklisted_class| if target_module.ancestors.include?(blacklisted_class) fail "Cannot include #{self.name} within an #{blacklisted_class} class, a plain-old Ruby object is preferred." end end end |
.apply_whitelist(target_module) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/outbacker.rb', line 116 def self.apply_whitelist(target_module) Outbacker.configuration.whitelist.each do |whitelisted_classs| return if target_module.ancestors.include?(whitelisted_classs) end fail "Can only include #{self.name} within a subclass of: #{Outbacker.configuration.whitelist.join(', ')}" end |
.included(target_module) ⇒ Object
Restrict where Outbacker can be included.
111 112 113 114 |
# File 'lib/outbacker.rb', line 111 def self.included(target_module) apply_whitelist(target_module) if Outbacker.configuration.whitelist.any? apply_blacklist(target_module) if Outbacker.configuration.blacklist.any? end |
Instance Method Details
#with(outcome_handlers) {|outcome_handler_set| ... } ⇒ Object
DSL-ish factory method to create an instance of OutcomeHandlerSet given a block of outcome handlers.
To be used within your business-logic methods in combination with the OutcomeHandlerSet#handle method.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/outbacker.rb', line 24 def with(outcome_handlers) outcome_handler_set = OutcomeHandlerSet.new(outcome_handlers) yield outcome_handler_set if outcome_handlers.nil? return outcome_handler_set.triggered_outcome, *outcome_handler_set.args else raise "No outcome selected" unless outcome_handler_set.outcome_handled? end end |