Skip to content

Instantly share code, notes, and snippets.

@bunnymatic
Created January 13, 2016 08:41
Show Gist options
  • Select an option

  • Save bunnymatic/11fa0d5ac32a4e37be8c to your computer and use it in GitHub Desktop.

Select an option

Save bunnymatic/11fa0d5ac32a4e37be8c to your computer and use it in GitHub Desktop.

Revisions

  1. bunnymatic created this gist Jan 13, 2016.
    8 changes: 8 additions & 0 deletions features-support-elasticsearch.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    require_relative "../../spec/support/test_es_server"
    require_relative "./webmock"

    TestEsServer.start

    at_exit do
    TestEsServer.stop
    end
    3 changes: 3 additions & 0 deletions features-support-webmock.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    require 'webmock/cucumber'

    WebMock.disable_net_connect!(:allow_localhost => true)
    24 changes: 24 additions & 0 deletions spec-support-test_es_server.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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