diff --git a/.travis.yml b/.travis.yml index 426ccf85a..79ae349f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ language: ruby services: - mongodb + - elasticsearch branches: only: @@ -23,29 +24,40 @@ matrix: include: - rvm: 2.2 jdk: oraclejdk8 - env: TEST_SUITE=unit + env: RAILS_VERSIONS=3.0 - rvm: 2.3 jdk: oraclejdk8 - env: TEST_SUITE=unit + env: RAILS_VERSIONS=5.0 - rvm: 2.4 jdk: oraclejdk8 - env: TEST_SUITE=unit + env: RAILS_VERSIONS=5.0 - rvm: 2.5 jdk: oraclejdk8 - env: TEST_SUITE=unit + env: RAILS_VERSIONS=5.0 - rvm: jruby-9.1 jdk: oraclejdk8 - env: TEST_SUITE=unit + env: RAILS_VERSIONS=5.0 - rvm: 2.5 jdk: oraclejdk8 - env: TEST_SUITE=integration QUIET=y + env: RAILS_VERSIONS=4.0,5.0 + +env: + global: + - ELASTICSEARCH_VERSION=6.4.0 + - QUIET=true + before_install: + - wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.deb + - wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.deb.sha512 + - shasum -a 512 -c elasticsearch-${ELASTICSEARCH_VERSION}.deb.sha512 + - sudo dpkg -i --force-confnew elasticsearch-${ELASTICSEARCH_VERSION}.deb + - sudo service elasticsearch restart - gem update --system -q - gem update bundler -q - gem --version @@ -57,7 +69,7 @@ install: - rake bundle:install script: - - rake test:$TEST_SUITE + - rake test:all notifications: disable: true diff --git a/Rakefile b/Rakefile index bfca05bfd..6020f304d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,7 @@ require 'pathname' -subprojects = %w| elasticsearch-rails elasticsearch-persistence elasticsearch-model | +subprojects = [ 'elasticsearch-rails', 'elasticsearch-persistence' ] +subprojects << 'elasticsearch-model' unless defined?(JRUBY_VERSION) __current__ = Pathname( File.expand_path('..', __FILE__) ) @@ -25,15 +26,9 @@ namespace :bundle do task :install do subprojects.each do |project| puts '-'*80 - sh "bundle install --gemfile #{__current__.join(project)}/Gemfile" + sh "cd #{__current__.join(project)} && bundle exec rake bundle:install" puts end - puts '-'*80 - sh "bundle install --gemfile #{__current__.join('elasticsearch-model/gemfiles')}/3.0.gemfile" - puts '-'*80 - sh "bundle install --gemfile #{__current__.join('elasticsearch-model/gemfiles')}/4.0.gemfile" - puts '-'*80 - sh "bundle install --gemfile #{__current__.join('elasticsearch-model/gemfiles')}/5.0.gemfile" end desc "Remove Gemfile.lock in all subprojects" @@ -60,7 +55,7 @@ namespace :test do end desc "Run Elasticsearch (Docker)" - task :setup_elasticsearch do + task :setup_elasticsearch_docker do begin sh <<-COMMAND.gsub(/^\s*/, '').gsub(/\s{1,}/, ' ') docker run -d=true \ @@ -70,15 +65,30 @@ namespace :test do --env "cluster.routing.allocation.disk.threshold_enabled=false" \ --publish 9250:9200 \ --rm \ - docker.elastic.co/elasticsearch/elasticsearch:6.4.0 + docker.elastic.co/elasticsearch/elasticsearch:${ELASTICSEARCH_VERSION} COMMAND require 'elasticsearch/extensions/test/cluster' - Elasticsearch::Extensions::Test::Cluster::Cluster.new(version: '6.4.0', + Elasticsearch::Extensions::Test::Cluster::Cluster.new(version: ENV['ELASTICSEARCH_VERSION'], number_of_nodes: 1).wait_for_green rescue end end + desc "Setup MongoDB (Docker)" + task :setup_mongodb_docker do + begin + if ENV['MONGODB_VERSION'] + sh <<-COMMAND.gsub(/^\s*/, '').gsub(/\s{1,}/, ' ') + wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB_VERSION}.tgz -O /tmp/mongodb.tgz && + tar -xvf /tmp/mongodb.tgz && + mkdir /tmp/data && + ${PWD}/mongodb-linux-x86_64-${MONGODB_VERSION}/bin/mongod --setParameter enableTestCommands=1 --dbpath /tmp/data --bind_ip 127.0.0.1 --auth &> /dev/null & + COMMAND + end + rescue + end + end + desc "Run integration tests in all subprojects" task :integration => :setup_elasticsearch do # 1/ elasticsearch-model @@ -106,8 +116,13 @@ namespace :test do desc "Run all tests in all subprojects" task :all do - Rake::Task['test:unit'].invoke - Rake::Task['test:integration'].invoke + subprojects.each do |project| + puts '-'*80 + sh "cd #{project} && " + + "unset BUNDLE_GEMFILE && " + + "bundle exec rake test:all" + puts "\n" + end end namespace :cluster do diff --git a/elasticsearch-model/Rakefile b/elasticsearch-model/Rakefile index e479d3599..6969c1d4a 100644 --- a/elasticsearch-model/Rakefile +++ b/elasticsearch-model/Rakefile @@ -4,12 +4,25 @@ desc "Run unit tests" task :default => 'test:unit' task :test => 'test:unit' -namespace :bundler do - desc "Install dependencies for all the Gemfiles" +if RUBY_VERSION < '2.3' + GEMFILES = ['3.0.gemfile', '4.0.gemfile', '5.0.gemfile'] +else + GEMFILES = ['4.0.gemfile', '5.0.gemfile'] +end + +namespace :bundle do + desc 'Install dependencies for all the Gemfiles in /gemfiles. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0' task :install do - sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/3.0.gemfile', __FILE__)}' bundle install" - sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/4.0.gemfile', __FILE__)}' bundle install" - sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/5.0.gemfile', __FILE__)}' bundle install" + unless defined?(JRUBY_VERSION) + puts '-'*80 + gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map { |v| "#{v}.gemfile"} : GEMFILES + gemfiles.each do |gemfile| + Bundler.with_clean_env do + sh "bundle install --gemfile #{File.expand_path('../gemfiles/'+gemfile, __FILE__)}" + end + puts '-'*80 + end + end end end @@ -18,38 +31,16 @@ end require 'rake/testtask' namespace :test do - Rake::TestTask.new(:run_unit) do |test| - test.libs << 'lib' << 'test' - test.test_files = FileList["test/unit/**/*_test.rb"] - test.verbose = false - test.warning = false - end - - Rake::TestTask.new(:run_integration) do |test| - test.libs << 'lib' << 'test' - test.test_files = FileList["test/integration/**/*_test.rb"] - test.verbose = false - test.warning = false - end - - desc "Run unit tests against ActiveModel 3, 4 and 5" - task :unit do - end - - desc "Run integration tests against latest stable ActiveModel (5)" - task :integration do - ['3.0.gemfile', '4.0.gemfile', '5.0.gemfile'].each do |gemfile| - ['bundle exec rake test:run_unit', 'bundle exec rspec'].each do |cmd| - sh "BUNDLE_GEMFILE='#{File.expand_path('../gemfiles/'+gemfile, __FILE__)}' #{cmd}" - end + desc 'Run all tests. Optionally define env variable RAILS_VERSIONS. E.g. RAILS_VERSIONS=3.0,5.0' + task :all, [:rails_versions] do |task, args| + gemfiles = ENV['RAILS_VERSIONS'] ? ENV['RAILS_VERSIONS'].split(',').map {|v| "#{v}.gemfile"} : GEMFILES + puts '-' * 80 + gemfiles.each do |gemfile| + sh "BUNDLE_GEMFILE='#{File.expand_path("../gemfiles/#{gemfile}", __FILE__)}' " + + " bundle exec rspec" + puts '-' * 80 end end - - desc "Run unit and integration tests" - task :all do - Rake::Task['test:unit'].invoke - Rake::Task['test:integration'].invoke - end end # ----- Documentation tasks --------------------------------------------------- diff --git a/elasticsearch-model/spec/spec_helper.rb b/elasticsearch-model/spec/spec_helper.rb index 178f9c9fe..9e46a27de 100644 --- a/elasticsearch-model/spec/spec_helper.rb +++ b/elasticsearch-model/spec/spec_helper.rb @@ -10,6 +10,10 @@ require 'yaml' require 'active_record' +unless defined?(ELASTICSEARCH_URL) + ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}" +end + RSpec.configure do |config| config.formatter = 'documentation' config.color = true @@ -18,7 +22,7 @@ require 'ansi' tracer = ::Logger.new(STDERR) tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" } - Elasticsearch::Model.client = Elasticsearch::Client.new host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}", + Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL, tracer: (ENV['QUIET'] ? nil : tracer) unless ActiveRecord::Base.connected? diff --git a/elasticsearch-persistence/Rakefile b/elasticsearch-persistence/Rakefile index 660e57211..0942fbdcf 100644 --- a/elasticsearch-persistence/Rakefile +++ b/elasticsearch-persistence/Rakefile @@ -12,19 +12,22 @@ require 'rspec/core/rake_task' namespace :test do RSpec::Core::RakeTask.new(:spec) - Rake::TestTask.new(:unit) do |test| - end - Rake::TestTask.new(:integration) do |test| + Rake::TestTask.new(:all) do |test| test.verbose = false test.warning = false test.deps = [ :spec ] end +end - Rake::TestTask.new(:all) do |test| - test.verbose = false - test.warning = false - test.deps = [ :spec ] +namespace :bundle do + desc 'Install gem dependencies' + task :install do + puts '-'*80 + Bundler.with_clean_env do + sh 'bundle install' + end + puts '-'*80 end end diff --git a/elasticsearch-persistence/spec/spec_helper.rb b/elasticsearch-persistence/spec/spec_helper.rb index 9f2f0f5df..6b8ea8182 100644 --- a/elasticsearch-persistence/spec/spec_helper.rb +++ b/elasticsearch-persistence/spec/spec_helper.rb @@ -1,6 +1,10 @@ require 'pry-nav' require 'elasticsearch/persistence' +unless defined?(ELASTICSEARCH_URL) + ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}" +end + RSpec.configure do |config| config.formatter = 'documentation' config.color = true @@ -13,7 +17,7 @@ # The default client to be used by the repositories. # # @since 6.0.0 -DEFAULT_CLIENT = Elasticsearch::Client.new(host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}", +DEFAULT_CLIENT = Elasticsearch::Client.new(host: ELASTICSEARCH_URL, tracer: (ENV['QUIET'] ? nil : ::Logger.new(STDERR))) class MyTestRepository diff --git a/elasticsearch-rails/Rakefile b/elasticsearch-rails/Rakefile index 622731c66..f555aaf42 100644 --- a/elasticsearch-rails/Rakefile +++ b/elasticsearch-rails/Rakefile @@ -28,6 +28,17 @@ namespace :test do end end +namespace :bundle do + desc 'Install gem dependencies' + task :install do + puts '-'*80 + Bundler.with_clean_env do + sh 'bundle install' + end + puts '-'*80 + end +end + # ----- Documentation tasks --------------------------------------------------- require 'yard' diff --git a/elasticsearch-rails/test/test_helper.rb b/elasticsearch-rails/test/test_helper.rb index e06554fc0..bc96002c5 100644 --- a/elasticsearch-rails/test/test_helper.rb +++ b/elasticsearch-rails/test/test_helper.rb @@ -1,4 +1,7 @@ RUBY_1_8 = defined?(RUBY_VERSION) && RUBY_VERSION < '1.9' +unless defined?(ELASTICSEARCH_URL) + ELASTICSEARCH_URL = ENV['ELASTICSEARCH_URL'] || "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}" +end exit(0) if RUBY_1_8 @@ -56,7 +59,7 @@ def setup tracer = ::Logger.new(STDERR) tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" } - Elasticsearch::Model.client = Elasticsearch::Client.new host: "localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9250)}", + Elasticsearch::Model.client = Elasticsearch::Client.new host: ELASTICSEARCH_URL, tracer: (ENV['QUIET'] ? nil : tracer) end end