Skip to content

Instantly share code, notes, and snippets.

@roalcantara
Created March 24, 2017 14:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roalcantara/16650889e29dfb920fc5f0cc833bd5dd to your computer and use it in GitHub Desktop.
Save roalcantara/16650889e29dfb920fc5f0cc833bd5dd to your computer and use it in GitHub Desktop.
Rails > Disabling elasticsearch requests durying rspec tests
# spec/support/elasticsearch.rb
RSpec.configure do |config|
config.before :each do
stub_request(:any, /localhost:9200/).to_return(body: "<html>a webpage!</html>", status: 200)
end
end
@ThangLeQuoc
Copy link

Hey, thanks for this snippet. Could you please add some more comment to be clear, so other at beginner level would be easy to follow ?
The stub_request belong to the webmock gem. It's took me a while to figure out why it's wrong.

Add the following line in spec/spec_helper

require 'webmock/rspec'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment