-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
105 lines (85 loc) · 2.49 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
94
95
96
97
98
99
100
101
102
103
104
105
require 'bundler/setup'
require 'rake'
require 'rake/testtask'
require 'yard'
require 'rspec'
require 'rspec/core'
require 'rspec/core/rake_task'
Bundler::GemHelper.install_tasks
desc "Run Specs"
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = "spec/**/*_spec.rb"
spec.verbose = true
spec.rspec_opts = ['--color']
end
desc "Generate YARD docs"
YARD::Rake::YardocTask.new(:yard)
namespace :test do
def run_tests(rvm, rails, database)
database_yml = File.dirname(__FILE__) + "/test/config/database.#{database}.yml"
FileUtils.cp(database_yml, 'test/config/database.yml')
puts
puts "============ Ruby #{rvm} - Rails #{rails} - Db #{database} ============="
puts
rvm_script = File.expand_path("~/.rvm/scripts/rvm")
# a bit hackish - source rvm as described here
# https://rvm.beginrescueend.com/workflow/scripting/
sh <<-BASH
source #{rvm_script}
export BUNDLE_GEMFILE=test/config/Gemfile.rails-#{rails}
rvm #{rvm}
bundle install
rake test
BASH
end
desc 'Run the tests in all combinations described in test-matrix.yml'
task :matrix do
# a la travis
require 'yaml'
data = YAML.load(IO.read(File.dirname(__FILE__) + '/test-matrix.yml'))
data['rvm'].each do |rvm|
data['rails'].each do |rails|
data['database'].each do |database|
run_tests(rvm, rails, database)
end
end
end
end
end
task :default => :test
desc 'Test the ETL application.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib' << '.'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
# TODO: reset the database
end
namespace :rcov do
desc 'Measures test coverage'
task :test do
rm_f 'coverage.data'
mkdir 'coverage' unless File.exist?('coverage')
rcov = "rcov --aggregate coverage.data --text-summary -Ilib"
system("#{rcov} test/*_test.rb")
# system("open coverage/index.html") if PLATFORM['darwin']
end
end
desc "Generate code statistics"
task :lines do
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
for file_name in FileList["lib/**/*.rb"]
next if file_name =~ /vendor/
f = File.open(file_name)
while line = f.gets
lines += 1
next if line =~ /^\s*$/
next if line =~ /^\s*#/
codelines += 1
end
puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
total_lines += lines
total_codelines += codelines
lines, codelines = 0, 0
end
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
end