Sha256: 0dac083c6596da6e0a5e45c9df58e39d294de94c8b7576b1d06af58aa3fb8f89

Contents?: true

Size: 819 Bytes

Versions: 3

Compression:

Stored size: 819 Bytes

Contents

class FakeConnection

  attr_reader :read_data, :response

  def self.with_request(version, name, params = {}, raise_on_write = false)
    request = Sanford::Protocol::Request.new(version, name, params)
    self.new(request.to_hash, raise_on_write)
  end

  def initialize(*args)
    if args.first.kind_of?(Sanford::Protocol::Connection)
      protocol_connection = args.first
      @read_data = proc{ protocol_connection.read }
      @write_data = proc{|data| protocol_connection.write(data) }
    else
      @read_data, @raise_on_write = args
    end
  end

  def read_data
    @read_data.kind_of?(Proc) ? @read_data.call : @read_data
  end

  def write_data(data)
    if @raise_on_write
      @raise_on_write = false
      raise 'test fail'
    end
    @response = Sanford::Protocol::Response.parse(data)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sanford-0.6.2 test/support/fake_connection.rb
sanford-0.6.1 test/support/fake_connection.rb
sanford-0.6.0 test/support/fake_connection.rb