From d0d38a79728018713491782fca871cd7e1ed25ec Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Tue, 14 May 2019 13:44:02 +0200 Subject: [PATCH] Test populate_match_below Interactor --- .../populate_match_below_interactor_spec.rb | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/interactors/populate_match_below_interactor_spec.rb diff --git a/spec/interactors/populate_match_below_interactor_spec.rb b/spec/interactors/populate_match_below_interactor_spec.rb new file mode 100644 index 0000000..8b751e0 --- /dev/null +++ b/spec/interactors/populate_match_below_interactor_spec.rb @@ -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