From 47b5b5a9894fb84014ad369306d9447eadf4ccea Mon Sep 17 00:00:00 2001 From: stbn Date: Mon, 7 Jun 2021 12:47:54 +0200 Subject: [PATCH] improve output tests module using open3 gem --- Gemfile | 1 + Gemfile.lock | 2 ++ lib/tasks/test.rake | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 82b6835e75..05d49fcb71 100644 --- a/Gemfile +++ b/Gemfile @@ -113,6 +113,7 @@ group :development, :test do gem "i18n-tasks" gem "spring" gem "puma" + gem "open3", "~> 0.1.1" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 0508a448bc..4993e9f5df 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -330,6 +330,7 @@ GEM racc (~> 1.4) nori (2.6.0) oj (3.10.16) + open3 (0.1.1) open4 (1.3.4) os (1.1.1) paper_trail (12.0.0) @@ -572,6 +573,7 @@ DEPENDENCIES minitest-stub_any_instance mocha net-ldap + open3 (~> 0.1.1) paper_trail paranoia pg (~> 1.1) diff --git a/lib/tasks/test.rake b/lib/tasks/test.rake index 254962d6a3..96c7f58f78 100644 --- a/lib/tasks/test.rake +++ b/lib/tasks/test.rake @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'open3' + namespace :test do modules = %w{ gobierto_admin @@ -26,8 +28,16 @@ namespace :test do task "#{mod}".to_sym, [:fail_fast_enable] => :environment do |_t, args| files = `find test -path '*#{mod}*' -name '*_test.rb' | grep -v '#{mod}\/gobierto_'`.gsub("\n"," ") cmd = "bin/rails test #{files} #{"--fail-fast" if args[:fail_fast_enable]}" - puts cmd - puts `#{cmd}` + + Open3::popen3(cmd) do |std_in, std_out, std_err| + std_err.each_line do |line| + puts line + end + std_out.each_line do |line| + puts line + end + end + end end end