Sha256: b4c5eb662cae1bf0caf05077efde02ddf09b5bbcb4d4bc79ecff5422b19a38c5
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
require 'spec_helper' describe NightcrawlerSwift::Delete do let(:connection) { NightcrawlerSwift::Connection.new } let(:token) { "token" } let(:expires_at) { (DateTime.now + 60).to_time } let(:upload_url) { "server-url" } subject do NightcrawlerSwift::Delete.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(:upload_url).and_return(upload_url) end describe "#execute" do let :execute do subject.execute "file_path" end before do allow(subject).to receive(:delete).and_return(response) end context "success" do let :response do double(:response, code: 200) end it "deletes using upload url" do execute expect(subject).to have_received(:delete).with("server-url/file_path", headers: {accept: :json}) end it "returns true" do expect(execute).to eql true end end context "when the file does not exist" do let :response do double(:response, code: 404) end before do allow(subject).to receive(:delete).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(:delete).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/delete_spec.rb |