-
Notifications
You must be signed in to change notification settings - Fork 350
/
Rakefile
104 lines (82 loc) · 2.55 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
# Bootstrap
#-----------------------------------------------------------------------------#
desc 'Initializes your working copy to run the specs'
task :bootstrap do
puts 'Updating submodules...'
`git submodule update --init --recursive`
if system('which bundle')
puts 'Installing gems'
`bundle install`
else
$stderr.puts "\033[0;31m" \
"[!] Please install the bundler gem manually:\n" \
' $ [sudo] gem install bundler' \
"\e[0m"
exit 1
end
end
begin
require 'bundler/gem_tasks'
# Travis support
#-----------------------------------------------------------------------------#
def rvm_ruby_dir
@rvm_ruby_dir ||= File.expand_path('../..', `which ruby`.strip)
end
namespace :travis do
task :setup do
sh 'git submodule update --init'
sh "env CFLAGS='-I#{rvm_ruby_dir}/include' bundle install --without debugging documentation"
end
end
# Spec
#-----------------------------------------------------------------------------#
namespace :spec do
def specs(dir)
FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
end
desc 'Automatically run specs for updated files'
task :kick do
exec 'bundle exec kicker -c'
end
task :all do
title 'Running Unit Tests'
sh "bundle exec bacon #{specs('**')}"
title 'Checking code style...'
Rake::Task['rubocop'].invoke if RUBY_VERSION >= '1.9.3'
end
end
desc 'Run all specs'
task :spec => 'spec:all'
# Coverage
#-----------------------------------------------------------------------------#
desc 'Generates & opens the coverage report'
task :coverage do
title 'Generating Coverage Report'
sh "env GENERATE_COVERAGE=true bundle exec bacon --quiet #{specs('**')}"
title 'Opening Report'
puts 'Coverage report available at `coverage/index.html`'
sh 'open coverage/index.html'
end
#-- RuboCop ----------------------------------------------------------------#
if RUBY_VERSION >= '1.9.3'
require 'rubocop/rake_task'
RuboCop::RakeTask.new
end
#---------------------------------------------------------------------------#
task :default => :spec
rescue LoadError
$stderr.puts "\033[0;31m" \
'[!] Some Rake tasks haven been disabled because the environment' \
' couldn’t be loaded. Be sure to run `rake bootstrap` first.' \
"\e[0m"
end
# Helpers
#-----------------------------------------------------------------------------#
def title(title)
cyan_title = "\033[0;36m#{title}\033[0m"
puts
puts '-' * 80
puts cyan_title
puts '-' * 80
puts
end