forked from exercism/website-copy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
59 lines (49 loc) · 1.46 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
require "rake/testtask"
desc "Run the tests"
task :test do
errors = []
require 'json'
Dir['mentors/**/*.json'].each do |file|
begin
mentors = JSON.parse(File.read(file))
next if mentors.empty?
if mentors.is_a?(Hash)
errors << "JSON should be an array of mentors, not a JSON object in %s." % file
next
end
mentors.each do |mentor|
username = mentor["github_username"]
name = mentor["name"]
if name == "" || name.nil?
errors << "Name can't be blank for %s in %s." % [username, file]
next
end
url = mentor["link_url"]
next if url.nil? || url.empty?
if url.strip == "null"
errors << "Link URL should be null, not the string 'null' for %s in %s." % [username, file]
next
end
if url.strip != url
errors << "Link URL has extraneous whitespace for %s in %s." % [username, file]
next
end
if url !~ /^https?/
errors << "Link URL must have HTTP protocol for %s in %s." % [username, file]
end
if mentor["link_text"].to_s.include?("Github")
errors << "GitHub should be spelled with an uppercase 'H' for %s in %s." % [username, file]
end
end
rescue
errors << "Invalid JSON in: %s" % file
end
end
unless errors.empty?
errors.each do |error|
STDERR.puts "- %s" % error
end
exit 1
end
end
task :default => :test