Skip to content

Commit ac9660b

Browse files
committed
Check es-ruby client v8 availibility with a separate method in the spec.
1 parent 5471b74 commit ac9660b

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)
@@ -92,10 +99,10 @@
9299

93100
before do
94101
allow(Elasticsearch::Client).to receive(:new).and_return(es_client)
95-
begin
96-
allow(es_client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
97-
rescue NameError # NameError: uninitialized constant Elasticsearch::Transport
102+
if elastic_ruby_v8_client_available?
98103
allow(es_client).to receive(:info).and_raise(Elastic::Transport::Transport::Errors::BadRequest.new)
104+
else
105+
allow(es_client).to receive(:info).and_raise(Elasticsearch::Transport::Transport::Errors::BadRequest.new)
99106
end
100107
end
101108

0 commit comments

Comments
 (0)