From d9a9323968f614d0bad59ebd759086aad6f2b402 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 9 Aug 2023 07:15:04 -0400 Subject: [PATCH] Avoid connecting to a running ES instance in ES search check spec (#26413) --- .../admin/system_check/elasticsearch_check_spec.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/lib/admin/system_check/elasticsearch_check_spec.rb b/spec/lib/admin/system_check/elasticsearch_check_spec.rb index 1ffac89ee4..4982159269 100644 --- a/spec/lib/admin/system_check/elasticsearch_check_spec.rb +++ b/spec/lib/admin/system_check/elasticsearch_check_spec.rb @@ -49,11 +49,7 @@ describe Admin::SystemCheck::ElasticsearchCheck do end context 'when running version is missing' do - before do - client = instance_double(Elasticsearch::Transport::Client) - allow(client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Error) - allow(Chewy).to receive(:client).and_return(client) - end + before { stub_elasticsearch_error } it 'returns false' do expect(check.pass?).to be false @@ -86,6 +82,8 @@ describe Admin::SystemCheck::ElasticsearchCheck do end context 'when running version is missing' do + before { stub_elasticsearch_error } + it 'sends class name symbol to message instance' do allow(Admin::SystemCheck::Message).to receive(:new) .with(:elasticsearch_running_check) @@ -97,4 +95,10 @@ describe Admin::SystemCheck::ElasticsearchCheck do end end end + + def stub_elasticsearch_error + client = instance_double(Elasticsearch::Transport::Client) + allow(client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Error) + allow(Chewy).to receive(:client).and_return(client) + end end