require 'rubygems'
require 'rake'
require 'rake/rdoctask'
require 'rcov/rcovtask'
require 'date'
require 'rake/gempackagetask'

require 'spec/rake/spectask'
require 'cucumber/rake/task'

desc 'Default: run the specs and features.'
task :default do
  system("rake -s spec:unit;")
  %w(2.1 2.3 3.0).each do |version|
    system("RAILS_VERSION=#{version} rake -s spec:acceptance features;")
  end
end

namespace :spec do
  desc "Run unit specs"
  Spec::Rake::SpecTask.new('unit') do |t|
    t.spec_opts = ['--options', "spec/spec.opts"]
    t.spec_files = FileList['spec/factory_girl/**/*_spec.rb']
  end

  desc "Run acceptance specs"
  Spec::Rake::SpecTask.new('acceptance') do |t|
    t.spec_opts = ['--options', "spec/spec.opts"]
    t.spec_files = FileList['spec/acceptance/**/*_spec.rb']
  end
end

desc "Run the unit and acceptance specs"
task :spec => ['spec:unit', 'spec:acceptance']

desc 'Performs code coverage on the factory_girl plugin.'
Rcov::RcovTask.new do |t|
  t.test_files = FileList['spec/*_spec.rb']
  t.verbose = true
end

desc 'Generate documentation for the factory_girl plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
  rdoc.rdoc_dir = 'rdoc'
  rdoc.title    = 'Factory Girl'
  rdoc.options << '--line-numbers' << "--main" << "README.rdoc"
  rdoc.rdoc_files.include('README.rdoc')
  rdoc.rdoc_files.include('CONTRIBUTION_GUIDELINES.rdoc')
  rdoc.rdoc_files.include('lib/**/*.rb')
end

desc 'Update documentation on website'
task :sync_docs => 'rdoc' do
  `rsync -ave ssh rdoc/ dev@dev.thoughtbot.com:/home/dev/www/dev.thoughtbot.com/factory_girl`
end

desc "Clean files generated by rake tasks"
task :clobber => [:clobber_rdoc, :clobber_rcov]

Cucumber::Rake::Task.new(:features) do |t|
  t.fork = true
  t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
end

eval("$specification = begin; #{IO.read('factory_girl.gemspec')}; end")
Rake::GemPackageTask.new($specification) do |package|
  package.need_zip = true
  package.need_tar = true
end
