require 'rake' require 'fileutils' # # Code Coverage # # begin # require 'class_loader/tasks' # # desc "Clean code coverage temporary files" # task clean: 'class_loader:clean' do # require 'fileutils' # FileUtils.rm_r '../*/coverage' if File.exist? '../*/coverage' # end # rescue LoadError # end # # Spec # begin require 'rspec/core/rake_task' task default: :spec task spec: 'spec:find_and_specs' namespace :spec do desc "Finds Specifications" task :find_and_specs do RSpec::Core::RakeTask.new('spec') do |t| t.pattern = "spec/**/[^_]*_spec.rb" end end desc "Run RSpec code exapmples in isolated mode (every spec file in another Ruby process)" task :isolated do Dir.glob("spec/[^_]**/[^_]*_spec.rb").each do |spec_file| Kernel.system "rspec #{spec_file}" end end end rescue LoadError task :default do puts "default rake task is :rspec but there's no rspec gem installed, install it first" end end # # before, after and remove task # def before task_name, &block $_task_counter ||= {} counter = ($_task_counter[task_name] ||= 0) before_task_name = "#{task_name}_before_#{counter}" task before_task_name, &block task task_name => before_task_name $_task_counter[task_name] += 1 end def after task_name, &block task task_name, &block end def remove_task(task_name) Rake.application.instance_variable_get('@tasks').delete(task_name.to_s) end alias :delete_task :remove_task # # project # $_project_dir = ( caller.find{|line| line =~ /\/Rakefile\:/} || raise("You can include the 'rake_ext' only in Rakefile!") ).sub(/\/Rakefile\:.*/, '') def project_dir $_project_dir end def project options = nil if options $_project = {} options.each{|k, v| $_project[k.to_sym] = v} $_project[:name] || raise("project name not defined") $_project[:official_name] ||= $_project[:name] require 'rake_ext/project' end $_project || raise("project not defined!") end # # Docs # desc "Generate documentation" task :docs do %x(cd docs && rocco -o site *.rb) end