Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Elasticsearch test helpers
require_relative "../../spec/support/test_es_server"
require_relative "./webmock"
TestEsServer.start
at_exit do
TestEsServer.stop
end
require 'webmock/cucumber'
WebMock.disable_net_connect!(:allow_localhost => true)
require 'elasticsearch/extensions/test/cluster'
class TestEsServer
def self.cluster
Elasticsearch::Extensions::Test::Cluster
end
def self.port
@port ||= URI.parse(Rails.application.config.elasticsearch_url).port
end
def self.running?
cluster.running?(on: port)
end
def self.start
puts "Starting elastic search cluster on port #{port} if necessary"
cluster.start(port: port, nodes: 1) unless running?
end
def self.stop
puts "Tearing down elastic search cluster on port #{port} if necessary"
cluster.stop(port: port) if running?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment