unobtainium 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9464c7e860902fed8b6f41813261a19368aea2aa
4
- data.tar.gz: f9498b642d79da6d09cbebd854bda897c6b737d1
3
+ metadata.gz: c5ce28fc39781ca3d3ad6b7116e93f3b194e44d2
4
+ data.tar.gz: 58b285e599f453331bfe7c7382158fa09d591f1e
5
5
  SHA512:
6
- metadata.gz: 07d45f57984c9ffe4d7c12d8fa7a189a6e22e0638a4dab0bed898f423ba73a9ae0f484247d0c23824513bf93f3eedfc32b7e4212e6515d751611c2b1c34eaee7
7
- data.tar.gz: c1378459dc8affa7f5d2a2ce96cfcf5d240b2bf45c83158be0a1d3bf81795ae5024821c99eb3cd3e00617e606cea21c6b43f7ea3eda29b70213a43c5a78f3d30
6
+ metadata.gz: 8e8d24aae8e1143ca3ec5a7d6043968f6c0bc6f1ced20bd35f868bf2c5ca74cc669caada417a58d23509987bdeca92e18abcc92abaa78b37d02cd936c549569f
7
+ data.tar.gz: 4ee5af3d346f55488f65f33929a37cc18a39c6ba42337db2ad25c94fc695d133f72975566d3c9804c5f584dd3d3a5460ce661782db5f3b7a5f72d54925dcabd5
data/.rubocop.yml CHANGED
@@ -24,6 +24,9 @@ Metrics/PerceivedComplexity:
24
24
  Metrics/CyclomaticComplexity:
25
25
  Max: 15
26
26
 
27
+ Metrics/ClassLength:
28
+ Max: 300
29
+
27
30
  # Style
28
31
 
29
32
  Style/StringLiterals:
@@ -61,6 +61,83 @@ module Unobtainium
61
61
  end
62
62
 
63
63
  private :new
64
+
65
+ ##
66
+ # Ensures arguments are according to expectations.
67
+ def sanitize_options(*args)
68
+ if args.empty?
69
+ raise ArgumentError, "Need at least one argument specifying the driver!"
70
+ end
71
+
72
+ label = args[0].to_sym
73
+
74
+ options = nil
75
+ if args.length > 1
76
+ if not args[1].nil? and not args[1].is_a? Hash
77
+ raise ArgumentError, "The second argument is expected to be an "\
78
+ "options hash!"
79
+ end
80
+ options = args[1]
81
+ end
82
+
83
+ # Determine the driver class, if any
84
+ load_drivers
85
+
86
+ driver_klass = get_driver(label)
87
+ if not driver_klass
88
+ raise LoadError, "No driver implementation matching #{@label} found, "\
89
+ "aborting!"
90
+ end
91
+
92
+ # Sanitize options according to the driver's idea
93
+ if driver_klass.respond_to?(:sanitize_options)
94
+ label, options = driver_klass.sanitize_options(label, options)
95
+ end
96
+
97
+ return label, options
98
+ end
99
+
100
+ ##
101
+ # Load drivers; this loads all driver implementations included in this gem.
102
+ # You can register external implementations with the :register_implementation
103
+ # method.
104
+ def load_drivers
105
+ pattern = File.join(File.dirname(__FILE__), 'drivers', '*.rb')
106
+ Dir.glob(pattern).each do |fpath|
107
+ # Determine class name from file name
108
+ fname = File.basename(fpath, '.rb')
109
+ fname = fname.split('_').map(&:capitalize).join
110
+
111
+ begin
112
+ require fpath
113
+ klassname = 'Unobtainium::Drivers::' + fname
114
+ klass = Object.const_get(klassname)
115
+ Driver.register_implementation(klass, fpath)
116
+ rescue LoadError => err
117
+ raise LoadError, "#{err.message}: unknown problem loading driver, "\
118
+ "aborting!"
119
+ rescue NameError => err
120
+ raise LoadError, "#{err.message}: unknown problem loading driver, "\
121
+ "aborting!"
122
+ end
123
+ end
124
+ end
125
+
126
+ ##
127
+ # Out of the loaded drivers, returns the one matching the label (if any)
128
+ def get_driver(label)
129
+ # Of all the loaded classes, choose the first (unsorted) to match the
130
+ # requested driver label
131
+ impl = nil
132
+ @@drivers.keys.each do |klass|
133
+ if klass.matches?(label)
134
+ impl = klass
135
+ break
136
+ end
137
+ end
138
+
139
+ return impl
140
+ end
64
141
  end # class << self
65
142
 
66
143
  ############################################################################
@@ -89,13 +166,14 @@ module Unobtainium
89
166
  # Initializer
90
167
  def initialize(*args)
91
168
  # Load drivers
92
- load_drivers
169
+ ::Unobtainium::Driver.load_drivers
93
170
 
94
171
  # Sanitize options
95
- @label, @options = sanitize_options(*args)
172
+ @label, @options = ::Unobtainium::Driver.sanitize_options(*args)
96
173
 
97
- # Determine the driver class, if any
98
- driver_klass = get_driver(@label)
174
+ # Get the driver class. We kind of know this works because
175
+ # sanitize_options does the same, but let's be strict.
176
+ driver_klass = ::Unobtainium::Driver.get_driver(label)
99
177
  if not driver_klass
100
178
  raise LoadError, "No driver implementation matching #{@label} found, "\
101
179
  "aborting!"
@@ -120,68 +198,5 @@ module Unobtainium
120
198
  :ensure_preconditions,
121
199
  :create
122
200
  ].freeze
123
-
124
- ##
125
- # Ensures arguments are according to expectations.
126
- def sanitize_options(*args)
127
- if args.empty?
128
- raise ArgumentError, "Need at least one argument specifying the driver!"
129
- end
130
-
131
- label = args[0].to_sym
132
-
133
- options = nil
134
- if args.length > 1
135
- if not args[1].nil? and not args[1].is_a? Hash
136
- raise ArgumentError, "The second argument is expected to be an options "\
137
- "hash!"
138
- end
139
- options = args[1]
140
- end
141
-
142
- return label, options
143
- end
144
-
145
- ##
146
- # Load drivers; this loads all driver implementations included in this gem.
147
- # You can register external implementations with the :register_implementation
148
- # method.
149
- def load_drivers
150
- pattern = File.join(File.dirname(__FILE__), 'drivers', '*.rb')
151
- Dir.glob(pattern).each do |fpath|
152
- # Determine class name from file name
153
- fname = File.basename(fpath, '.rb')
154
- fname = fname.split('_').map(&:capitalize).join
155
-
156
- begin
157
- require fpath
158
- klassname = 'Unobtainium::Drivers::' + fname
159
- klass = Object.const_get(klassname)
160
- Driver.register_implementation(klass, fpath)
161
- rescue LoadError => err
162
- raise LoadError, "#{err.message}: unknown problem loading driver, "\
163
- "aborting!"
164
- rescue NameError => err
165
- raise LoadError, "#{err.message}: unknown problem loading driver, "\
166
- "aborting!"
167
- end
168
- end
169
- end
170
-
171
- ##
172
- # Out of the loaded drivers, returns the one matching the label (if any)
173
- def get_driver(label)
174
- # Of all the loaded classes, choose the first (unsorted) to match the
175
- # requested driver label
176
- impl = nil
177
- @@drivers.keys.each do |klass|
178
- if klass.matches?(label)
179
- impl = klass
180
- break
181
- end
182
- end
183
-
184
- return impl
185
- end
186
201
  end # class Driver
187
202
  end # module Unobtainium
@@ -49,8 +49,8 @@ module Unobtainium
49
49
  end
50
50
 
51
51
  ##
52
- # Create and return a driver instance
53
- def create(label, options)
52
+ # Sanitize options, and expand the :browser key, if present.
53
+ def sanitize_options(label, options)
54
54
  # The label specifies the platform, if no other platform is given.
55
55
  normalized = normalize_label(label)
56
56
 
@@ -69,6 +69,14 @@ module Unobtainium
69
69
  # some information
70
70
  options = supplement_browser(options)
71
71
 
72
+ return label, options
73
+ end
74
+
75
+ ##
76
+ # Create and return a driver instance
77
+ def create(label, options)
78
+ _, options = sanitize_options(label, options)
79
+
72
80
  # Create the driver
73
81
  driver = ::Appium::Driver.new(options).start_driver
74
82
  return driver
@@ -106,6 +114,9 @@ module Unobtainium
106
114
  return options
107
115
  end
108
116
 
117
+ # We have data, so we can remove the browser key itself
118
+ options.delete('browser')
119
+
109
120
  # We do have to check that we're not overwriting any of the keys.
110
121
  data.keys.each do |key|
111
122
  key_s = key.to_s
@@ -114,7 +125,7 @@ module Unobtainium
114
125
  end
115
126
  raise ArgumentError, "You specified the browser option as, "\
116
127
  "'#{options['browser']}', but you also have the key "\
117
- "'#{key}' set in your requested capabilities. Use one or the"\
128
+ "'#{key}' set in your requested capabilities. Use one or the "\
118
129
  "other."
119
130
  end
120
131
 
@@ -7,5 +7,5 @@
7
7
  # All rights reserved.
8
8
  #
9
9
  module Unobtainium
10
- VERSION = "0.1.0".freeze
10
+ VERSION = "0.1.1".freeze
11
11
  end
@@ -53,6 +53,10 @@ module Unobtainium
53
53
  options = config["drivers.#{label}"]
54
54
  end
55
55
 
56
+ # The driver may modify the options; if so, we should let it do that
57
+ # here. That way our key (below) is based on the expanded options.
58
+ label, options = ::Unobtainium::Driver.sanitize_options(label, options)
59
+
56
60
  # Create a key for the label and options. This should always
57
61
  # return the same key for the same label and options.
58
62
  key = { label: label, options: options }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unobtainium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Finkhaeuser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler