Skip to content

Commit 4a1be97

Browse files
committed
[MODEL] Update test tasks
1 parent 570f029 commit 4a1be97

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

elasticsearch-model/Rakefile

+27-34
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ desc "Run unit tests"
44
task :default => 'test:unit'
55
task :test => 'test:unit'
66

7-
namespace :bundler do
8-
desc "Install dependencies for all the Gemfiles"
7+
if RUBY_VERSION < '2.3'
8+
GEMFILES = ['3.0.gemfile', '4.0.gemfile', '5.0.gemfile']
9+
else
10+
GEMFILES = ['4.0.gemfile', '5.0.gemfile']
11+
end
12+
13+
namespace :bundle do
14+
desc 'Install dependencies for all the Gemfiles in /gemfiles. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
915
task :install do
10-
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/3.0.gemfile', __FILE__)}' bundle install"
11-
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/4.0.gemfile', __FILE__)}' bundle install"
12-
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/5.0.gemfile', __FILE__)}' bundle install"
16+
unless defined?(JRUBY_VERSION)
17+
puts '-'*80
18+
gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map { |v| "#{v}.gemfile"} : GEMFILES
19+
gemfiles.each do |gemfile|
20+
Bundler.with_clean_env do
21+
sh "bundle install --gemfile #{File.expand_path('../gemfiles/'+gemfile, __FILE__)}"
22+
end
23+
puts '-'*80
24+
end
25+
end
1326
end
1427
end
1528

@@ -18,38 +31,18 @@ end
1831
require 'rake/testtask'
1932
namespace :test do
2033

21-
Rake::TestTask.new(:run_unit) do |test|
22-
test.libs << 'lib' << 'test'
23-
test.test_files = FileList["test/unit/**/*_test.rb"]
24-
test.verbose = false
25-
test.warning = false
26-
end
27-
28-
Rake::TestTask.new(:run_integration) do |test|
29-
test.libs << 'lib' << 'test'
30-
test.test_files = FileList["test/integration/**/*_test.rb"]
31-
test.verbose = false
32-
test.warning = false
33-
end
34-
35-
desc "Run unit tests against ActiveModel 3, 4 and 5"
36-
task :unit do
37-
end
38-
39-
desc "Run integration tests against latest stable ActiveModel (5)"
40-
task :integration do
41-
['3.0.gemfile', '4.0.gemfile', '5.0.gemfile'].each do |gemfile|
42-
['bundle exec rake test:run_unit', 'bundle exec rspec'].each do |cmd|
43-
sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/'+gemfile, __FILE__)}' #{cmd}"
34+
desc 'Run all tests. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0'
35+
task :all, [:rails_versions] do |task, args|
36+
unless defined?(JRUBY_VERSION)
37+
gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map { |v| "#{v}.gemfile"} : GEMFILES
38+
puts '-'*80
39+
gemfiles.each do |gemfile|
40+
sh "BUNDLE_GEMFILE='#{File.expand_path("../gemfiles/#{gemfile}", __FILE__)}' " +
41+
" bundle exec rspec"
42+
puts '-'*80
4443
end
4544
end
4645
end
47-
48-
desc "Run unit and integration tests"
49-
task :all do
50-
Rake::Task['test:unit'].invoke
51-
Rake::Task['test:integration'].invoke
52-
end
5346
end
5447

5548
# ----- Documentation tasks ---------------------------------------------------

elasticsearch-model/spec/spec_helper.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
require 'yaml'
1111
require 'active_record'
1212

13+
unless defined?(ELASTICSEARCH_URL)
14+
ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}"
15+
end
16+
1317
RSpec.configure do |config|
1418
config.formatter = 'documentation'
1519
config.color = true
@@ -18,7 +22,7 @@
1822
require 'ansi'
1923
tracer = ::Logger.new(STDERR)
2024
tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" }
21-
Elasticsearch::Model.client = Elasticsearch::Client.new host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}",
25+
Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL,
2226
tracer: (ENV['QUIET'] ? nil : tracer)
2327

2428
unless ActiveRecord::Base.connected?

0 commit comments

Comments
 (0)