Test populate_match_below Interactor

This commit is contained in:
Daniel Schädler 2019-05-14 13:44:02 +02:00
parent 645f3d0800
commit d0d38a7972
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
# frozen_string_literal: true
RSpec.describe PopulateMatchBelow do
before do
@match = create(:match)
@objects_to_save = [create(:match), create_list(:match_score, 2)]
end
context 'no exception' do
let(:context) do
PopulateMatchBelow.call(match: @match)
end
before do
allow(PlayoffStageService)
.to receive(:populate_match_below).with(@match)
.and_return(@objects_to_save)
end
it 'succeeds' do
expect(context).to be_a_success
end
it 'provides the objects to save' do
expect(context.object_to_save).to match_array(@objects_to_save)
end
end
context 'exception is thrown' do
let(:context) do
PopulateMatchBelow.call(match: @match)
end
before do
allow(PlayoffStageService)
.to receive(:populate_match_below).with(@match)
.and_throw('This failed :(')
end
it 'fails' do
test = context.failure?
expect(test).to eq(true)
end
end
end