Skip to content

Instantly share code, notes, and snippets.

@akirasosa
Created September 12, 2013 10:18
Show Gist options
  • Save akirasosa/6535402 to your computer and use it in GitHub Desktop.
Save akirasosa/6535402 to your computer and use it in GitHub Desktop.
speed up rspec tests using elasticsearch by bypass useless connections to the elasticsearch server
# Gemfile
group :test do
gem "webmock"
end
describe Club, "#search", elasticsearch: true do
before {...}
it "can search by keyword" do
Club.search(keyword: 'Hawaii', min_score: 0).count.should eql(1)
end
end
# spec/spec_helper.rb
RSpec.configure do |config|
config.before(:each) do
if example.metadata[:elasticsearch]
Club.tire.index.delete
Club.tire.create_elasticsearch_index
else
stub_request(:any, %r|#{ENV['ELASTIC_SEARCH_URL']}|).to_return({
body: {}.to_json,
headers: {content_type: "application/json"}
})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment