Api clients
/
Ruby
/
V1
/
Guides
Jun 25, 2024
Mock API Calls in the Ruby API Client (Deprecated)
Deprecated content
This documentation is for a deprecated version of Ruby API client .
Some features and settings may be missing or their usage may have changed.
Refer to the documentation for the
latest version of Ruby API client for up-to-date information.
Webmock
For testing purposes, you may want to mock Algolia’s API calls. We provide a WebMock configuration that you can use including algolia/webmock
.
Add gem webmock
to your Gemfile to use the following configuration:
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'algolia/webmock'
describe 'With a mocked client' do
before(:each) do
WebMock.enable!
end
it "shouldn't perform any API calls here" do
index = client.init_index('friends')
index.add_object!({ name: 'John Doe', email: 'john@doe.org' })
index.search('').should == { hits: [{ objectID: 42 }], page: 1, hitsPerPage: 1 } # mocked
index.clear_index
index.delete_index
end
after(:each) do
WebMock.disable!
end
end
Did you find this page helpful?