-
Notifications
You must be signed in to change notification settings - Fork 45
/
Rakefile
177 lines (166 loc) · 4.73 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# encoding: utf-8
require 'bundler'
Bundler::GemHelper.install_tasks
# Rake::Task['release'].enhance([:test, :release_js]) FIXME, this just doesn't work.
task :default => [:test]
task :release_js do
$: << 'lib'
require 'http_router/version'
File.open('js/package.json', 'w') do |f|
f << <<-EOT
{
"name": "http_router",
"description": "URL routing and generation in js",
"author": "Joshua Hull <[email protected]>",
"version": "#{HttpRouter::VERSION}",
"directories": {
"lib" : "./lib/http_router"
},
"main": "lib/http_router"
}
EOT
end
sh "cd js && npm publish"
`git commit js/package.json -m'bumped js version'`
end
test_tasks = ['test:generation', 'test:recognition', 'test:integration', 'test:examples', 'test:rdoc_examples']
#test_tasks << 'test:js' if `which coffee && which node` && $?.success?
desc "Run all tests"
task :test => test_tasks
desc "Clean things"
task :clean do
sh 'find . -name "*.rbc" | xargs rm'
sh 'rm -rf pkg'
end
namespace :test do
desc "Run integration tests"
task :integration do
$: << 'lib'
require 'http_router'
require './test/helper'
Dir['./test/**/test_*.rb'].each { |test| require test }
end
desc "Run js tests"
task :js do
sh "coffee -c js/test/test.coffee"
sh "coffee -c js/lib/http_router.coffee"
sh "node js/test/test.js"
end
desc "Run generic recognition tests"
task :recognition do
$: << 'lib'
require 'http_router'
require './test/recognition'
end
desc "Run generic recognition tests"
task :generation do
$: << 'lib'
require 'http_router'
require './test/generation'
end
desc "Run example tests"
task :examples do
$: << 'lib'
require 'http_router'
require 'thin'
Dir['./examples/**/*.ru'].each do |example|
print "running example #{example}..."
comments = File.read(example).split(/\n/).select{|l| l[0] == ?#}
pid = nil
Thin::Logging.silent = true
begin
pid = fork {
code = "Proc.new { \n#{File.read(example)}\n }"
r = eval(code, binding, example, 2)
Thin::Server.start(:signals => false, &r)
}
sleep 0.5
out = nil
assertion_count = 0
comments.each do |c|
c.gsub!(/^# ?/, '')
case c
when /^\$/
out = `#{c[1, c.size]} 2>/dev/null`.split(/\n/)
raise "#{c} produced #{`#{c[1, c.size]} 2>&1`}" unless $?.success?
when /^=> ?(.*)/
c = $1
raise "out was nil" if out.nil?
test = out.shift
if c['Last-Modified'] == test['Last-Modified']
assertion_count += 1
else
raise "expected #{c.inspect}, received #{test.inspect}" unless c.strip == test.strip
assertion_count += 1
end
end
end
raise "no assertions were raised in #{example}" if assertion_count.zero?
puts "✔"
ensure
Process.kill('HUP', pid) if pid
end
end
end
desc "rdoc examples"
task :rdoc_examples do
$: << 'lib'
require 'http_router'
in_example = false
examples = []
STDOUT.sync = true
current_example = ''
rb_files = Dir['./lib/**/*.rb']
puts "Scanning #{rb_files * ', '}"
rb_files.each do |file|
lines = File.read(file).split(/\n/)
lines.each do |line|
if line[/^\s*#(.*)/] # comment
line = $1.strip
case line
when /^example:/i then in_example = true
when /^(?:# )?=+> (.*)/
expected = $1.strip
msg = expected.dup
msg << " was expected to be "
msg << "\#{__example_runner.inspect}"
current_example << "raise \"#{msg.gsub('"', '\\"')}\" unless (__example_runner.respond_to?(:strip) ? __example_runner.strip : __example_runner) == #{expected}\n" if in_example
when ''
unless current_example.empty?
examples << current_example
current_example = ''
end
in_example = false
else
current_example << "__example_runner = (" << line << ")\n" if in_example
end
else
unless current_example.empty?
examples << current_example
current_example = ''
end
in_example = false
end
end
end
puts "Running #{examples.size} example#{'s' if examples.size != 1}"
examples.each do |example|
print "."
eval(example)
end
puts " ✔"
end
end
begin
require 'rake/rdoctask'
rescue
require 'rdoc/task'
end
desc "Generate documentation"
Rake::RDocTask.new do |rd|
rd.main = "README.md"
rd.rdoc_files.include("README.md", "lib/**/*.rb")
rd.rdoc_dir = 'rdoc'
end
require 'code_stats'
CodeStats::Tasks.new