@@ -51,7 +51,6 @@ class Spec < Test
51
51
52
52
module Appium
53
53
# Load appium.txt (toml format)
54
- # the basedir of this file + appium.txt is what's used
55
54
#
56
55
# ```
57
56
# [caps]
@@ -67,17 +66,15 @@ module Appium
67
66
#
68
67
# @param opts [Hash] file: '/path/to/appium.txt', verbose: true
69
68
# @return [hash] the symbolized hash with updated :app and :require keys
70
- def self . load_appium_txt ( opts = { } )
69
+ def self . load_settings ( opts = { } )
71
70
fail 'opts must be a hash' unless opts . is_a? Hash
72
71
fail 'opts must not be empty' if opts . empty?
73
72
74
- file = opts [ :file ]
75
- fail 'Must pass file' unless file
73
+ toml = opts [ :file ]
74
+ fail 'Must pass file' unless toml
76
75
verbose = opts . fetch :verbose , false
77
76
78
- parent_dir = File . dirname file
79
- toml = File . expand_path File . join parent_dir , 'appium.txt'
80
- Appium ::Logger . info "appium.txt path: #{ toml } " if verbose
77
+ Appium ::Logger . info "appium settings path: #{ toml } " if verbose
81
78
82
79
toml_exists = File . exist? toml
83
80
Appium ::Logger . info "Exists? #{ toml_exists } " if verbose
@@ -93,40 +90,47 @@ def self.load_appium_txt(opts = {})
93
90
data [ :caps ] [ :app ] = Appium ::Driver . absolute_app_path data
94
91
end
95
92
96
- # return list of require files as an array
97
- # nil if require doesn't exist
98
93
if data && data [ :appium_lib ] && data [ :appium_lib ] [ :require ]
99
- r = data [ :appium_lib ] [ :require ]
100
- r = r . is_a? ( Array ) ? r : [ r ]
101
- # ensure files are absolute
102
- r . map! do |f |
103
- file = File . exist? ( f ) ? f : File . join ( parent_dir , f )
104
- file = File . expand_path file
105
-
106
- File . exist? ( file ) ? file : nil
107
- end
108
- r . compact! # remove nils
94
+ parent_dir = File . dirname toml
95
+ data [ :appium_lib ] [ :require ] = expand_required_files ( parent_dir , data [ :appium_lib ] [ :require ] )
96
+ end
109
97
110
- files = [ ]
98
+ data
99
+ end
111
100
112
- # now expand dirs
113
- r . each do |item |
114
- unless File . directory? item
115
- # save file
116
- files << item
117
- next # only look inside folders
118
- end
119
- Dir . glob ( File . expand_path ( File . join ( item , '**' , '*.rb' ) ) ) do |f |
120
- # do not add folders to the file list
121
- files << File . expand_path ( f ) unless File . directory? f
122
- end
123
- end
101
+ class << self
102
+ alias_method :load_appium_txt , :load_settings
103
+ end
124
104
125
- # Must not sort files. File order is specified in appium.txt
126
- data [ :appium_lib ] [ :require ] = files
105
+ # @param base_dir [String] parent directory of loaded appium.txt (toml)
106
+ # @param file_paths
107
+ # @return list of require files as an array, nil if require doesn't exist
108
+ def self . expand_required_files ( base_dir , file_paths )
109
+ # ensure files are absolute
110
+ Array ( file_paths ) . map! do |f |
111
+ file = File . exist? ( f ) ? f : File . join ( base_dir , f )
112
+ file = File . expand_path file
113
+
114
+ File . exist? ( file ) ? file : nil
127
115
end
116
+ r . compact! # remove nils
128
117
129
- data
118
+ files = [ ]
119
+
120
+ # now expand dirs
121
+ file_paths . each do |item |
122
+ unless File . directory? item
123
+ # save file
124
+ files << item
125
+ next # only look inside folders
126
+ end
127
+ Dir . glob ( File . expand_path ( File . join ( item , '**' , '*.rb' ) ) ) do |f |
128
+ # do not add folders to the file list
129
+ files << File . expand_path ( f ) unless File . directory? f
130
+ end
131
+ end
132
+
133
+ files
130
134
end
131
135
132
136
# convert all keys (including nested) to symbols
@@ -430,7 +434,7 @@ def self.absolute_app_path(opts)
430
434
return app_path unless app_path . match ( /[\/ \\ ]/ )
431
435
432
436
# relative path that must be expanded.
433
- # absolute_app_path is called from load_appium_txt
437
+ # absolute_app_path is called from load_settings
434
438
# and the txt file path is the base of the app path in that case.
435
439
app_path = File . expand_path app_path
436
440
fail "App doesn't exist #{ app_path } " unless File . exist? app_path
0 commit comments