Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Created February 20, 2019 17:25
Show Gist options
  • Save tbuehlmann/4947ca69b933e56f1294928fa90d1b6a to your computer and use it in GitHub Desktop.
Save tbuehlmann/4947ca69b933e56f1294928fa90d1b6a to your computer and use it in GitHub Desktop.
$ bundle exec ruby spec.rb 1 ↵
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using bundler 1.17.3
Using diff-lcs 1.3
Using rspec-support 3.8.0
Using rspec-core 3.8.0
Using rspec-expectations 3.8.2
Using rspec-mocks 3.8.0
Using rspec 3.8.0
F
Failures:
1) success Uploads file to folder on Box
Failure/Error: subject { BoxApi.new }
NameError:
uninitialized constant BoxApi
# spec.rb:18:in `block (2 levels) in <main>'
# spec.rb:26:in `block (2 levels) in <main>'
# spec.rb:42:in `<main>'
Finished in 0.0034 seconds (files took 0.21899 seconds to load)
1 example, 1 failure
Failed examples:
rspec spec.rb:25 # success Uploads file to folder on Box
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rspec'
end
require 'rspec'
RSpec.context 'success' do
subject { BoxApi.new }
let(:client) { double }
let(:file_path) {'spec/fixtures/pdfs/pdf_without_data.pdf'}
let(:file_name) {'pdf_without_data.pdf'}
let(:folder_id) {'123'}
it 'Uploads file to folder on Box' do
allow(subject).to receive(:client).and_return(client)
allow(subject).to receive(:folder).with(folder_id).and_return("123")
allow(client).to receive(:upload_file).with(file_path, folder_id).and_return(status: 201)
subject.upload_file_to_box(file_path, file_name, folder_id)
expect(client).to receive(:upload_file).with(file_path, folder_id)
end
def upload_file_to_box(file_path, file, box_folder_id)
client.upload_file(file_path, self.folder(box_folder_id))
rescue Boxr::BoxrError
file = find_file_by_name(file).shift
client.upload_new_version_of_file(file_path, file)
end
end
RSpec::Core::Runner.invoke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment