-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
126 lines (103 loc) · 3.23 KB
/
Rakefile
File metadata and controls
126 lines (103 loc) · 3.23 KB
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
require "rake/clean"
task :default => :spec
backends = Dir.glob('lib/monkey/backend/*.rb').map { |f| File.basename f, ".rb" }
modes = [:autodetect, :explicit]
CLEAN.include "**/*.rbc"
CLOBBER.include "monkey-lib*.gem"
setup_rspec = proc do
require "spec/rake/spectask"
SPEC_RUNNER = "mspec"
def define_spec_task(name, ruby_cmd, pattern)
Spec::Rake::SpecTask.new name do |t|
t.spec_opts += %w[-b -c --format progress --loadby mtime --reverse]
t.ruby_cmd = ruby_cmd
t.pattern = pattern
end
end
end
setup_mspec = proc do
require "mspec"
SPEC_RUNNER = "mspec"
def define_spec_task(name, ruby_cmd, pattern)
task(name) { sh "#{ruby_cmd} -S mspec-run #{pattern}" }
end
end
case ENV['SPEC_RUNNER']
when "rspec" then setup_rspec.call
when "mspec" then setup_mspec.call
when nil
# yes, this code is trying to be smart, but let me have some fun, please?
raise @spec_load_error unless [setup_rspec, setup_mspec].any? { |b| b.call || true rescue (@spec_load_error ||= $!) && false }
else
puts "sorry, currently no #{ENV['SPEC_RUNNER']} support"
exit 1
end
def backend_available?(backend = nil)
require backend unless backend.nil?
true
rescue LoadError
false
end
def spec_task(name, backend = nil, mode = nil)
desc "runs specs #{"with backend #{backend} " if backend}#{"(#{mode} mode)" if mode}"
if backend_available? backend
define_spec_task(name, "BACKEND=#{backend.to_s.inspect} BACKEND_SETUP=#{mode.to_s.inspect} #{ENV['RUBY'] || RUBY}", "spec/**/*_spec.rb")
else
task(name) do
puts "", "could not load #{backend.inspect}, skipping specs.", ""
end
end
end
task :environment do
$LOAD_PATH.unshift "lib"
require "monkey-lib"
end
desc "run all specs"
task :spec => "spec:all"
namespace :spec do
desc "runs specs without explicitly setting a backend"
spec_task :autodetect
backends.each do |backend|
task :all => backend
desc "runs specs with backend #{backend}"
task backend => "#{backend}:all"
namespace backend do
modes.each do |mode|
task :all => mode
spec_task mode, backend, mode
end
end
end
end
namespace :backend do
desc "lists all available backends"
task(:list) { puts backends }
desc "lists expectations a backend has to meet"
task :expectations => :environment do
Monkey::Ext.expectations.each do |core_class, methods|
print "#{core_class}:".ljust(10)
puts methods.map { |n| "##{n}" }.join(", ")
end
end
desc "checks whether specs for expectations are present"
task :spec_check =>:environment do
Monkey::Ext.expectations.each do |core_class, methods|
path = "spec/monkey/ext/#{core_class.name.to_const_path}_spec.rb"
list = path.file_exists? ? %x[spec -d -fs #{path} -e "Monkey::Ext::#{core_class.name} backend expectations"] : ""
methods.each { |m| puts "missing specs for #{core_class.name}##{m}" unless list =~ /- imports #{m} from backend/ }
end
end
end
############
# aliases
namespace(:b) do
task :e => "backend:expectations"
task :l => "backend:list"
task :s => "backend:spec_check"
end
namespace(:s) do
task :as => "spec:active_support:explicit"
task :bp => "spec:backports:explicit"
task :ex => "spec:extlib:explicit"
task :fc => "spec:facets:explicit"
end