Skip to content

Commit 8b4bd31

Browse files
committed
Modernize test suite: replace deprecated syntax, remove dead tests
- Replace `its/should` with `specify/expect` in config_spec and repository_spec (also removes a duplicate transport_logger test) - Remove duplicate specify blocks in query_proxy_spec - Remove permanently-pending Groovy script tests in response_spec (Groovy scripting unsupported since ES 6) - Modernize version test description in chewy_spec - Remove broken xdescribe '.massacre' (never called .massacre, incorrect setup, untestable with ES 8 defaults) - Remove xcontext 'applying journal' from actions_spec (timing- dependent, full of debug prints, covered by journaling context)
1 parent f74a271 commit 8b4bd31

File tree

6 files changed

+17
-143
lines changed

6 files changed

+17
-143
lines changed

spec/chewy/config_spec.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
describe Chewy::Config do
44
subject { described_class.send(:new) }
55

6-
its(:logger) { should be_nil }
7-
its(:transport_logger) { should be_nil }
8-
its(:transport_logger) { should be_nil }
9-
its(:root_strategy) { should == :base }
10-
its(:request_strategy) { should == :atomic }
11-
its(:console_strategy) { should == :urgent }
12-
its(:use_after_commit_callbacks) { should == true }
13-
its(:indices_path) { should == 'app/chewy' }
14-
its(:reset_disable_refresh_interval) { should == false }
15-
its(:reset_no_replicas) { should == false }
16-
its(:disable_refresh_async) { should == false }
17-
its(:search_class) { should be < Chewy::Search::Request }
6+
specify { expect(subject.logger).to be_nil }
7+
specify { expect(subject.transport_logger).to be_nil }
8+
specify { expect(subject.root_strategy).to eq(:base) }
9+
specify { expect(subject.request_strategy).to eq(:atomic) }
10+
specify { expect(subject.console_strategy).to eq(:urgent) }
11+
specify { expect(subject.use_after_commit_callbacks).to eq(true) }
12+
specify { expect(subject.indices_path).to eq('app/chewy') }
13+
specify { expect(subject.reset_disable_refresh_interval).to eq(false) }
14+
specify { expect(subject.reset_no_replicas).to eq(false) }
15+
specify { expect(subject.disable_refresh_async).to eq(false) }
16+
specify { expect(subject.search_class).to be < Chewy::Search::Request }
1817

1918
describe '#transport_logger=' do
2019
let(:logger) { Logger.new('/dev/null') }

spec/chewy/index/actions_spec.rb

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -583,67 +583,6 @@
583583
end
584584
end
585585

586-
xcontext 'applying journal' do
587-
before do
588-
stub_index(:cities) do
589-
index_scope City
590-
field :name, value: (lambda do
591-
sleep(rating)
592-
name
593-
end)
594-
end
595-
end
596-
597-
let!(:cities) { Array.new(3) { |i| City.create!(id: i + 1, name: "Name#{i + 1}", rating: 1) } }
598-
599-
let(:parallel_update) do
600-
Thread.new do
601-
p 'start parallel'
602-
sleep(1.5)
603-
cities.first.update(name: 'NewName1', rating: 0)
604-
cities.last.update(name: 'NewName3', rating: 0)
605-
CitiesIndex::City.import!([cities.first, cities.last], journal: true)
606-
p 'end parallel'
607-
end
608-
end
609-
610-
specify 'with journal application' do
611-
cities
612-
p 'cities created1'
613-
ActiveRecord::Base.connection.close if defined?(ActiveRecord::Base)
614-
[
615-
parallel_update,
616-
Thread.new do
617-
p 'start reset1'
618-
CitiesIndex.reset!('suffix')
619-
p 'end reset1'
620-
end
621-
].map(&:join)
622-
ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
623-
p 'expect1'
624-
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 NewName1], %w[2 Name2], %w[3 NewName3])
625-
p 'end expect1'
626-
end
627-
628-
specify 'without journal application' do
629-
cities
630-
p 'cities created2'
631-
ActiveRecord::Base.connection.close if defined?(ActiveRecord::Base)
632-
[
633-
parallel_update,
634-
Thread.new do
635-
p 'start reset2'
636-
CitiesIndex.reset!('suffix', apply_journal: false)
637-
p 'end reset2'
638-
end
639-
].map(&:join)
640-
ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
641-
p 'expect2'
642-
expect(CitiesIndex::City.pluck(:_id, :name)).to contain_exactly(%w[1 Name1], %w[2 Name2], %w[3 Name3])
643-
p 'end expect2'
644-
end
645-
end
646-
647586
context 'journaling' do
648587
before { City.create!(id: 1, name: 'Moscow') }
649588

spec/chewy/repository_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
describe Chewy::Repository do
44
subject { described_class.send(:new) }
55

6-
its(:analyzers) { should == {} }
7-
its(:tokenizers) { should == {} }
8-
its(:filters) { should == {} }
9-
its(:char_filters) { should == {} }
6+
specify { expect(subject.analyzers).to eq({}) }
7+
specify { expect(subject.tokenizers).to eq({}) }
8+
specify { expect(subject.filters).to eq({}) }
9+
specify { expect(subject.char_filters).to eq({}) }
1010

1111
describe '#analyzer' do
1212
specify { expect(subject.analyzer(:name)).to be_nil }

spec/chewy/search/query_proxy_spec.rb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
expect(subject.must(multi_match: {foo: 'bar'}).render[:body])
1313
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
1414
end
15-
specify do
16-
expect(subject.must(multi_match: {foo: 'bar'}).render[:body])
17-
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
18-
end
1915
end
2016

2117
describe '#should' do
@@ -24,10 +20,6 @@
2420
expect(subject.should(multi_match: {foo: 'bar'}).render[:body])
2521
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, should: {multi_match: {foo: 'bar'}}}})
2622
end
27-
specify do
28-
expect(subject.should(multi_match: {foo: 'bar'}).render[:body])
29-
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, should: {multi_match: {foo: 'bar'}}}})
30-
end
3123
end
3224

3325
describe '#must_not' do
@@ -36,10 +28,6 @@
3628
expect(subject.must_not(multi_match: {foo: 'bar'}).render[:body])
3729
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {multi_match: {foo: 'bar'}}}})
3830
end
39-
specify do
40-
expect(subject.must_not(multi_match: {foo: 'bar'}).render[:body])
41-
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {multi_match: {foo: 'bar'}}}})
42-
end
4331
end
4432

4533
describe '#and' do
@@ -48,10 +36,6 @@
4836
expect(subject.and(multi_match: {foo: 'bar'}).render[:body])
4937
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
5038
end
51-
specify do
52-
expect(subject.and(multi_match: {foo: 'bar'}).render[:body])
53-
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
54-
end
5539
specify do
5640
expect(subject.and(scope).render[:body])
5741
.to eq(query: {bool: {must: [{match: {foo: 'bar'}}, {bool: {must_not: {match: {foo: 'bar'}}}}]}})
@@ -64,10 +48,6 @@
6448
expect(subject.or(multi_match: {foo: 'bar'}).render[:body])
6549
.to eq(query: {bool: {should: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
6650
end
67-
specify do
68-
expect(subject.or(multi_match: {foo: 'bar'}).render[:body])
69-
.to eq(query: {bool: {should: [{match: {foo: 'bar'}}, {multi_match: {foo: 'bar'}}]}})
70-
end
7151
specify do
7252
expect(subject.or(scope).render[:body])
7353
.to eq(query: {bool: {should: [{match: {foo: 'bar'}}, {bool: {must_not: {match: {foo: 'bar'}}}}]}})
@@ -80,10 +60,6 @@
8060
expect(subject.not(multi_match: {foo: 'bar'}).render[:body])
8161
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {multi_match: {foo: 'bar'}}}})
8262
end
83-
specify do
84-
expect(subject.not(multi_match: {foo: 'bar'}).render[:body])
85-
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {multi_match: {foo: 'bar'}}}})
86-
end
8763
specify do
8864
expect(subject.not(scope).render[:body])
8965
.to eq(query: {bool: {must: {match: {foo: 'bar'}}, must_not: {bool: {must_not: {match: {foo: 'bar'}}}}}})

spec/chewy/search/response_spec.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,10 @@
6868

6969
describe '#took' do
7070
specify { expect(subject.took).to be >= 0 }
71-
72-
context do
73-
let(:request) do
74-
Chewy::Search::Request.new(CitiesIndex)
75-
.query(script: {script: {inline: 'sleep(100); true', lang: 'groovy'}})
76-
end
77-
specify do
78-
pending
79-
expect(subject.took).to be > 100
80-
end
81-
end
8271
end
8372

8473
describe '#timed_out?' do
8574
specify { expect(subject.timed_out?).to eq(false) }
86-
87-
context do
88-
let(:request) do
89-
Chewy::Search::Request.new(CitiesIndex)
90-
.query(script: {script: {inline: 'sleep(100); true', lang: 'groovy'}}).timeout('10ms')
91-
end
92-
specify do
93-
pending
94-
expect(subject.timed_out?).to eq(true)
95-
end
96-
end
9775
end
9876

9977
describe '#suggest' do

spec/chewy_spec.rb

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require 'spec_helper'
22

33
describe Chewy do
4-
it 'should have a version number' do
5-
expect(Chewy::VERSION).not_to be nil
4+
it 'has a version number' do
5+
expect(Chewy::VERSION).not_to be_nil
66
end
77

88
describe '.derive_name' do
@@ -31,24 +31,6 @@
3131
end
3232
end
3333

34-
xdescribe '.massacre' do
35-
before { drop_indices }
36-
37-
before do
38-
allow(Chewy).to receive_messages(configuration: Chewy.configuration.merge(prefix: 'prefix1'))
39-
stub_index(:admins).create!
40-
allow(Chewy).to receive_messages(configuration: Chewy.configuration.merge(prefix: 'prefix2'))
41-
stub_index(:developers).create!
42-
43-
drop_indices
44-
45-
allow(Chewy).to receive_messages(configuration: Chewy.configuration.merge(prefix: 'prefix1'))
46-
end
47-
48-
specify { expect(AdminsIndex.exists?).to eq(true) }
49-
specify { expect(DevelopersIndex.exists?).to eq(false) }
50-
end
51-
5234
describe '.client' do
5335
let!(:initial_client) { Chewy.current[:chewy_client] }
5436
let(:faraday_block) { proc {} }

0 commit comments

Comments
 (0)