Created
January 13, 2016 08:41
-
-
Save bunnymatic/11fa0d5ac32a4e37be8c to your computer and use it in GitHub Desktop.
Elasticsearch test helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "../../spec/support/test_es_server" | |
require_relative "./webmock" | |
TestEsServer.start | |
at_exit do | |
TestEsServer.stop | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'webmock/cucumber' | |
WebMock.disable_net_connect!(:allow_localhost => true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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