-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
51 lines (45 loc) · 1.31 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
require 'JSON'
require 'faraday'
require 'colorize'
desc "Output JSON of challenge paths"
task :generate_challenge_paths do
list = []
Dir['source/tingkat/*'].each do |path1|
Dir[path1 + '/*'].each do |path2|
list << (path2.split('source/tingkat/').last.split('.md').first)
end
end
File.open('source/challenge_paths.json', 'w') do |f|
f.write JSON.generate challenge_paths: list
end
end
desc "Make sure all challenge pages returns 200 success"
task test_success: [:generate_challenge_paths] do
conn = Faraday.new(url: "http://localhost:4567") do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
end
json = JSON.parse File.read "source/challenge_paths.json"
all_paths = json["challenge_paths"] || []
paths_with_error = []
all_paths.each do |path|
full_path = "/tingkat/" + path + ".html"
response = conn.get full_path
if response.status.to_i == 200
print '.'.green
else
print 'F'.red
end
end
puts
bad_count = paths_with_error.size
puts "#{all_paths.size - bad_count} Good Pages, #{bad_count} Bad Pages"
puts
unless paths_with_error.empty?
puts "Paths with error:"
paths_with_error.each do |path|
puts path
end
puts
end
end