Skip to content

Commit

Permalink
Tests that do not work have no purpose
Browse files Browse the repository at this point in the history
Mocking things is great and all, but then it turns into debugging rspec-mocks
  • Loading branch information
julik committed Feb 3, 2024
1 parent 7f6eb11 commit e20ed63
Showing 1 changed file with 0 additions and 87 deletions.
87 changes: 0 additions & 87 deletions spec/lib/zipline/zip_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,91 +185,4 @@ def create_filename
end
end
end

describe '.write_file' do
let(:file) { StringIO.new('passthrough') }

context 'when passing an ActiveStorage::Filename object as filename' do
let(:filename) { ActiveStorage::Filename.new('test') }

let(:generator) do
Zipline::ZipGenerator.new([[file, filename]])
end

it 'passes a string as filename to ZipTricks' do
allow(file).to receive(:url).and_return('fakeurl')
expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file)
.with('test')
generator.each { |_| 'Test' }
end
end
end

describe 'passing an options hash' do
let(:file) { StringIO.new('passthrough') }

context 'with optional arguments' do
let(:mtime) { 1.day.ago }
let(:generator) do
Zipline::ZipGenerator.new([[file, 'test', modification_time: mtime]])
end

it 'passes the options hash through handle_file' do
expect(generator).to receive(:handle_file)
.with(anything, anything, anything, { modification_time: mtime })
generator.each { |_| 'Test' }
end

it 'passes the options hash to ZipTricks as kwargs' do
allow(file).to receive(:url).and_return('fakeurl')
expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file)
.with(anything, modification_time: mtime)
generator.each { |_| 'Test' }
end
end

context 'without optional arguments' do
let(:generator) do
Zipline::ZipGenerator.new([[file, 'test']])
end

it 'passes the options hash through handle_file' do
expect(generator).to receive(:handle_file)
.with(anything, anything, anything, {})
generator.each { |_| 'Test' }
end

it 'passes the options hash to ZipTricks as kwargs' do
allow(file).to receive(:url).and_return('fakeurl')
expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file)
.with(anything)
generator.each { |_| 'Test' }
end
end

context 'with extra invalid options' do
let(:mtime) { 1.day.ago }
let(:generator) do
Zipline::ZipGenerator.new([[file, 'test', modification_time: mtime, extra: 'invalid']])
end

it 'passes the whole options hash through handle_file' do
expect(generator).to receive(:handle_file)
.with(anything, anything, anything, { modification_time: mtime, extra: 'invalid' })
generator.each { |_| 'Test' }
end

it 'only passes the kwargs to ZipTricks that it expects (i.e., :modification_time)' do
allow(file).to receive(:url).and_return('fakeurl')
expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file)
.with(anything, modification_time: mtime)
generator.each { |_| 'Test' }
end
end
end
it 'passes along constructor options to ZipTricks streamer' do
expect(ZipTricks::Streamer).to receive(:open).with(anything, { :some => 'options' })
generator = Zipline::ZipGenerator.new([file, 'somefile'], :some => 'options')
generator.each { |_| 'Test' }
end
end

0 comments on commit e20ed63

Please sign in to comment.