Skip to content

Commit de38377

Browse files
committed
Check es-ruby client v8 availibility with a separate method in the spec.
1 parent 9b169fd commit de38377

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

spec/inputs/elasticsearch_spec.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
let(:es_version) { "7.5.0" }
2222
let(:cluster_info) { {"version" => {"number" => es_version, "build_flavor" => build_flavor}, "tagline" => "You Know, for Search"} }
2323

24+
def elastic_ruby_v8_client_available?
25+
Elasticsearch::Transport
26+
false
27+
rescue NameError # NameError: uninitialized constant Elasticsearch::Transport if Elastic Ruby client is not available
28+
true
29+
end
30+
2431
before(:each) do
2532
Elasticsearch::Client.send(:define_method, :ping) { } # define no-action ping method
2633
allow_any_instance_of(Elasticsearch::Client).to receive(:info).and_return(cluster_info)
@@ -79,10 +86,10 @@
7986

8087
before do
8188
allow(Elasticsearch::Client).to receive(:new).and_return(es_client)
82-
begin
83-
allow(es_client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
84-
rescue NameError # NameError: uninitialized constant Elasticsearch::Transport
89+
if elastic_ruby_v8_client_available?
8590
allow(es_client).to receive(:info).and_raise(Elastic::Transport::Transport::Errors::BadRequest.new)
91+
else
92+
allow(es_client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
8693
end
8794
end
8895

0 commit comments

Comments
 (0)