From b3c0b5d824cfd5d166713ca1e24648170e62f969 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Tue, 20 Jan 2015 10:25:08 +0200 Subject: [PATCH] Don't load test related tasks in other env --- lib/tasks/test.rake | 66 +++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake index e8dc5ccfa..20e3f5f91 100644 --- a/lib/tasks/test.rake +++ b/lib/tasks/test.rake @@ -1,43 +1,45 @@ begin - require 'rspec/core/rake_task' - require 'open3' + if Rails.env.test? || Rails.env.development? + require 'rspec/core/rake_task' + require 'open3' - desc 'Run all specs against server' - task 'test' do - test_against_server { Rake::Task['spec'].invoke } - end + desc 'Run all specs against server' + task 'test' do + test_against_server { Rake::Task['spec'].invoke } + end - desc 'Run EPP specs against server' - task 'test:epp' do - test_against_server { Rake::Task['spec:epp'].invoke } - end + desc 'Run EPP specs against server' + task 'test:epp' do + test_against_server { Rake::Task['spec:epp'].invoke } + end - desc 'Run all but EPP specs' - RSpec::Core::RakeTask.new('test:other') do |t| - t.rspec_opts = '--tag ~epp' - end + desc 'Run all but EPP specs' + RSpec::Core::RakeTask.new('test:other') do |t| + t.rspec_opts = '--tag ~epp' + end - desc 'Run all but EPP specs' - RSpec::Core::RakeTask.new('test:all_but_features') do |t| - t.rspec_opts = '--tag ~feature' - end + desc 'Run all but EPP specs' + RSpec::Core::RakeTask.new('test:all_but_features') do |t| + t.rspec_opts = '--tag ~feature' + end - desc 'Generate EPP doc from specs' - RSpec::Core::RakeTask.new('test:epp_doc') do |t| - ENV['EPP_DOC'] = 'true' - t.rspec_opts = '--tag epp --require support/epp_doc.rb --format EppDoc' - end + desc 'Generate EPP doc from specs' + RSpec::Core::RakeTask.new('test:epp_doc') do |t| + ENV['EPP_DOC'] = 'true' + t.rspec_opts = '--tag epp --require support/epp_doc.rb --format EppDoc' + end - Rake::Task[:default].prerequisites.clear - task default: :test + Rake::Task[:default].prerequisites.clear + task default: :test - def test_against_server - _stdin, _stdout, _stderr, wait_thr = Open3.popen3('unicorn -E test -p 8989') - pid = wait_thr.pid - begin - yield - ensure - `kill #{pid}` + def test_against_server + _stdin, _stdout, _stderr, wait_thr = Open3.popen3('unicorn -E test -p 8989') + pid = wait_thr.pid + begin + yield + ensure + `kill #{pid}` + end end end rescue LoadError => e