Created
September 12, 2013 10:18
-
-
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
This file contains 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 characters
# Gemfile | |
group :test do | |
gem "webmock" | |
end | |
This file contains 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 characters
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 |
This file contains 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 characters
# 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