require 'spec/rake/spectask'

task :default => :spec

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

desc 'Run the specs with autotest'
task :autotest do
  ENV['RSPEC'] = 'true'
  sh 'autotest'
end

desc 'Start an IRB session with the library loaded'
task :console do
  sh "irb -I ./lib -r 'httpattack'"
end


#
# Gem Stuff
#
APP_DIR = File.dirname(__FILE__)
GEMSPEC = File.join(APP_DIR, 'httpattack-lib.gemspec')
GEMNAME = File.basename(GEMSPEC, '.gemspec')

desc 'Build the gem'
task :gem => ['gem:build']

namespace :gem do
  task :build do
    sh "gem build #{GEMSPEC}"
  end

  desc "Clean the built gem"
  task :clean do
    sh "rm -f #{APP_DIR}/*.gem"
  end

  desc 'Clean, rebuild and install the gem'
  task :install do
    Rake::Task['gem:clean'].invoke
    Rake::Task['gem:build'].invoke
    gem = FileList["#{APP_DIR}/#{GEMNAME}-*.gem"].first
    sh "gem uninstall #{GEMNAME} ; gem install #{gem}"
  end
end
