Skip to content

Commit 221005e

Browse files
committed
Make tests run on Ruby 2.2.x
1. Added selective require of test-unit gem vs. minitest 2. Added closing `true` statement to Mocha `expects(:foo).with {...}` expressions, because `assert_equal` doesn't return a truthy value 3. Don't require "turn" on Ruby 2.2 4. Don't run integration tests against ActiveModel/Record 3.0 on Ruby 2.2 5. Don't run the Rails instrumentation test on Ruby 2.2 (should be investigated)
1 parent 2dcf3b6 commit 221005e

23 files changed

+132
-28
lines changed

elasticsearch-model/Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace :test do
3030

3131
desc "Run integration tests against ActiveModel 3 and 4"
3232
task :integration do
33-
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/3.0.gemfile', __FILE__)}' bundle exec rake test:run_integration"
33+
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/3.0.gemfile', __FILE__)}' bundle exec rake test:run_integration" unless defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
3434
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/4.0.gemfile', __FILE__)}' bundle exec rake test:run_integration"
3535
end
3636

elasticsearch-model/elasticsearch-model.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
4040
s.add_development_dependency "will_paginate"
4141

4242
s.add_development_dependency "minitest", "~> 4"
43+
s.add_development_dependency "test-unit" if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
4344
s.add_development_dependency "shoulda-context"
4445
s.add_development_dependency "mocha"
4546
s.add_development_dependency "turn"

elasticsearch-model/test/test_helper.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010

1111
puts '-'*80
1212

13-
require 'minitest/autorun'
14-
begin; require 'test/unit'; rescue LoadError; end
13+
if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
14+
require 'test-unit'
15+
require 'mocha/test_unit'
16+
else
17+
require 'minitest/autorun'
18+
require 'mocha/mini_test'
19+
end
20+
1521
require 'shoulda-context'
16-
require 'mocha/setup'
17-
require 'turn' unless ENV["TM_FILEPATH"] || ENV["NOTURN"] || RUBY_1_8
22+
23+
require 'turn' unless ENV["TM_FILEPATH"] || ENV["NOTURN"] || defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
1824

1925
require 'ansi'
2026
require 'oj'
@@ -28,12 +34,6 @@
2834
require 'elasticsearch/extensions/test/cluster'
2935
require 'elasticsearch/extensions/test/startup_shutdown'
3036

31-
module Test
32-
module Unit
33-
class TestCase < MiniTest::Unit::TestCase; end
34-
end
35-
end unless defined?(::Test::Unit::TestCase)
36-
3737
module Elasticsearch
3838
module Test
3939
class IntegrationTestCase < ::Test::Unit::TestCase

elasticsearch-model/test/unit/callbacks_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def callbacks_mixin
2222
::DummyCallbacksModel.expects(:__send__).with do |method, parameter|
2323
assert_equal :include, method
2424
assert_equal DummyCallbacksAdapter::CallbacksMixin, parameter
25+
true
2526
end
2627

2728
Elasticsearch::Model::Callbacks.included(DummyCallbacksModel)

elasticsearch-model/test/unit/importing_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ def importing_mixin
108108
DummyImportingModel.expects(:__find_in_batches).with do |options|
109109
assert_equal 'bar', options[:foo]
110110
assert_nil options[:force]
111+
true
111112
end
112113

113114
DummyImportingModel.expects(:create_index!).with do |options|
114115
assert_equal true, options[:force]
116+
true
115117
end
116118

117119
DummyImportingModel.expects(:index_name).returns('foo')

elasticsearch-model/test/unit/indexing_test.rb

+13
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def as_indexed_json(options={})
164164
instance.expects(:instance_variable_set).with do |name, value|
165165
assert_equal :@__changed_attributes, name
166166
assert_equal({foo: 'Two'}, value)
167+
true
167168
end
168169

169170
::DummyIndexingModelWithCallbacks.__send__ :include, Elasticsearch::Model::Indexing::InstanceMethods
@@ -182,6 +183,7 @@ def as_indexed_json(options={})
182183
assert_equal 'bar', payload[:type]
183184
assert_equal '1', payload[:id]
184185
assert_equal 'JSON', payload[:body]
186+
true
185187
end
186188

187189
instance.expects(:client).returns(client)
@@ -199,6 +201,7 @@ def as_indexed_json(options={})
199201

200202
client.expects(:index).with do |payload|
201203
assert_equal 'A', payload[:parent]
204+
true
202205
end
203206

204207
instance.expects(:client).returns(client)
@@ -218,6 +221,7 @@ def as_indexed_json(options={})
218221
assert_equal 'foo', payload[:index]
219222
assert_equal 'bar', payload[:type]
220223
assert_equal '1', payload[:id]
224+
true
221225
end
222226

223227
instance.expects(:client).returns(client)
@@ -234,6 +238,7 @@ def as_indexed_json(options={})
234238

235239
client.expects(:delete).with do |payload|
236240
assert_equal 'A', payload[:parent]
241+
true
237242
end
238243

239244
instance.expects(:client).returns(client)
@@ -267,6 +272,7 @@ def as_indexed_json(options={})
267272
assert_equal 'bar', payload[:type]
268273
assert_equal '1', payload[:id]
269274
assert_equal({foo: 'bar'}, payload[:body][:doc])
275+
true
270276
end
271277

272278
instance.expects(:client).returns(client)
@@ -286,6 +292,7 @@ def as_indexed_json(options={})
286292

287293
client.expects(:update).with do |payload|
288294
assert_equal({:foo => 'B'}, payload[:body][:doc])
295+
true
289296
end
290297

291298
instance.expects(:client).returns(client)
@@ -306,6 +313,7 @@ def as_indexed_json(options={})
306313

307314
client.expects(:update).with do |payload|
308315
assert_equal({'foo' => 'BAR'}, payload[:body][:doc])
316+
true
309317
end
310318

311319
instance.expects(:client).returns(client)
@@ -356,6 +364,7 @@ class ::DummyIndexingModelForRecreate
356364
assert_equal 'dummy_indexing_model_for_recreates', payload[:index]
357365
assert_equal 1, payload[:body][:settings][:index][:number_of_shards]
358366
assert_equal 'keyword', payload[:body][:mappings][:dummy_indexing_model_for_recreate][:properties][:foo][:analyzer]
367+
true
359368
end.returns({})
360369

361370
DummyIndexingModelForRecreate.expects(:client).returns(client).at_least_once
@@ -434,10 +443,12 @@ class ::DummyIndexingModelForRecreate
434443
should "create the custom index" do
435444
@indices.expects(:exists).with do |arguments|
436445
assert_equal 'custom-foo', arguments[:index]
446+
true
437447
end
438448

439449
@indices.expects(:create).with do |arguments|
440450
assert_equal 'custom-foo', arguments[:index]
451+
true
441452
end
442453

443454
DummyIndexingModelForRecreate.create_index! index: 'custom-foo'
@@ -446,6 +457,7 @@ class ::DummyIndexingModelForRecreate
446457
should "delete the custom index" do
447458
@indices.expects(:delete).with do |arguments|
448459
assert_equal 'custom-foo', arguments[:index]
460+
true
449461
end
450462

451463
DummyIndexingModelForRecreate.delete_index! index: 'custom-foo'
@@ -454,6 +466,7 @@ class ::DummyIndexingModelForRecreate
454466
should "refresh the custom index" do
455467
@indices.expects(:refresh).with do |arguments|
456468
assert_equal 'custom-foo', arguments[:index]
469+
true
457470
end
458471

459472
DummyIndexingModelForRecreate.refresh_index! index: 'custom-foo'

elasticsearch-model/test/unit/proxy_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def changes
4848
instance.__elasticsearch__.expects(:instance_variable_set).with do |name, value|
4949
assert_equal :@__changed_attributes, name
5050
assert_equal({foo: 'Two'}, value)
51+
true
5152
end
5253

5354
::DummyProxyModelWithCallbacks.__send__ :include, Elasticsearch::Model::Proxy

elasticsearch-model/test/unit/response_pagination_kaminari_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def self.document_type; 'bar'; end
3434
.with do |definition|
3535
assert_equal 25, definition[:from]
3636
assert_equal 25, definition[:size]
37+
true
3738
end
3839
.returns(RESPONSE)
3940

@@ -51,6 +52,7 @@ def self.document_type; 'bar'; end
5152
.with do |definition|
5253
assert_equal 75, definition[:from]
5354
assert_equal 25, definition[:size]
55+
true
5456
end
5557
.returns(RESPONSE)
5658

elasticsearch-model/test/unit/response_pagination_will_paginate_test.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class WillPaginateResponse < Elasticsearch::Model::Response::Response
8888
.with do |definition|
8989
assert_equal 0, definition[:from]
9090
assert_equal 33, definition[:size]
91+
true
9192
end
9293
.returns(RESPONSE)
9394

@@ -105,6 +106,7 @@ class WillPaginateResponse < Elasticsearch::Model::Response::Response
105106
.with do |definition|
106107
assert_equal 33, definition[:from]
107108
assert_equal 33, definition[:size]
109+
true
108110
end
109111
.returns(RESPONSE)
110112

@@ -122,6 +124,7 @@ class WillPaginateResponse < Elasticsearch::Model::Response::Response
122124
.with do |definition|
123125
assert_equal 18, definition[:from]
124126
assert_equal 9, definition[:size]
127+
true
125128
end
126129
.returns(RESPONSE)
127130

@@ -133,12 +136,13 @@ class WillPaginateResponse < Elasticsearch::Model::Response::Response
133136
assert_equal 9, @response.search.definition[:size]
134137
end
135138

136-
should "searches for page 1 if specified page is < 1" do
139+
should "search for first page if specified page is < 1" do
137140
@response.klass.client
138141
.expects(:search)
139142
.with do |definition|
140143
assert_equal 0, definition[:from]
141144
assert_equal 33, definition[:size]
145+
true
142146
end
143147
.returns(RESPONSE)
144148

elasticsearch-model/test/unit/searching_search_request_test.rb

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def self.document_type; 'bar'; end
1818
should "pass the search definition as a simple query" do
1919
@client.expects(:search).with do |params|
2020
assert_equal 'foo', params[:q]
21+
true
2122
end
2223
.returns({})
2324

@@ -28,6 +29,7 @@ def self.document_type; 'bar'; end
2829
should "pass the search definition as a Hash" do
2930
@client.expects(:search).with do |params|
3031
assert_equal( {foo: 'bar'}, params[:body] )
32+
true
3133
end
3234
.returns({})
3335

@@ -38,6 +40,7 @@ def self.document_type; 'bar'; end
3840
should "pass the search definition as a JSON string" do
3941
@client.expects(:search).with do |params|
4042
assert_equal( '{"foo":"bar"}', params[:body] )
43+
true
4144
end
4245
.returns({})
4346

@@ -52,6 +55,7 @@ def to_hash; {foo: 'bar'}; end
5255

5356
@client.expects(:search).with do |params|
5457
assert_equal( {foo: 'bar'}, params[:body] )
58+
true
5559
end
5660
.returns({})
5761

@@ -63,6 +67,7 @@ def to_hash; {foo: 'bar'}; end
6367
@client.expects(:search).with do |params|
6468
assert_equal 'foo', params[:q]
6569
assert_equal 15, params[:size]
70+
true
6671
end
6772
.returns({})
6873

elasticsearch-model/test/unit/searching_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def self.document_type; 'bar'; end
2424
assert_equal DummySearchingModel, klass
2525
assert_equal 'foo', query
2626
assert_equal({default_operator: 'AND'}, options)
27+
true
2728
end
2829
.returns( stub('search') )
2930

elasticsearch-persistence/elasticsearch-persistence.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
4040
s.add_development_dependency "elasticsearch-extensions"
4141

4242
s.add_development_dependency "minitest", "~> 4"
43+
s.add_development_dependency "test-unit" if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
4344
s.add_development_dependency "shoulda-context"
4445
s.add_development_dependency "mocha"
4546
s.add_development_dependency "turn"

elasticsearch-persistence/test/test_helper.rb

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
# MUST be called before requiring `test/unit`.
99
at_exit { Elasticsearch::Test::IntegrationTestCase.__run_at_exit_hooks } if ENV['SERVER']
1010

11-
require 'test/unit'
11+
if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
12+
require 'test-unit'
13+
require 'mocha/test_unit'
14+
else
15+
require 'minitest/autorun'
16+
require 'mocha/mini_test'
17+
end
18+
1219
require 'shoulda-context'
13-
require 'mocha/setup'
14-
require 'turn' unless ENV["TM_FILEPATH"] || ENV["NOTURN"] || RUBY_1_8
20+
21+
require 'turn' unless ENV["TM_FILEPATH"] || ENV["NOTURN"] || defined?(RUBY_VERSION) && RUBY_VERSION > '2.2'
1522

1623
require 'ansi'
1724
require 'oj'

elasticsearch-persistence/test/unit/model_find_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class DummyFindModel
9393
assert_equal 'scan', arguments[:search_type]
9494
assert_equal 'foo', arguments[:index]
9595
assert_equal 'bar', arguments[:type]
96+
true
9697
end
9798
.returns(MultiJson.load('{"_scroll_id":"abc123==", "hits":{"hits":[]}}'))
9899

0 commit comments

Comments
 (0)