Module: Elasticsearch::Embedded::RSpec

Defined in:
lib/elasticsearch/embedded/rspec_configuration.rb

Defined Under Namespace

Modules: ElasticSearchHelpers

Class Method Summary collapse

Class Method Details

.configureObject

Default config method, configure RSpec with :elasticsearch filter only. Equivalent to .configure_with(:elasticsearch)



62
63
64
# File 'lib/elasticsearch/embedded/rspec_configuration.rb', line 62

def configure
  configure_with(elasticsearch: true)
end

.configure_with(*meta) ⇒ Object

Configure rspec for usage with ES cluster



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/elasticsearch/embedded/rspec_configuration.rb', line 40

def configure_with(*meta)
  # assign default value to tags
  ::RSpec.configure do |config|

    # Include helpers only in tagged specs
    config.include ElasticSearchHelpers, *meta

    # Before hook, starts the cluster
    config.before(:each, *meta) do
      ElasticSearchHelpers.memoized_cluster.ensure_started!
      ElasticSearchHelpers.memoized_cluster.delete_all_indices!
    end

    # After suite hook, stop the cluster
    config.after(:suite) do
      ElasticSearchHelpers.memoized_cluster.stop if ElasticSearchHelpers.memoized_cluster.running?
    end
  end
end