Skip to content

Instantly share code, notes, and snippets.

@bunnymatic
Created January 13, 2016 08:41
Show Gist options
  • Save bunnymatic/11fa0d5ac32a4e37be8c to your computer and use it in GitHub Desktop.
Save bunnymatic/11fa0d5ac32a4e37be8c to your computer and use it in GitHub Desktop.
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