From 4a82e1d7663313e724351943cbc313ef1c828a62 Mon Sep 17 00:00:00 2001 From: Tom Black Date: Tue, 19 Apr 2016 22:23:54 -0400 Subject: Improving Rakefile Added useful helper classes and methods, prettier output, other :lipstick: --- Rakefile | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/Rakefile b/Rakefile index df44733..fa3ad4c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,30 +1,49 @@ require 'rspec/core/rake_task' require './lib/ruby2d/version' -task default: 'all' +# Helpers + +class String + def colorize(c); "\e[#{c}m#{self}\e[0m" end + def bold; colorize('1') end + def blue; colorize('1;34') end + def red; colorize('1;31') end +end + +# Simple 2D is required for these tasks +if `which simple2d`.empty? + puts "Simple 2D not found!".red + puts "Install before running Rake tasks." + exit +end + +def run_cmd(cmd) + print "\n==> ".blue, cmd.bold, "\n\n" + system cmd +end def run_test(file) Rake::Task['build'].invoke Rake::Task['spec'].invoke + print "==> ".blue, "running tests/#{file}.rb".bold, "\n" system "( cd tests/ ; ruby #{file}.rb )" end -desc "Run the specs" +# Tasks + +task default: 'all' + +desc "Run the RSpec tests" RSpec::Core::RakeTask.new do |t| + print "\n==> ".blue, "running RSpec".bold, "\n\n" t.pattern = "spec/*spec.rb" end -desc "Build Gem" +desc "Build gem" task :build do - puts "==> uninstall gem" - system "gem uninstall ruby2d --executables" - - puts "==> build gem" - system "gem build ruby2d.gemspec --verbose" - - puts "==> install gem" - system "gem install ruby2d-#{Ruby2D::VERSION}.gem "\ - "--local --verbose -- --no-brew" + run_cmd "gem uninstall ruby2d --executables" + run_cmd "gem build ruby2d.gemspec --verbose" + run_cmd "gem install ruby2d-#{Ruby2D::VERSION}.gem --local --verbose" end desc "Run testcard" @@ -32,12 +51,12 @@ task :testcard do run_test 'testcard' end -desc "Run input" +desc "Run input tests" task :input do run_test 'input' end -desc "Run controller" +desc "Run controller tests" task :controller do run_test 'controller' end -- cgit v1.2.3