Add Rake task to fetch ace_modes, and skip test if there's no internet

This commit is contained in:
Garen Torikian
2014-11-28 11:48:26 -08:00
parent 26ab33754f
commit 1d4149168d
3 changed files with 29 additions and 3 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ benchmark/
lib/linguist/samples.json
/grammars
/node_modules
test/fixtures/ace_modes.json

View File

@@ -3,13 +3,15 @@ require 'rake/clean'
require 'rake/testtask'
require 'yaml'
require 'yajl'
require 'open-uri'
require 'json'
task :default => :test
Rake::TestTask.new
# Extend test task to check for samples
task :test => :check_samples
# Extend test task to check for samples and fetch latest Ace modes
task :test => [:check_samples, :fetch_ace_modes]
desc "Check that we have samples.json generated"
task :check_samples do
@@ -18,6 +20,26 @@ task :check_samples do
end
end
desc "Fetch the latest Ace modes from its GitHub repository"
task :fetch_ace_modes do
ACE_FIXTURE_PATH = File.join('test', 'fixtures', 'ace_modes.json')
File.delete(ACE_FIXTURE_PATH) if File.exist?(ACE_FIXTURE_PATH)
begin
ace_github_modes = (open("https://api.github.com/repos/ajaxorg/ace/contents/lib/ace/mode").read)
File.write(ACE_FIXTURE_PATH, ace_github_modes)
rescue => e
case e
when OpenURI::HTTPError
when SocketError
# no internet? no problem.
else
raise e
end
end
end
task :samples do
require 'linguist/samples'
json = Yajl.dump(Linguist::Samples.data, :pretty => true)

View File

@@ -371,7 +371,10 @@ class TestLanguage < Test::Unit::TestCase
end
def test_all_languages_have_a_valid_ace_mode
ace_github_modes = JSON.parse `curl https://api.github.com/repos/ajaxorg/ace/contents/lib/ace/mode`
ace_fixture_path = File.join('test', 'fixtures', 'ace_modes.json')
skip("No ace_modes.json file") unless File.exist?(ace_fixture_path)
ace_github_modes = JSON.parse(File.read(ace_fixture_path))
existing_ace_modes = ace_github_modes.map do |ace_github_mode|
File.basename(ace_github_mode["name"], ".js") if ace_github_mode["name"] !~ /_highlight_rules|_test|_worker/
end.compact.uniq.sort.map(&:downcase)