Sha256: 22f46fdb57e72e310643b9bcc4dd80d6fcd742adbca9bc0dd3d8eb8fb4d79335
Contents?: true
Size: 1.95 KB
Versions: 1
Compression:
Stored size: 1.95 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(:public_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(:public_url).and_return(public_url) NightcrawlerSwift.configure bucket: bucket end describe "#execute" do let :execute do subject.execute "file_path" end before do allow(subject).to receive(:get).and_return(response) end context "success" do let :response do double(:response, code: 200, body: "content") end it "gets using public 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 file does not exist" do let :response do double(:response, code: 404) end before do allow(subject).to receive(:get).and_raise(RestClient::ResourceNotFound.new(response)) end it "raises NightcrawlerSwift::Exceptions::NotFoundError" do expect { execute }.to raise_error NightcrawlerSwift::Exceptions::NotFoundError end end context "when another error happens" do let :response do double(:response, code: 500) end before do allow(subject).to receive(:get).and_raise(RuntimeError.new(response)) end it "raises NightcrawlerSwift::Exceptions::ConnectionError" do expect { execute }.to raise_error NightcrawlerSwift::Exceptions::ConnectionError end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nightcrawler_swift-0.4.0 | spec/lib/nightcrawler_swift/commands/download_spec.rb |