Sha256: 4b8baa62f06431b92a2f748ba9a709ee4354cf9f5e08f5494538fed6d8ff25dd

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

require 'sanford-protocol'

require 'sanford/logger'
require 'sanford/runner'

module Sanford

  class TestRunner
    include Sanford::Runner::HaltMethods

    attr_reader :handler, :response, :request, :logger

    def initialize(handler_class, params = {}, logger = nil)
      @handler_class  = handler_class
      @request        = params.kind_of?(Sanford::Protocol::Request) ? params : test_request(params)
      @logger         = logger || Sanford::NullLogger.new

      @handler  = @handler_class.new(self)
      @response = build_response catch(:halt){ @handler.init; nil }
    end

    def run
      @response ||= build_response catch_halt{ @handler.run }
    end

    protected

    def test_request(params)
      Sanford::Protocol::Request.new('test_version', 'test_service', params)
    end

    def build_response(response_args)
      Sanford::Protocol::Response.new(response_args.status, response_args.data) if response_args
    end

    module Helpers
      module_function

      def test_runner(*args)
        TestRunner.new(*args)
      end

    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sanford-0.4.0 lib/sanford/test_runner.rb
sanford-0.3.0 lib/sanford/test_runner.rb
sanford-0.2.0 lib/sanford/test_runner.rb