Sha256: 00ce3f4d94b683304f2aa0647b338fe2ce953523830741dc6889559f9b689486

Contents?: true

Size: 898 Bytes

Versions: 4

Compression:

Stored size: 898 Bytes

Contents

class FakeConnection

  attr_reader :read_data, :response, :write_stream_closed

  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

  def close_write
    @write_stream_closed = true
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sanford-0.7.0 test/support/fake_connection.rb
sanford-0.6.5 test/support/fake_connection.rb
sanford-0.6.4 test/support/fake_connection.rb
sanford-0.6.3 test/support/fake_connection.rb