Created
March 27, 2012 11:06
Revisions
-
dvdplm created this gist
Mar 27, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ module Tire module Disable module ClassMethods def mock_es_response_doc @mock_es_response_doc ||= '{"took": 1,"timed_out": false,"_shards": {"total": 5,"successful": 5,"failed": 0},"hits": {"total": 0,"max_score": null,"hits": []}}' end def enable! &blk old_enabled = @tire_enabled || false @tire_enabled = true WebMock.disable! if block_given? begin yield ensure @tire_enabled = old_enabled if not @tire_enabled self.disable! end end end end def disable! WebMock.enable! && WebMock.reset! WebMock .stub_request(:any, %r|#{Tire::Configuration.url}.*|) .to_return(status: 200, body: mock_es_response_doc, headers: {}) end def init_elasticsearch_index klass idx = Tire::Index.new klass.tire.index.name idx.delete idx.create mappings: klass.tire.mapping_to_hash, settings: klass.tire.settings idx.refresh end end end extend Disable::ClassMethods end require 'webmock' Tire.disable! RSpec.configure do |config| config.around do |example| if not example.metadata[:elasticsearch] example.call else Tire.enable! do example.call end end end end