File: Rakefile

package info (click to toggle)
ruby-em-mongo 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 320 kB
  • sloc: ruby: 2,728; makefile: 2
file content (131 lines) | stat: -rw-r--r-- 3,276 bytes parent folder | download | duplicates (3)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

require 'fileutils'
require 'tmpdir'

def em_mongo_version
  File.read("VERSION").strip
end

def root_dir
  File.dirname(__FILE__)
end

task :default => 'spec:integration:default'

class MongoRunner
  def self.run(options={}) 
    auth = "--auth" if options[:auth]
    dir = Dir.tmpdir + "/em-mongo-tests-#$$"
    FileUtils.mkdir dir
    pidf = "#{dir}/mongod.pid"
    logf = "#{dir}/mongo.log"
    begin
      system "mongod run #{auth} --fork -vvvvvvv --dbpath #{dir} --pidfilepath #{pidf} --logpath #{logf} >> /dev/null "
      yield if block_given?
    ensure
      if File.exists?(pidf) and File.read(pidf).to_i != 0
        Process.kill("KILL", File.read(pidf).to_i)
        FileUtils.rm_r dir unless options[:noclean]
      end
    end
  end
end

spec = eval(File.read('em-mongo.gemspec'))

namespace :bundle do
  task :install do
    if `bundle check` =~ /bundle install/
      system("bundle install --path vendor/gems")
    end
  end
end

namespace :gem do

  desc "build gem"
  task :build do
    puts "Building em-mongo #{em_mongo_version}"
    system "gem build em-mongo.gemspec -q"
  end

  desc "release gem"
  task :release do
    system "gem push em-mongo-#{em_mongo_version}.gem"
  end

end

namespace :spec do
  
  namespace :gem do

    desc "bundler tests"
    task :bundler do
      MongoRunner.run do
        print "Testing Bundler integration ... "
        if system "cd spec/gem && bundle install --quiet && ./bundler.rb"
          puts "SUCCESS."
        else
          puts "FAILURE."
        end
      end
    end

    desc "rubygems tests"
    task :rubygems do
      MongoRunner.run do
        print "Testing Rubygems integration ... "
        steps =[]
        steps << "cd spec/gem"
        
        if `gem list -i em-mongo` == 'true'
          steps << "gem uninstall --force -a em-mongo >/dev/null"
        end
        steps << "gem install #{root_dir}/em-mongo-#{em_mongo_version}.gem >/dev/null "
        steps << "./rubygems.rb"
        if system steps.join(" && ")
          puts "SUCCESS."
        else
          puts "FAILURE."
        end
      end
    end

    desc "all gem tests"
    task :all => [:bundler, :rubygems]
  end

  namespace :integration do

    desc "default tests"
    task :default => ['bundle:install'] do
      MongoRunner.run do
        files = spec.test_files.select{|x| x =~ /integration/}.join(' ')
        system "bundle exec spec #{files} -t -b -fs -color"
      end
    end

    desc "exhaustive tests"
    task :exhaustive => ['bundle:install'] do
      MongoRunner.run({:noclean => true}) do
        files = spec.test_files.select{|x| x =~ /integration/}.join(' ')
        system "bundle exec spec #{files} -t -b -fs -color"
      end
      MongoRunner.run({:auth => true}) do
        files = spec.test_files.select{|x| x =~ /integration/}.join(' ')
        system "bundle exec spec #{files} -t -b -fs -color"
      end
    end

    desc "default tests, but don't start mongodb for me"
    task :no_mongo => ['bundle:install'] do
      files = spec.test_files.select{|x| x =~ /integration/}.join(' ')
      system "bundle exec spec #{files} -t -b -fs -color"
    end

  end

  desc "release testing"
  task :release => ['spec:integration:default','gem:build','spec:gem:bundler','spec:gem:rubygems']
end