module Outbacker

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.

Constants

DEFAULT_BLACKLIST
DEFAULT_WHITELIST
OutcomeHandlerSet

Class to encapsulate the processing of a block of outcome handlers.

VERSION

Public Class Methods

apply_blacklist(target_module) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Restrict where Outbacker can be included.

# 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

Public Instance Methods

with(outcome_handlers) { |outcome_handler_set| ... } click to toggle source

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.

# 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