`algolia/webmock` and `webmock/rspec` compatibility
Hello everyone,
in my Rails 5.2 application, i'm indexing a model using the algoliasearch-rails gem.
In my test for a service class, which takes care of retrieving an object through an API and updating the model whenever there's changes to bring, i'm stubbing the requests to the Algolia API with:
# support/algolia.rb
require 'algolia/webmock'
RSpec.configure do |config|
config.before(:each) do
WebMock.enable!
end
config.after(:each) do
WebMock.disable!
end
end
However when i bring in 'webmock/rspec' and run the following test, calls are made to the API:
# spec/adapter_spec.rb
require 'rails_helper'
require 'algolia/webmock'
RSpec.describe 'Adapter::Object'
context 'when raw object and model object are different' do
let!(:object) { create(:object) }
let(:adapter_object) { Adapter::object.new(raw_object) }
it 'calls the Algolia API when adapting object' do
expect(a_request(:any, /algolia/)).to have_been_made.at_least_once
adapter_object.adapt
end
end
end
When i remove webmock/rspec no calls are made. It looks like it clears all stubs made by algolia/webmock.
Is there a way to configure these two to work together that i overlooked ?
I'm seeing the same issue
I fixed this issue by calling the Algolia implementation explicitly:
require 'algolia/webmock'
Rspec.configuration do |config|
config.before(:example) do
Algolia::WebMock.mock!
end
end
I am getting error on this line (spec_helper.rb)
require "algolia/webmock"
Error backtrace:
Failure/Error: require "algolia/webmock"
LoadError:
cannot load such file -- algolia/webmock
Previously i was using 1.20.4 version, it was working fine. Now i have updated version to 2.2.2 then i am getting this error.