Skip to content

Instantly share code, notes, and snippets.

@otobrglez
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otobrglez/222e59132cae86a46cb1 to your computer and use it in GitHub Desktop.
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)
# 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
@otobrglez
Copy link
Author

Task can be executed from root folder simply...

rake

Oh, and output looks like this;

kicktrace : Success in 1.378s
zed : Failed in 1.211s
eksperiments : Success in 2.002s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment