Sha256: 5a8b2bb0f2916473ad1f48beccec197212449e64283c93d61f57a481143e48c2

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe Snapme::Snapper do
  let(:host)      { 'http://example.com' }
  let(:interval)  { double :interval     }
  let(:auth_token){ double :auth_token   }
  let(:command)   { double :command      }

  subject(:snapper){ described_class.new(host, interval, auth_token, command) }

  describe '#run' do
    it 'takes a snapshot' do
      expect(command).to receive(:call).with(snapper.filename)
      snapper.run(false) # do not loop
    end

    it 'posts the snapshot to the web' do
      allow(command).to receive(:call)
      curl  = double 'Curl::Easy'
      file  = double 'Curl::PostField - file'
      token = double 'Curl::PostField - token'

      # Hint: The number of mocks here is probably a hint that we're missing an
      # object. I'm willing to accept this for now...
      expect(Curl::Easy).to receive(:new).with(snapper.endpoint_url).and_return(curl)
      expect(Curl::PostField).to receive(:file)
        .with(snapper.file_field_name, snapper.filename)
        .and_return(file)
      expect(Curl::PostField).to receive(:content)
        .with(snapper.auth_token_field_name, auth_token)
        .and_return(token)
      expect(curl).to receive(:multipart_form_post=).with(true)
      expect(curl).to receive(:http_post).with(file, token)

      snapper.run(false)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
snapme-0.2.2 spec/lib/snapme/snapper_spec.rb
snapme-0.2.1 spec/lib/snapme/snapper_spec.rb