Last active
August 29, 2015 14:01
-
-
Save otobrglez/222e59132cae86a46cb1 to your computer and use it in GitHub Desktop.
Rake task to execute RSpec suite for each "project" inside its own folder (RVM)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# By Oto Brglez - <otobrglez@gmail.com> | |
# | |
# Problem: Sometimes you have project that is build out of many "sub-projects", | |
# sub-project, can be anything, gem, rails app to single page app. And then you | |
# want to run specs for each of this project to see if everything works. Then what? | |
# | |
# Solution: On your "root" folder create Rake task that goes and executes test suite | |
# for each project and summers everything into report. Well... At least thats what this is. ;) | |
# | |
# Cheers, | |
# - Oto | |
require 'open3' | |
# Array that holds your project folders. In my case "kicktrace" and "zed" | |
components = %w{ | |
kicktrace zed | |
} | |
# Array that holds report | |
big_report = [] | |
components.map(&:to_sym).each_with_index do |component,i| | |
desc "Run tests for #{component}" | |
task component do | |
rvm_set = nil | |
# Determine Ruby version and gemset for each project | |
cmd = %[echo `cat #{component}/.ruby-version`@`cat #{component}/.ruby-gemset`] | |
Open3.popen3(cmd) { |stdin, stdout, stderr, wait_thr| rvm_set = stdout.read.strip } | |
# We want to know how long will the suite run | |
start = DateTime.now | |
# "cd" into project, exec rspec, and "fail fast" | |
test_cmd = %[cd #{component} && rvm "#{rvm_set}" exec bundle exec rspec . --fail-fast --format=progress > /dev/null ] | |
# Remember to capture response status. Status != 0 is fail | |
sh(test_cmd) do |ok, res| | |
status = !ok ? "Failed" : "Success" | |
completed = '%.3f' % ((DateTime.now - start) * 24 * 60 * 60).to_f | |
big_report.push "#{component} : #{status} in #{completed}s" | |
end | |
# Output repor | |
if i == components.size-1 | |
puts "\n" | |
puts big_report | |
end | |
end | |
end | |
# Default task goes over all components | |
task :default => components |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Task can be executed from
root
folder simply...Oh, and output looks like this;