specs for services

This commit is contained in:
Karol
2019-12-09 20:35:49 +01:00
parent c89ee6c102
commit 46e7853465
16 changed files with 1029 additions and 13 deletions

View File

@@ -0,0 +1,41 @@
# frozen_string_literal: true
require 'rails_helper'
describe ProformaService::ExportTask do
describe '.new' do
subject(:export_task) { described_class.new(exercise: exercise) }
let(:exercise) { FactoryBot.build(:dummy) }
it 'assigns exercise' do
expect(export_task.instance_variable_get(:@exercise)).to be exercise
end
context 'without exercise' do
subject(:export_task) { described_class.new }
it 'assigns exercise' do
expect(export_task.instance_variable_get(:@exercise)).to be nil
end
end
end
describe '#execute' do
subject(:export_task) { described_class.call(exercise: exercise) }
let(:task) { Proforma::Task.new }
let(:exercise) { FactoryBot.build(:dummy) }
let(:exporter) { instance_double('Proforma::Exporter', perform: 'zip') }
before do
allow(ProformaService::ConvertExerciseToTask).to receive(:call).with(exercise: exercise).and_return(task)
allow(Proforma::Exporter).to receive(:new).with(task).and_return(exporter)
end
it do
export_task
expect(exporter).to have_received(:perform)
end
end
end