Rakefile in vanity-1.3.0 vs Rakefile in vanity-1.4.0.beta

- old
+ new

@@ -1,54 +1,107 @@ require "rake/testtask" +# -- Building stuff -- + spec = Gem::Specification.load(File.expand_path("vanity.gemspec", File.dirname(__FILE__))) desc "Build the Gem" -task :build=>:test do +task :build do sh "gem build #{spec.name}.gemspec" end desc "Install #{spec.name} locally" task :install=>:build do sudo = "sudo" unless File.writable?( Gem::ConfigMap[:bindir]) sh "#{sudo} gem install #{spec.name}-#{spec.version}.gem" end desc "Push new release to gemcutter and git tag" -task :push=>:build do +task :push=>["test:rubies", "build"] do sh "git push" puts "Tagging version #{spec.version} .." sh "git tag v#{spec.version}" sh "git push --tag" puts "Building and pushing gem .." sh "gem push #{spec.name}-#{spec.version}.gem" end +# -- Testing stuff -- + +# Ruby versions we're testing with. +RUBIES = %w{1.8.7 1.9.1 1.9.2} + +# Use rake test:rubies to run all combination of tests (see test:adapters) using +# all the versions of Ruby specified in RUBIES. Or to test a specific version of +# Ruby, rake test:rubies[1.8.7]. +# +# This task uses RVM to install all the Ruby versions it needs, and creates a +# vanity gemset in each one that includes Bundler and all the gems specified in +# Gemfile. If anything goes south you can always wipe these gemsets or uninstall +# these Rubies and start over. +desc "Test using multiple versions of Ruby" +task "test:rubies", :ruby do |t, args| + rubies = args.ruby ? [args.ruby] : RUBIES + rubies.each do |ruby| + puts "** Setup #{ruby}" + sh "env rvm_install_on_use_flag=1 rvm_gemset_create_on_use_flag=1 rvm use #{ruby}@vanity" + sh "rvm #{ruby}@vanity rake test:setup" + puts + puts "** Test using #{ruby}" + sh "rvm #{ruby}@vanity -S bundle exec rake test:adapters #{'--trace' if Rake.application.options.trace}" + end +end + +task "test:setup" do + # Intended to be used from test:rubies, within specific RVM context. + begin # Make sure we got Bundler installed. + require "bundler" + rescue LoadError + sh "gem install bundler" + end + begin # Make sure we got all the dependencies + sh "bundle exec ruby -e puts > /dev/null" + rescue + sh "bundle install" + end +end + +# These are all the adapters we're going to test with. +ADAPTERS = %w{redis mongodb} + +desc "Test using different back-ends" +task "test:adapters", :adapter do |t, args| + adapters = args.adapter ? [args.adapter] : ADAPTERS + adapters.each do |adapter| + puts "** Testing #{adapter} adapter" + sh "rake test ADAPTER=#{adapter} #{'--trace' if Rake.application.options.trace}" + end +end + +# Run the test suit. + task :default=>:test -desc "Run all tests using Redis mock (also default task)" +desc "Run all tests" Rake::TestTask.new do |task| - task.test_files = FileList['test/*_test.rb'] + task.test_files = FileList['test/**/*_test.rb'] if Rake.application.options.trace #task.warning = true task.verbose = true elsif Rake.application.options.silent task.ruby_opts << "-W0" else task.verbose = true end + task.ruby_opts << "-I." end -desc "Run all tests using live redis server" -task "test:redis" do - ENV["REDIS"] = "true" - task(:test).invoke -end - task(:clobber) { rm_rf "tmp" } +# -- Documenting stuff -- + begin require "yard" YARD::Rake::YardocTask.new(:yardoc) do |task| task.files = FileList["lib/**/*.rb"].exclude("lib/vanity/backport.rb") task.options = "--output", "html/api", "--title", "Vanity #{spec.version}", "--main", "README.rdoc", "--files", "CHANGELOG" @@ -57,19 +110,26 @@ end desc "Jekyll generates the main documentation (sans API)" task(:jekyll) { sh "jekyll", "doc", "html" } +file "html/vanity-api-#{spec.version}.zip"=>:yardoc do |t| + Dir.chdir "html" do + sh "zip vanity-api-#{spec.version}.zip -r api" + end +end desc "Create documentation in docs directory (including API)" -task :docs=>[:jekyll, :yardoc] +task :docs=>[:jekyll, :yardoc, "html/vanity-api-#{spec.version}.zip"] desc "Remove temporary files and directories" -task(:clobber) { rm_rf "html" } +task(:clobber) { rm_rf "html" ; rm_rf ".yardoc" } desc "Publish documentation to vanity.labnotes.org" task :publish=>[:clobber, :docs] do sh "rsync -cr --del --progress html/ labnotes.org:/var/www/vanity/" end + +# -- Misc -- task :report do $LOAD_PATH.unshift "lib" require "vanity" require "timecop"