Skip to content

Commit 438fbe0

Browse files
committed
Grand work for integration tests with real instance
1 parent 9240cda commit 438fbe0

File tree

10 files changed

+29
-124
lines changed

10 files changed

+29
-124
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
ruby-version: ['3.0', '3.2', '3.3']
13+
ruby-version: ['3.0', '3.2', '3.3', '3.4']
1414
services:
1515
typesense:
1616
image: typesense/typesense:28.0

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ typesense-server-peers
1616
# rspec failure tracking
1717
.rspec_status
1818
typesense-data
19+
20+
# os files
21+
.DS_Store

.rubocop.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
require: rubocop-rspec
1+
plugins:
2+
- rubocop-rspec
3+
- rubocop-rake
24

35
AllCops:
46
NewCops: enable

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ gem 'rspec', '~> 3.9'
1616
gem 'rspec_junit_formatter', '~> 0.4'
1717
gem 'rspec-legacy_formatters', '~> 1.0' # For codecov formatter
1818
gem 'rubocop', '~> 1.12'
19+
gem 'rubocop-rake', '~> 0.7'
1920
gem 'rubocop-rspec', '~> 2.4', require: false
2021
gem 'simplecov', '~> 0.18'
2122
gem 'timecop', '~> 0.9'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "companies",
3+
"num_documents": 0,
4+
"fields": [
5+
{ "name": "company_name", "type": "string", "facet": false },
6+
{ "name": "num_employees", "type": "int32", "facet": false },
7+
{ "name": "country", "type": "string", "facet": true }
8+
],
9+
"token_ranking_field": "num_employees",
10+
"default_sorting_field": "num_employees"
11+
}

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
require 'webmock/rspec'
1212
require 'typesense'
1313

14+
WebMock.disable_net_connect!(allow_localhost: true)
15+
1416
RSpec.configure do |config|
1517
# Enable flags like --only-failures and --next-failure
1618
config.example_status_persistence_file_path = '.rspec_status'

spec/typesense/collection_spec.rb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,7 @@
88

99
include_context 'with Typesense configuration'
1010

11-
let(:company_schema) do
12-
{
13-
'name' => 'companies',
14-
'num_documents' => 0,
15-
'fields' => [
16-
{
17-
'name' => 'company_name',
18-
'type' => 'string',
19-
'facet' => false
20-
},
21-
{
22-
'name' => 'num_employees',
23-
'type' => 'int32',
24-
'facet' => false
25-
},
26-
{
27-
'name' => 'country',
28-
'type' => 'string',
29-
'facet' => true
30-
}
31-
],
32-
'token_ranking_field' => 'num_employees'
33-
}
34-
end
11+
let(:company_schema) { JSON.parse(File.read('spec/fixtures/collections/companies.json')) }
3512

3613
describe '#retrieve' do
3714
it 'returns the specified collection' do

spec/typesense/collections_spec.rb

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,7 @@
88

99
include_context 'with Typesense configuration'
1010

11-
let(:company_schema) do
12-
{
13-
'name' => 'companies',
14-
'num_documents' => 0,
15-
'fields' => [
16-
{
17-
'name' => 'company_name',
18-
'type' => 'string',
19-
'facet' => false
20-
},
21-
{
22-
'name' => 'num_employees',
23-
'type' => 'int32',
24-
'facet' => false
25-
},
26-
{
27-
'name' => 'country',
28-
'type' => 'string',
29-
'facet' => true
30-
}
31-
],
32-
'token_ranking_field' => 'num_employees'
33-
}
34-
end
11+
let(:company_schema) { JSON.parse(File.read('spec/fixtures/collections/companies.json')) }
3512

3613
describe '#create' do
3714
it 'creates a collection and returns it' do
@@ -52,29 +29,7 @@
5229
end
5330

5431
context 'with integration', :integration do
55-
let(:integration_schema) do
56-
{
57-
'name' => 'integration_companies',
58-
'fields' => [
59-
{
60-
'name' => 'company_name',
61-
'type' => 'string',
62-
'facet' => false
63-
},
64-
{
65-
'name' => 'num_employees',
66-
'type' => 'int32',
67-
'facet' => false
68-
},
69-
{
70-
'name' => 'country',
71-
'type' => 'string',
72-
'facet' => true
73-
}
74-
],
75-
'default_sorting_field' => 'num_employees'
76-
}
77-
end
32+
let(:integration_schema) { company_schema }
7833

7934
let(:integration_client) do
8035
Typesense::Client.new(
@@ -135,15 +90,15 @@
13590
before do
13691
WebMock.disable!
13792
begin
138-
integration_client.collections['integration_companies'].delete
93+
integration_client.collections['companies'].delete
13994
rescue Typesense::Error::ObjectNotFound
14095
# Collection doesn't exist, which is fine
14196
end
14297
end
14398

14499
after do
145100
begin
146-
integration_client.collections['integration_companies'].delete
101+
integration_client.collections['companies'].delete
147102
rescue Typesense::Error::ObjectNotFound
148103
# Collection doesn't exist, which is fine
149104
end
@@ -153,7 +108,7 @@
153108
it 'creates a collection on a real Typesense server' do
154109
result = integration_client.collections.create(integration_schema)
155110

156-
expect(result['name']).to eq('integration_companies')
111+
expect(result['name']).to eq('companies')
157112
expect(result['fields']).to eq(expected_fields)
158113
expect(result['default_sorting_field']).to eq(integration_schema['default_sorting_field'])
159114
expect(result['num_documents']).to eq(0)

spec/typesense/document_spec.rb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,7 @@
88

99
include_context 'with Typesense configuration'
1010

11-
let(:company_schema) do
12-
{
13-
'name' => 'companies',
14-
'num_documents' => 0,
15-
'fields' => [
16-
{
17-
'name' => 'company_name',
18-
'type' => 'string',
19-
'facet' => false
20-
},
21-
{
22-
'name' => 'num_employees',
23-
'type' => 'int32',
24-
'facet' => false
25-
},
26-
{
27-
'name' => 'country',
28-
'type' => 'string',
29-
'facet' => true
30-
}
31-
],
32-
'token_ranking_field' => 'num_employees'
33-
}
34-
end
11+
let(:company_schema) { JSON.parse(File.read('spec/fixtures/collections/companies.json')) }
3512

3613
let(:document) do
3714
{

spec/typesense/documents_spec.rb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,7 @@
88

99
include_context 'with Typesense configuration'
1010

11-
let(:company_schema) do
12-
{
13-
'name' => 'companies',
14-
'num_documents' => 0,
15-
'fields' => [
16-
{
17-
'name' => 'company_name',
18-
'type' => 'string',
19-
'facet' => false
20-
},
21-
{
22-
'name' => 'num_employees',
23-
'type' => 'int32',
24-
'facet' => false
25-
},
26-
{
27-
'name' => 'country',
28-
'type' => 'string',
29-
'facet' => true
30-
}
31-
],
32-
'token_ranking_field' => 'num_employees'
33-
}
34-
end
11+
let(:company_schema) { JSON.parse(File.read('spec/fixtures/collections/companies.json')) }
3512

3613
let(:document) do
3714
{

0 commit comments

Comments
 (0)