From b89e2c58d4a9701fe46698ba9eeeaf78f1b5d276 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sat, 1 Jun 2019 22:54:52 +0200 Subject: [PATCH] Dry out code with shared_examples --- spec/controllers/match_scores_controller_spec.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/controllers/match_scores_controller_spec.rb b/spec/controllers/match_scores_controller_spec.rb index b9c2a12..add6e06 100644 --- a/spec/controllers/match_scores_controller_spec.rb +++ b/spec/controllers/match_scores_controller_spec.rb @@ -81,22 +81,23 @@ RSpec.describe MatchScoresController, type: :controller do } end - context 'when successful' do - let(:context) { double(:context, success?: true) } - + shared_examples_for 'update_of_match_score' do it 'returns a 200 status code' do put :update, params: { id: @match_score.to_param }.merge(valid_update) expect(response).to be_successful end end + context 'when successful' do + let(:context) { double(:context, success?: true) } + + it_should_behave_like 'update_of_match_score' + end + context 'when unsuccessful' do let(:context) { double(:context, success?: false) } - it 'returns a 200 status code' do - put :update, params: { id: @match_score.to_param }.merge(valid_update) - expect(response).to be_successful - end + it_should_behave_like 'update_of_match_score' end end end