forked from ryanfitz/mongo_session_store
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Rakefile
93 lines (80 loc) · 2.99 KB
/
Rakefile
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
require 'rubygems'
require 'rake'
require 'bundler'
Bundler::GemHelper.install_tasks :name => 'mongo_session_store-rails4'
def run_with_output(command)
puts "Running: #{command}"
system(command)
end
def set_versions(rails_vers, orm)
success = true
unless File.exists?("Gemfile_Rails_#{rails_vers}_#{orm}_#{RUBY_VERSION}.lock")
success &&= run_with_output("export RAILS_VERS=#{rails_vers}; export MONGO_SESSION_STORE_ORM=#{orm}; bundle update")
success &&= run_with_output("cp Gemfile.lock Gemfile_Rails_#{rails_vers}_#{orm}_#{RUBY_VERSION}.lock")
else
success &&= run_with_output("rm Gemfile.lock")
success &&= run_with_output("cp Gemfile_Rails_#{rails_vers}_#{orm}_#{RUBY_VERSION}.lock Gemfile.lock")
end
success
end
@rails_versions = ['3.1', '3.2', '4.0', '4.1', '4.2']
@orms = ['mongo_mapper', 'mongoid', 'mongo']
task :default => :test_all
desc 'Test each session store against Rails 3.1, 3.2, 4.0, 4.1, and 4.2'
task :test_all do
# inspired by http://pivotallabs.com/users/jdean/blog/articles/1728-testing-your-gem-against-multiple-rubies-and-rails-versions-with-rvm
# Wait for mongod to start on Travis.
# From the Mongo Ruby Driver gem.
if ENV['TRAVIS']
require 'mongo'
client = Mongo::Client.new(['127.0.0.1:27017'])
begin
puts "Waiting for MongoDB..."
client.command(Mongo::Server::Monitor::STATUS)
rescue Mongo::ServerSelector::NoServerAvailable => e
sleep(2)
# 1 Retry
puts "Waiting for MongoDB..."
client.cluster.scan!
client.command(Mongo::ServerSelector::NoServerAvailable)
end
end
@failed_suites = []
@rails_versions.each do |rails_version|
@orms.each do |orm|
success = set_versions(rails_version, orm)
unless success && run_with_output("export RAILS_VERS=#{rails_version}; export MONGO_SESSION_STORE_ORM=#{orm}; bundle exec rspec spec")
@failed_suites << "Rails #{rails_version} / #{orm}"
end
end
end
if @failed_suites.any?
puts "\033[0;31mFailed:"
puts @failed_suites.join("\n")
print "\033[0m"
exit(1)
else
print "\033[0;32mAll passed! Success! "
"Yahoooo!!!".chars.each { |c| sleep 0.4; print c; STDOUT.flush }
puts "\033[0m"
end
end
@rails_versions.each do |rails_version|
@orms.each do |orm|
desc "Set Gemfile.lock to #{rails_version} with #{orm}"
task :"use_#{rails_version.gsub('.', '')}_#{orm}" do
set_versions(rails_version, orm)
end
desc "Test against #{rails_version} with #{orm}"
task :"test_#{rails_version.gsub('.', '')}_#{orm}" do
set_versions(rails_version, orm)
success = run_with_output("export RAILS_VERS=#{rails_version}; export MONGO_SESSION_STORE_ORM=#{orm}; bundle exec rspec spec")
exit(1) unless success
end
desc "Rebundle for #{rails_version} with #{orm}"
task :"rebundle_#{rails_version.gsub('.', '')}_#{orm}" do
run_with_output "rm Gemfile_Rails_#{rails_version}_#{orm}_#{RUBY_VERSION}.lock Gemfile.lock"
set_versions(rails_version, orm)
end
end
end