forked from collectiveidea/graticule
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
94 lines (80 loc) · 2.34 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
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
# require 'rubygems'
require 'bundler/setup'
require 'graticule/version'
require 'active_support'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rcov/rcovtask'
desc 'Default: run unit tests.'
task :default => :test
task :build do
system "gem build graticule.gemspec"
end
task :release => :build do
system "gem push graticule-#{Graticule::VERSION}.gem"
end
task :install => :build do
system "gem install graticule-#{Graticule::VERSION}.gem"
end
desc 'Run the unit tests'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib' << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentatio'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Graticule'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README.txt')
rdoc.rdoc_files.include('lib/**/*.rb')
end
namespace :test do
desc "just rcov minus html output"
Rcov::RcovTask.new(:coverage) do |t|
# t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.output_dir = 'coverage'
t.verbose = true
t.rcov_opts = %w(--exclude test,/usr/lib/ruby,/Library/Ruby,$HOME/.gem --sort coverage)
end
end
require 'active_support'
require 'net/http'
require 'uri'
RESPONSES_PATH = File.dirname(__FILE__) + '/test/fixtures/responses'
def cache_responses(service)
test_config[service.to_s]['responses'].each do |file,url|
File.open("#{RESPONSES_PATH}/#{service}/#{file}", 'w') do |f|
f.puts Net::HTTP.get(URI.parse(url))
end
end
end
def test_config
file = File.dirname(__FILE__) + '/test/config.yml'
raise "Copy config.yml.default to config.yml and set the API keys" unless File.exists?(file)
@test_config ||= YAML.load(File.read(file)).tap do |config|
config.each do |service,values|
values['responses'].each {|f,url| update_placeholders!(values, url) }
end
end
end
def update_placeholders!(config, thing)
config.each do |option, value|
thing.gsub!(":#{option}", value) if value.is_a?(String)
end
end
namespace :test do
namespace :cache do
desc 'Cache test responses from all the geocoders'
task :all => test_config.keys
test_config.keys.each do |service|
desc "Cache test responses for #{service}"
task service do
cache_responses(service)
end
end
end
end