Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Add rake task all:rubies which runs specs for ruby 1.8.7, 1.9.3 and 2…
Browse files Browse the repository at this point in the history
….1.2
  • Loading branch information
judithroth committed Apr 27, 2015
1 parent 0ef5184 commit 8a35a1a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ namespace :all do
end
end

desc 'Install gems and run tests on several Ruby versions'
task :rubies do
success = case
when system('which rvm')
run_for_all_rubies :rvm
when system('which rbenv') && `rbenv commands`.split("\n").include?('alias')
# rbenv currently works only with the alias plugin, as we do not want to
# specify Ruby versions down to their patch levels.
run_for_all_rubies :rbenv
else
fail 'Currently only RVM and rbenv (with alias plugin) are supported. Open Rakefile and add your Ruby version manager!'
end

fail "Tests failed" unless success
end

end

def for_each_directory_of(path, &block)
Expand All @@ -58,3 +74,35 @@ def for_each_directory_of(path, &block)
block.call(directory)
end
end

def run_for_all_rubies(version_manager)
%w[
1.8.7
1.9.3
2.1.2
].all? do |ruby_version|
announce "Running bundle and specs for Ruby #{ruby_version}", 2

execute = case version_manager
when :rvm
"rvm #{ruby_version} do"
when :rbenv
ENV['RBENV_VERSION'] = ruby_version
'rbenv exec'
end

current_version = `#{execute} ruby -v`.match(/^ruby (\d\.\d\.\d)/)[1]
if current_version == ruby_version
puts "Currently active Ruby is #{current_version}"
system "#{execute} rake all:bundle all:spec"
else
fail "Failed to set Ruby #{ruby_version} (#{current_version} active!)"
end
end
end

def announce(text, level = 1)
space = "\n" * level
message = "# #{text}"
puts "\e[4;34m#{space + message}\e[0m" # blue underline
end

0 comments on commit 8a35a1a

Please sign in to comment.