# 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