aboutsummaryrefslogtreecommitdiffstats
path: root/Rakefile
blob: a6f80222c85c835f7ea738cc0d89d95f8f09a3d5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require "rubygems"

def gemspec
  @gemspec ||= begin
    gemspec_file = File.expand_path('../arel.gemspec', __FILE__)
    gemspec = eval(File.read(gemspec_file), binding, gemspec_file)
  end
end

begin
  require "spec/rake/spectask"
rescue LoadError
  desc "Run specs"
  task(:spec) { $stderr.puts '`gem install rspec` to run specs' }
else
  desc "Run specs using RCov (uses mysql database adapter)"
  Spec::Rake::SpecTask.new(:coverage) do |t|
    t.spec_files =
      ["spec/connections/mysql_connection.rb"] +
      FileList['spec/**/*_spec.rb']

    t.rcov = true
    t.rcov_opts << '--exclude' << "spec,gems"
    t.rcov_opts << '--text-summary'
    t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
    t.rcov_opts << '--only-uncovered'
  end

  namespace :spec do
    %w[mysql sqlite3 postgresql oracle].each do |adapter|
      task "set_env_for_#{adapter}" do
        ENV['ADAPTER'] = adapter
      end

      Spec::Rake::SpecTask.new(adapter) do |t|
        t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
        t.libs << "#{File.dirname(__FILE__)}/spec"
        # t.warning = true
        t.spec_files = FileList['spec/**/*_spec.rb']
      end

      desc "Run specs with the #{adapter} database adapter"
      task adapter => "set_env_for_#{adapter}"

      namespace :v1 do
        Spec::Rake::SpecTask.new(adapter) do |t|
          t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
          t.libs << "#{File.dirname(__FILE__)}/spec"
          t.warning    = true
          t.spec_files = FileList['spec/arel/**/*_spec.rb']
        end

        desc "Run specs with the #{adapter} database adapter"
        task adapter => "set_env_for_#{adapter}"
      end
    end
  end

  desc "Run specs with mysql and sqlite3 database adapters (default)"
  task :spec => ["spec:sqlite3", "spec:mysql", "spec:postgresql"]

  desc "Default task is to run specs"
  task :default => :spec
end

desc 'Removes trailing whitespace'
task :whitespace do
  sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
end

desc "Build pkg/#{gemspec.full_name}.gem"
task :build => "gemspec:validate" do
  sh %{gem build arel.gemspec}
  FileUtils.mkdir_p "pkg"
  FileUtils.mv gemspec.file_name, "pkg"
end

desc "Install the latest built gem"
task :install => :build do
  sh "gem install --local pkg/#{gemspec.file_name}"
end

namespace :release do
  task :tag do
    release_tag = "v#{gemspec.version}"
    sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'"
    sh "git push origin #{release_tag}"
  end

  task :gem => :build do
    sh "gem push pkg/#{gemspec.file_name}"
  end
end

desc "Release the current branch to GitHub and Gemcutter"
task :release => %w(release:tag release:gem)

namespace :gemspec do
  desc 'Validate the gemspec'
  task :validate do
    gemspec.validate
  end
end