lib/sniff/rake_tasks.rb in sniff-0.4.1 vs lib/sniff/rake_tasks.rb in sniff-0.4.2

- old
+ new

@@ -9,25 +9,26 @@ module Sniff class RakeTasks def self.define_tasks(&blk) - new.define_tasks(&blk) + new(&blk).define_tasks end - attr_accessor :earth_domains + attr_accessor :earth_domains, :cucumber, :rspec, :rcov, :rocco def initialize + self.earth_domains = :all + self.cucumber = true + self.rspec = false + self.rcov = true + self.rocco = true yield self if block_given? end - def earth_domains - @earth_domains ||= :all - end - def gemname - @gemname ||= Dir.glob(File.join(Dir.pwd, '*.gemspec')).first + @gemname ||= File.basename(Dir.glob(File.join(Dir.pwd, '*.gemspec')).first, '.gemspec') end def git(cmd, dir = nil, &blk) full_cmd = '' full_cmd << "cd #{dir} && " if dir @@ -44,72 +45,101 @@ require 'irb' ARGV.clear IRB.start end - Rocco::make 'docs/', "lib/#{gemname}/carbon_model.rb" + if rocco + Rocco::make 'docs/', "lib/#{gemname}/carbon_model.rb" - desc 'Set up and build rocco docs' - task :docs_init => :rocco + desc 'Set up and build rocco docs' + task :docs_init => :rocco - desc 'Rebuild rocco docs' - task :docs => ['pages:sync', :rocco] - directory 'docs/' + desc 'Rebuild rocco docs' + task :docs => ['pages:sync', :rocco] + directory 'docs/' - desc 'Update gh-pages branch' - task :pages => :docs do - rev = `git rev-parse --short HEAD`.strip - git 'add *.html', 'docs' - git "commit -m 'rebuild pages from #{rev}'", 'docs' do |ok,res| - if ok - verbose { puts "gh-pages updated" } - git 'push -q o HEAD:gh-pages', 'docs' unless ENV['NO_PUSH'] + desc 'Update gh-pages branch' + task :pages => :docs do + rev = `git rev-parse --short HEAD`.strip + git 'add *.html', 'docs' + git "commit -m 'rebuild pages from #{rev}'", 'docs' do |ok,res| + if ok + verbose { puts "gh-pages updated" } + git 'push -q o HEAD:gh-pages', 'docs' unless ENV['NO_PUSH'] + end end end - end - # Update the pages/ directory clone - namespace :pages do - task 'sync' => ['.git/refs/heads/gh-pages', 'docs/.git/refs/remotes/o'] do |f| - git 'fetch -q o', 'docs' - git 'reset -q --hard o/gh-pages', 'docs' - sh 'touch docs' + # Update the pages/ directory clone + namespace :pages do + task 'sync' => ['.git/refs/heads/gh-pages', 'docs/.git/refs/remotes/o'] do |f| + git 'fetch -q o', 'docs' + git 'reset -q --hard o/gh-pages', 'docs' + sh 'touch docs' + end + + file '.git/refs/heads/gh-pages' => 'docs/' do |f| + unless File.exist? f.name + git 'branch gh-pages --track origin/gh-pages', 'docs' + end + end + + file 'docs/.git/refs/remotes/o' => 'docs/' do |f| + unless File.exist? f.name + git 'init -q docs' + git 'remote add o ../.git', 'docs' + end + end end - file '.git/refs/heads/gh-pages' do |f| - unless File.exist? f.name - git 'branch gh-pages --track origin/gh-pages', 'docs' + CLOBBER.include 'docs/.git' + end + + if cucumber + desc 'Run all cucumber tests' + Cucumber::Rake::Task.new(:features) do |t| + if ENV['CUCUMBER_FORMAT'] + t.cucumber_opts = "features --format #{ENV['CUCUMBER_FORMAT']}" + else + t.cucumber_opts = 'features --format pretty' end end - file 'docs/.git/refs/remotes/o' do |f| - unless File.exist? f.name - git 'init -q docs' - git 'remote add o ../.git', 'docs' + if rcov + desc "Run cucumber tests with RCov" + Cucumber::Rake::Task.new(:features_with_coverage) do |t| + t.cucumber_opts = "features --format pretty" + t.rcov = true + t.rcov_opts = ['--exclude', 'features'] end end end - CLOBBER.include 'docs/.git' + if rspec + require 'rspec/core/rake_task' - desc 'Run all cucumber tests' - Cucumber::Rake::Task.new(:features) do |t| - if ENV['CUCUMBER_FORMAT'] - t.cucumber_opts = "features --format #{ENV['CUCUMBER_FORMAT']}" - else - t.cucumber_opts = 'features --format pretty' + desc "Run all examples" + RSpec::Core::RakeTask.new('examples') do |c| + c.rspec_opts = '-Ispec' end - end - desc "Run all tests with RCov" - Cucumber::Rake::Task.new(:features_with_coverage) do |t| - t.cucumber_opts = "features --format pretty" - t.rcov = true - t.rcov_opts = ['--exclude', 'features'] + if rcov + desc "Run specs with RCov" + RSpec::Core::RakeTask.new(:examples_with_coverage) do |t| + t.rcov = true + t.rcov_opts = ['--exclude', 'spec'] + t.rspec_opts = '-Ispec' + end + end end - task :test => :features - task :default => :test + test_tasks = [] + test_tasks << :examples if rspec + test_tasks << :features if cucumber + unless test_tasks.empty? + task :default => test_tasks.first + task :test => test_tasks + end Rake::RDocTask.new do |rdoc| version = File.exist?('VERSION') ? File.read('VERSION') : "" rdoc.rdoc_dir = 'rdoc'