This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
ace-of-base/spec/ace_of_base/file_importer_spec.rb

44 lines
1,009 B
Ruby
Raw Normal View History

2019-07-10 21:03:07 +12:00
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AceOfBase::FileImporter do
let(:file_data) { File.read(File.expand_path('../fixtures/sample_file.txt', __dir__)) }
let(:file) { StringIO.new(file_data) }
let(:importer) { described_class.new(file) }
subject { importer }
describe '.import' do
subject { described_class.import(file) }
it 'delegates to #import' do
expect(described_class)
.to receive_message_chain(:new, :import)
.with(file)
.with(no_args)
subject
end
end
describe '#import' do
subject { super().import }
it 'imports the file data' do
expect { subject }
.to change { importer.records.size }
.from(0)
end
context 'When the file contains errors' do
let(:file_data) { 'TimeCop is the best time travel movie ever' }
it 'records the errors' do
expect { subject }
.to change { importer.valid? }
.from(true)
end
end
end
end