Sha256: ebf747c83a4acba21a3e31c475f28c7a71b006344612a20f8dfedea7801ebb8d

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

describe NightcrawlerSwift::Download do

  let(:connection) { NightcrawlerSwift::Connection.new }
  let(:token) { "token" }
  let(:expires_at) { (DateTime.now + 60).to_time }
  let(:internal_url) { "server-url" }
  let(:bucket) { "rogue" }

  subject do
    NightcrawlerSwift::Download.new
  end

  before do
    allow(NightcrawlerSwift).to receive(:connection).and_return(connection)
    allow(connection).to receive(:token_id).and_return(token)
    allow(connection).to receive(:expires_at).and_return(expires_at)
    allow(connection).to receive(:internal_url).and_return(internal_url)
    NightcrawlerSwift.configure bucket: bucket
  end

  describe "#execute" do
    let :execute do
      subject.execute "file_path"
    end

    context "success" do
      let :response do
        double(:response, code: 200, body: "content")
      end

      before do
        allow(subject).to receive(:get).and_return(response)
      end

      it "gets using internal url" do
        execute
        expect(subject).to have_received(:get).with("server-url/#{bucket}/file_path")
      end

      it "returns body" do
        expect(execute).to eql "content"
      end
    end

    context "when the path was not informed" do
      it "raises NightcrawlerSwift::Exceptions::ValidationError" do
        expect { subject.execute nil }.to raise_error NightcrawlerSwift::Exceptions::ValidationError
        expect { subject.execute "" }.to raise_error NightcrawlerSwift::Exceptions::ValidationError
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
nightcrawler_swift-1.0.0 spec/lib/nightcrawler_swift/commands/download_spec.rb
nightcrawler_swift-0.11.1 spec/lib/nightcrawler_swift/commands/download_spec.rb
nightcrawler_swift-0.11.0 spec/lib/nightcrawler_swift/commands/download_spec.rb
nightcrawler_swift-0.10.0 spec/lib/nightcrawler_swift/commands/download_spec.rb
nightcrawler_swift-0.9.0 spec/lib/nightcrawler_swift/commands/download_spec.rb
nightcrawler_swift-0.8.1 spec/lib/nightcrawler_swift/commands/download_spec.rb
nightcrawler_swift-0.8.0 spec/lib/nightcrawler_swift/commands/download_spec.rb
nightcrawler_swift-0.7.0 spec/lib/nightcrawler_swift/commands/download_spec.rb
nightcrawler_swift-0.6.0 spec/lib/nightcrawler_swift/commands/download_spec.rb