templates/Rakefile in linecook-0.6.2 vs templates/Rakefile in linecook-1.0.0

- old
+ new

@@ -1,16 +1,18 @@ require 'rake' +require 'rake/rdoctask' +require 'rake/gempackagetask' # # Gem tasks # -require 'rake/rdoctask' -require 'rake/gempackagetask' - def gemspec - @gemspec ||= eval(File.read('<%= project_name %>.gemspec'), TOPLEVEL_BINDING) + @gemspec ||= begin + gemspec_path = File.expand_path('../<%= project_name %>.gemspec', __FILE__) + eval(File.read(gemspec_path), TOPLEVEL_BINDING) + end end Rake::GemPackageTask.new(gemspec) do |pkg| pkg.need_tar = true end @@ -70,76 +72,71 @@ # # Linecook Helpers # -lib_dir = File.expand_path("../lib", __FILE__) -helpers_dir = File.expand_path("../helpers", __FILE__) +package = ENV['PACKAGE'] +force = (ENV['FORCE'] == 'true') -sources = {} -helpers = [] +desc "build helpers and packages" +task :build => :bundle do + sh "bundle exec linecook build #{force ? '--force ' : nil}#{package}" +end -Dir.glob("#{helpers_dir}/**/*").each do |source| - next if File.directory?(source) - (sources[File.dirname(source)] ||= []) << source +desc "run packages" +task :run => :build do + sh "bundle exec linecook run #{package}" end -sources.each_pair do |dir, sources| - name = dir[(helpers_dir.length + 1)..-1] - target = File.join(lib_dir, 'linebook', "#{name}.rb") - - file target => sources + [dir] do - system "bundle exec linecook helper '#{name}' --force" - end - - helpers << target +desc "start each vm at CURRENT" +task :start => :bundle do + sh 'bundle exec linecook start --socket --snapshot CURRENT' end -desc "generate helpers" -task :helpers => helpers + [:bundle] +desc "snapshot each vm to a new CURRENT" +task :snapshot => :bundle do + sh 'bundle exec linecook snapshot CURRENT' +end -# -# Linecook Scripts -# +desc "reset each vm to BASE" +task :reset_base => :bundle do + sh 'bundle exec linecook snapshot --reset BASE' + sh 'bundle exec linecook snapshot CURRENT' + sh 'bundle exec linecook start --socket --snapshot CURRENT' +end -scripts = Dir.glob("scripts/*.yml") -dependencies = Dir.glob('{attributes,files,recipes,templates}/**/*') - -scripts.each do |source| - target = source.chomp('.yml') - name = File.basename(target) - - namespace :scripts do - file target => dependencies + [source] + helpers do - sh "bundle exec linecook package '#{source}' '#{target}' --force" - end - - desc "generate the script: #{name}" - task name => target - end - - task :scripts => target +desc "stop each vm" +task :stop => :bundle do + sh 'bundle exec linecook stop' end -desc "generate scripts" -task :scripts - # # Test tasks # desc 'Default: Run tests.' task :default => :test -desc 'Run the tests' -task :test => :helpers do +desc 'Run the tests assuming each vm is setup' +task :quicktest => :build do tests = Dir.glob('test/**/*_test.rb') + tests.delete_if {|test| test =~ /_test\/test_/ } if ENV['RCOV'] == 'true' FileUtils.rm_rf File.expand_path('../coverage', __FILE__) sh('rcov', '-w', '--text-report', '--exclude', '^/', *tests) else sh('ruby', '-w', '-e', 'ARGV.dup.each {|test| load test}', *tests) + end +end + +desc 'Run the tests' +task :test do + begin + Rake::Task["start"].invoke + Rake::Task["quicktest"].invoke + ensure + Rake::Task["stop"].execute(nil) end end desc 'Run rcov' task :rcov do