class Sanford::TestRunner

Public Class Methods

new(handler_class, args = nil) click to toggle source
Calls superclass method Sanford::Runner::new
# File lib/sanford/test_runner.rb, line 11
def initialize(handler_class, args = nil)
  if !handler_class.include?(Sanford::ServiceHandler)
    raise InvalidServiceHandlerError, "#{handler_class.inspect} is not a " \
                                      "Sanford::ServiceHandler"
  end

  a = (args || {}).dup
  super(handler_class, {
    :logger          => a.delete(:logger),
    :router          => a.delete(:router),
    :template_source => a.delete(:template_source),
    :request         => a.delete(:request),
    :params          => normalize_params(a.delete(:params) || {})
  })
  a.each{ |key, value| @handler.send("#{key}=", value) }

  @halted = false
  catch(:halt){ self.handler.sanford_init }
end

Public Instance Methods

halt(*args) click to toggle source

helpers

Calls superclass method Sanford::Runner#halt
# File lib/sanford/test_runner.rb, line 48
def halt(*args)
  @halted = true
  super
end
halted?() click to toggle source
# File lib/sanford/test_runner.rb, line 31
def halted?; @halted; end
run() click to toggle source
# File lib/sanford/test_runner.rb, line 33
def run
  catch(:halt){ self.handler.sanford_run } if !self.halted?
  self.to_response
end
to_response() click to toggle source

attempt to encode (and then throw away) the response this will error on the developer if it can't encode their response

Calls superclass method Sanford::Runner#to_response
# File lib/sanford/test_runner.rb, line 40
def to_response
  super.tap do |response|
    Sanford::Protocol.msg_body.encode(response.to_hash) if response
  end
end

Private Instance Methods

normalize_params(params) click to toggle source

stringify and encode/decode to ensure params are valid and are in the format they would normally be when a handler is built and run.

# File lib/sanford/test_runner.rb, line 57
def normalize_params(params)
  p = Sanford::Protocol::StringifyParams.new(params)
  Sanford::Protocol.msg_body.decode(Sanford::Protocol.msg_body.encode(p))
end