Sha256: 3e0f69a31f0767dfdf1e1ff475590349b7204666bc17b2fea445cab5ccf0b0f5

Contents?: true

Size: 715 Bytes

Versions: 56

Compression:

Stored size: 715 Bytes

Contents

class FakeClient
  def initialize
    @data = {}
    @uploaded = {}
    @uploads = 0
    @downloads = 0
  end

  attr_reader :uploaded, :uploads, :downloads
  attr_accessor :delay, :error

  def []=(key, value)
    @data[key] = value
  end

  def download
    wait_for_delay
    raise_error_if_present
    @downloads += 1
    yield @data.dup
    nil
  end

  def upload(data)
    wait_for_delay
    raise_error_if_present
    @uploaded.update(data)
    @uploads += 1
  end

  def uploaded?
    @uploads > 0
  end

  def downloaded?
    @downloads > 0
  end

  private

  def wait_for_delay
    if delay
      sleep delay
    end
  end

  def raise_error_if_present
    if error
      raise error
    end
  end
end

Version data entries

56 entries across 56 versions & 2 rubygems

Version Path
copy_tuner_client-0.4.9 spec/support/fake_client.rb
copy_tuner_client-0.4.8 spec/support/fake_client.rb
copy_tuner_client-0.4.7 spec/support/fake_client.rb
copy_tuner_client-0.4.6 spec/support/fake_client.rb
copy_tuner_client-0.4.5 spec/support/fake_client.rb
copy_tuner_client-0.4.4 spec/support/fake_client.rb
copy_tuner_client-0.4.3 spec/support/fake_client.rb
copy_tuner_client-0.4.2 spec/support/fake_client.rb
copy_tuner_client-0.4.1 spec/support/fake_client.rb
copy_tuner_client-0.4.0 spec/support/fake_client.rb
copy_tuner_client-0.3.5 spec/support/fake_client.rb
copy_tuner_client-0.3.4 spec/support/fake_client.rb
copy_tuner_client-0.3.3 spec/support/fake_client.rb
copy_tuner_client-0.3.2 spec/support/fake_client.rb
copy_tuner_client-0.3.1 spec/support/fake_client.rb
copy_tuner_client-0.3.0 spec/support/fake_client.rb
copy_tuner_client-0.2.4 spec/support/fake_client.rb
copy_tuner_client-0.2.3 spec/support/fake_client.rb
copy_tuner_client-0.2.2 spec/support/fake_client.rb
copy_tuner_client-0.2.1 spec/support/fake_client.rb