/
Rakefile
154 lines (134 loc) · 4.16 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
require 'jshintrb/jshinttask'
require 'sinatra/activerecord/rake'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'rubocop'
require 'fileutils'
require 'rainbow'
require 'inch/rake'
def cobertura_attrs
require 'ox'
f = File.open 'coverage/javascript/cobertura.xml'
Ox.parse(f.read).root.attributes
end
def verify_js_coverage(line_expected = 0.9, branch_expected = 0.9)
attrs = cobertura_attrs
fail "Line coverage is #{attrs[:'line-rate'].to_f * 100}%, " \
"that don't meet minimum requirements of #{line_expected * 100}%." if attrs[:'line-rate'].to_f < line_expected
fail "Branch coverage is #{attrs[:'branch-rate'].to_f * 100}%, " \
"that don't meet minimum requirements of #{branch_expected * 100}%." if attrs[:'branch-rate'].to_f < branch_expected
end
namespace :spec do
desc 'Run all spec tests at once.'
RSpec::Core::RakeTask.new(:all)
desc 'Run unit spec tests.'
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = [
'spec/unit'
]
end
desc 'Run integration spec tests.'
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = [
'spec/zzz_integration'
]
end
end
namespace :js do
desc 'Install NPM dependencies'
task :install do
sh 'npm install'
end
task :bower_standalone do
Dir.chdir 'lib/puppet-herald/public' do
sh 'bower install -p'
end
Dir.chdir 'test/javascript' do
sh 'bower install'
end
end
task :test_standalone do
FileUtils.rm_rf 'coverage/javascript'
sh 'node_modules/karma/bin/karma start --browsers PhantomJS test/javascript/karma.conf.js'
path = Pathname.glob('coverage/javascript/text.txt').first
puts Rainbow("\nCoverage for Javascript:\n").blue
puts File.read(path)
begin
verify_js_coverage
rescue StandardError => ex
$stderr.puts Rainbow("\n#{ex.message} Write more tests!\n").red.bright
exit 2
end
end
Jshintrb::JshintTask.new :hint do |t|
t.pattern = 'lib/puppet-herald/public/**/*.js'
t.exclude_pattern = 'lib/puppet-herald/public/bower_components/**/*'
t.options = :jshintrc
end
desc 'Install bower JS dependencies.'
task bower: [:'js:install', :'js:bower_standalone']
desc 'Run javascript Jasmine/Karma tests on PhantomJS.'
task test: [:'js:install', :'js:bower', :'js:hint', :'js:test_standalone']
end
namespace :console do
desc 'Start a console with loaded ActiveRecord models on dev database'
task :db do
require 'pry'
require 'puppet-herald'
PuppetHerald.environment = :dev
home = File.expand_path('~')
defaultdb = "sqlite://#{home}/pherald.db"
defaultdbpass = "#{home}/.pherald.pass"
PuppetHerald.database.dbconn = defaultdb
PuppetHerald.database.passfile = defaultdbpass
PuppetHerald.database.spec
require 'puppet-herald/app/configuration'
PuppetHerald::App::Configuration.configure_app(cron: false)
require 'puppet-herald/models/node'
pry
end
end
Inch::Rake::Suggest.new :inch, '--pedantic'
RuboCop::RakeTask.new(:rubocop) do |task|
# don't abort rake on failure
task.fail_on_error = true
end
namespace :rubocop do
namespace :todo do
desc 'Cleans a rubocop TODO list'
task :clean do
File.write('.rubocop_todo.yml', '')
Rake::Task[:rubocop].execute
end
desc 'Saves actual rubocop state into TODO list'
task :save do
rcli = RuboCop::CLI.new
rcli.run ['--auto-gen-config']
end
end
end
desc 'Combine and POST covarage result to coveralls.io'
task :coveralls do
root = File.dirname(File.expand_path(__FILE__))
rlcov = File.read('./coverage/ruby/lcov/gem-puppet-herald.lcov').gsub("#{root}/", './')
File.write('./coverage/ruby/lcov/lcov.info', rlcov)
sh "./node_modules/.bin/lcov-result-merger 'coverage/*/lcov/lcov.info' | ./node_modules/coveralls/bin/coveralls.js"
end
tests = [
:'js:test',
:'spec:all',
:rubocop,
:inch
]
tests << :coveralls if ENV['TRAVIS']
desc 'Run lint, and all spec tests.'
task test: tests
desc 'Installs all dependencies.'
task install: [:'js:install', :'js:bower']
desc 'Build a gem package.'
task :gem do
sh 'gem build puppet-herald.gemspec'
end
desc 'Builds, and test package'
task build: [:install, :test, :gem]
task default: :test