forked from macdonst/callback-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helpers.rb
56 lines (43 loc) · 1.46 KB
/
spec_helpers.rb
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
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib', 'phonegap')
require 'file_helpers'
require 'fileutils'
class Helper
@@helpers = Object.new.extend(FileHelpers)
def self.create_tmp_directory_assets(reference_filename = nil)
if reference_filename.nil?
directories = { :source => docs_directory, :destination => tmp_docs_directory }
else
directories = find_test_directories(reference_filename)
end
if directories
@@helpers.copy_directory(directories[:source], directories[:destination])
end
directories[:destination]
end
def self.tmp_public_directory
File.join(tmp_directory, 'public')
end
def self.remove_tmp_directory
FileUtils.rm_rf(tmp_directory)
end
private
def self.root_directory
File.expand_path File.dirname(__FILE__)
end
def self.tmp_directory
File.expand_path File.join(root_directory, '..', 'tmp_spec')
end
def self.docs_directory
@@helpers.default_input_directory
end
def self.tmp_docs_directory
File.join(tmp_directory, 'docs')
end
def self.find_test_directories(filename)
source_directory = filename.sub(/#{File.extname(filename)}$/, '')
destination_directory = File.join(tmp_directory, File.basename(source_directory))
return nil unless File.directory?(source_directory)
{ :source => source_directory, :destination => destination_directory }
end
end