forked from rtweeks/baby_squeel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
85 lines (72 loc) · 1.94 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
require 'yaml'
require 'open3'
require 'filewatcher'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'coveralls/rake/task'
require 'bump/tasks'
Coveralls::RakeTask.new
RSpec::Core::RakeTask.new(:spec)
def invoke(env, cmd)
Bundler.with_clean_env do
system({ 'SKIPCOV' => '1' }.merge(env), cmd)
end
end
def format_version(env, failed: false)
vars = env.map { |k, v| "#{k}=#{v}" }
msg = "=== #{vars.join(' ')} "
msg << 'failed ' if failed
msg << '=' * (80 - msg.length)
end
def bundle_install(env)
FileUtils.rm_rf 'Gemfile.lock'
invoke env, 'bundle check --quiet > /dev/null || bundle install --quiet'
end
def version_passes?(env)
puts format_version(env)
bundle_install(env)
invoke env, 'bundle exec rspec -f progress' if $?.success?
$?.success?
end
desc 'Switch ActiveRecord version'
task :switch, [:version] do |_, args|
abort 'No version specified.' unless args[:version]
bundle_install 'AR' => args[:version]
puts "export AR=#{args[:version]}"
end
desc 'Run against all ActiveRecord versions'
task 'spec:matrix' do
travis = YAML.load_file '.travis.yml'
envs = travis['env']['matrix'].map do |build|
Hash[build.split(/=|\s+/).each_slice(2).to_a]
end
envs.each do |env|
unless version_passes? env
abort format_version(env, failed: true)
end
end
end
desc 'Watch for changes and rerun specs'
task 'spec:watch' do
puts 'Watching...'
Filewatcher.new(['lib', 'spec']).watch do |filename|
Bundler.with_clean_env do
if filename =~ /_spec\.rb$/
system "bundle exec rspec #{filename}"
else
system 'bundle exec rspec'
end
end
end
end
Bump::Bump::BUMPS.each do |bump|
desc "Increment #{bump} and release"
task "release:#{bump}" => "bump:#{bump}" do
# we can't just run this as a prereq, because gem_tasks
# loads the version when rake loads
Bundler.with_clean_env do
sh 'bundle exec rake release'
end
end
end
task default: :spec