ElasticSearch + Tire: good strategy to mock ES ElasticSearch + Tire: good strategy to mock ES elasticsearch elasticsearch

ElasticSearch + Tire: good strategy to mock ES


I would probably use FakeWeb to selectively enable and disable live HTTP calls.

To mock calls to ES:

FakeWeb.allow_net_connect = falseFakeWeb.register_uri(:any, %r|\Ahttp://localhost:9200|, :body => "{}")

To allow calls to ES:

FakeWeb.clean_registryFakeWeb.allow_net_connect = true

Allowing and disallowing net connections isn't strictly required here, since FakeWeb's mocks get priority over real calls, but I find that it helps to throw an exception in your tests when something makes an unmocked HTTP call.

You can probably expand on this to use the test metadata to enable or disable mocks as needed.