From 6a47458112f9af76f3a6f2415642d9e3f6bb0119 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 21 Jan 2020 17:24:42 +0100 Subject: [PATCH] specs: use order-insentitive matching for arrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The specs sometime failes locally, because the order of the returned objects is undefined. This is an acceptable behavior – but it means we should test for collection membership, rather than for a specific array order. Replace `match` by `match_array` to have unordered matching. --- .../procedures_controller_spec.rb | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index 0fdb90e5e..a8168d821 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -256,10 +256,10 @@ describe Instructeurs::ProceduresController, type: :controller do get :show, params: { procedure_id: procedure.id } end - it { expect(assigns(:a_suivre_dossiers)).to match([new_unfollow_dossier]) } + it { expect(assigns(:a_suivre_dossiers)).to match_array([new_unfollow_dossier]) } it { expect(assigns(:followed_dossiers)).to be_empty } it { expect(assigns(:termines_dossiers)).to be_empty } - it { expect(assigns(:all_state_dossiers)).to match([new_unfollow_dossier]) } + it { expect(assigns(:all_state_dossiers)).to match_array([new_unfollow_dossier]) } it { expect(assigns(:archived_dossiers)).to be_empty } context 'and dossiers without follower on each of the others groups' do @@ -270,8 +270,8 @@ describe Instructeurs::ProceduresController, type: :controller do get :show, params: { procedure_id: procedure.id } end - it { expect(assigns(:a_suivre_dossiers)).to match([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) } - it { expect(assigns(:all_state_dossiers)).to match([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) } + it { expect(assigns(:a_suivre_dossiers)).to match_array([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) } + it { expect(assigns(:all_state_dossiers)).to match_array([new_unfollow_dossier, new_unfollow_dossier_on_gi_2]) } end end @@ -284,9 +284,9 @@ describe Instructeurs::ProceduresController, type: :controller do end it { expect(assigns(:a_suivre_dossiers)).to be_empty } - it { expect(assigns(:followed_dossiers)).to match([new_followed_dossier]) } + it { expect(assigns(:followed_dossiers)).to match_array([new_followed_dossier]) } it { expect(assigns(:termines_dossiers)).to be_empty } - it { expect(assigns(:all_state_dossiers)).to match([new_followed_dossier]) } + it { expect(assigns(:all_state_dossiers)).to match_array([new_followed_dossier]) } it { expect(assigns(:archived_dossiers)).to be_empty } context 'and dossier with a follower on each of the others groups' do @@ -313,8 +313,8 @@ describe Instructeurs::ProceduresController, type: :controller do it { expect(assigns(:a_suivre_dossiers)).to be_empty } it { expect(assigns(:followed_dossiers)).to be_empty } - it { expect(assigns(:termines_dossiers)).to match([termine_dossier]) } - it { expect(assigns(:all_state_dossiers)).to match([termine_dossier]) } + it { expect(assigns(:termines_dossiers)).to match_array([termine_dossier]) } + it { expect(assigns(:all_state_dossiers)).to match_array([termine_dossier]) } it { expect(assigns(:archived_dossiers)).to be_empty } context 'and terminer dossiers on each of the others groups' do @@ -325,8 +325,8 @@ describe Instructeurs::ProceduresController, type: :controller do get :show, params: { procedure_id: procedure.id } end - it { expect(assigns(:termines_dossiers)).to match([termine_dossier, termine_dossier_on_gi_2]) } - it { expect(assigns(:all_state_dossiers)).to match([termine_dossier, termine_dossier_on_gi_2]) } + it { expect(assigns(:termines_dossiers)).to match_array([termine_dossier, termine_dossier_on_gi_2]) } + it { expect(assigns(:all_state_dossiers)).to match_array([termine_dossier, termine_dossier_on_gi_2]) } end end @@ -341,7 +341,7 @@ describe Instructeurs::ProceduresController, type: :controller do it { expect(assigns(:followed_dossiers)).to be_empty } it { expect(assigns(:termines_dossiers)).to be_empty } it { expect(assigns(:all_state_dossiers)).to be_empty } - it { expect(assigns(:archived_dossiers)).to match([archived_dossier]) } + it { expect(assigns(:archived_dossiers)).to match_array([archived_dossier]) } context 'and terminer dossiers on each of the others groups' do let!(:archived_dossier_on_gi_2) { create(:dossier, groupe_instructeur: gi_2, state: Dossier.states.fetch(:en_instruction), archived: true) } @@ -351,7 +351,7 @@ describe Instructeurs::ProceduresController, type: :controller do get :show, params: { procedure_id: procedure.id } end - it { expect(assigns(:archived_dossiers)).to match([archived_dossier, archived_dossier_on_gi_2]) } + it { expect(assigns(:archived_dossiers)).to match_array([archived_dossier, archived_dossier_on_gi_2]) } end end @@ -369,7 +369,7 @@ describe Instructeurs::ProceduresController, type: :controller do context 'when statut is empty' do let(:statut) { nil } - it { expect(assigns(:dossiers)).to match([a_suivre__dossier]) } + it { expect(assigns(:dossiers)).to match_array([a_suivre__dossier]) } it { expect(assigns(:statut)).to eq('a-suivre') } end @@ -377,21 +377,21 @@ describe Instructeurs::ProceduresController, type: :controller do let(:statut) { 'a-suivre' } it { expect(assigns(:statut)).to eq('a-suivre') } - it { expect(assigns(:dossiers)).to match([a_suivre__dossier]) } + it { expect(assigns(:dossiers)).to match_array([a_suivre__dossier]) } end context 'when statut is suivis' do let(:statut) { 'suivis' } it { expect(assigns(:statut)).to eq('suivis') } - it { expect(assigns(:dossiers)).to match([new_followed_dossier]) } + it { expect(assigns(:dossiers)).to match_array([new_followed_dossier]) } end context 'when statut is traites' do let(:statut) { 'traites' } it { expect(assigns(:statut)).to eq('traites') } - it { expect(assigns(:dossiers)).to match([termine_dossier]) } + it { expect(assigns(:dossiers)).to match_array([termine_dossier]) } end context 'when statut is tous' do @@ -405,7 +405,7 @@ describe Instructeurs::ProceduresController, type: :controller do let(:statut) { 'archives' } it { expect(assigns(:statut)).to eq('archives') } - it { expect(assigns(:dossiers)).to match([archived_dossier]) } + it { expect(assigns(:dossiers)).to match_array([archived_dossier]) } end end end