unobtainium 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -6
- data/features/step_definitions/steps.rb +45 -0
- data/features/world.feature +13 -0
- data/lib/unobtainium/version.rb +1 -1
- data/lib/unobtainium/world.rb +58 -26
- data/spec/driver_spec.rb +2 -4
- data/spec/drivers_phantom_spec.rb +10 -0
- data/spec/mock_driver.rb +2 -0
- data/unobtainium.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a47708be130d105fbf6be7bbdd7f00406882929
|
4
|
+
data.tar.gz: 81128ec3068eb4e880c7b314e6c7cd2e3d7d6c3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ffd14ee0d6b4958e4238a437530726e3ed18d278f8ff462db70d2a58b63f7e2423bee73aa958358fcccd85fd2f673f389d34dceab480464b6d94a0c420305c3
|
7
|
+
data.tar.gz: be670c898c0fff253dc79bd3e8ff3841d44ebac6e7b494d6a6d9a7e873c545acb8e32d8a2b0477f4e99b840f6bf31d139a148dc2f44c32ca3bdeb22b82bf0e26
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
unobtainium (0.
|
4
|
+
unobtainium (0.10.0)
|
5
5
|
collapsium (~> 0.8)
|
6
6
|
collapsium-config (~> 0.4)
|
7
7
|
ptools (~> 1.3)
|
@@ -10,7 +10,7 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
appium_lib (8.1
|
13
|
+
appium_lib (8.2.1)
|
14
14
|
awesome_print (~> 1.6)
|
15
15
|
json (~> 1.8)
|
16
16
|
nokogiri (~> 1.6.6)
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
nokogiri (~> 1.6)
|
29
29
|
codeclimate-test-reporter (1.0.3)
|
30
30
|
simplecov
|
31
|
-
collapsium (0.8.
|
31
|
+
collapsium (0.8.2)
|
32
32
|
collapsium-config (0.4.3)
|
33
33
|
collapsium (~> 0.7)
|
34
34
|
cucumber (2.4.0)
|
@@ -53,7 +53,7 @@ GEM
|
|
53
53
|
multi_test (0.1.2)
|
54
54
|
nokogiri (1.6.8.1)
|
55
55
|
mini_portile2 (~> 2.1.0)
|
56
|
-
parser (2.3.
|
56
|
+
parser (2.3.3.1)
|
57
57
|
ast (~> 2.2)
|
58
58
|
phantomjs (2.1.1.0)
|
59
59
|
powerpack (0.1.1)
|
@@ -73,7 +73,7 @@ GEM
|
|
73
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
74
74
|
rspec-support (~> 3.5.0)
|
75
75
|
rspec-support (3.5.0)
|
76
|
-
rubocop (0.
|
76
|
+
rubocop (0.46.0)
|
77
77
|
parser (>= 2.3.1.1, < 3.0)
|
78
78
|
powerpack (~> 0.1)
|
79
79
|
rainbow (>= 1.99.1, < 3.0)
|
@@ -108,7 +108,7 @@ DEPENDENCIES
|
|
108
108
|
phantomjs
|
109
109
|
rake (~> 11.3)
|
110
110
|
rspec (~> 3.5)
|
111
|
-
rubocop (~> 0.
|
111
|
+
rubocop (~> 0.46)
|
112
112
|
selenium-webdriver
|
113
113
|
simplecov (~> 0.12)
|
114
114
|
unobtainium!
|
@@ -7,6 +7,51 @@
|
|
7
7
|
# All rights reserved.
|
8
8
|
#
|
9
9
|
|
10
|
+
def store_ids(the_driver = driver)
|
11
|
+
@driver_ids ||= []
|
12
|
+
@driver_ids << the_driver.object_id
|
13
|
+
|
14
|
+
@driver_impl_ids ||= []
|
15
|
+
@driver_impl_ids << the_driver.impl.object_id
|
16
|
+
end
|
17
|
+
|
18
|
+
Given(/^I have no driver IDs stored$/) do
|
19
|
+
@driver_ids = []
|
20
|
+
@driver_impl_ids = []
|
21
|
+
end
|
22
|
+
|
10
23
|
Given(/^I navigate to the best website in the world$/) do
|
11
24
|
driver.navigate.to "http://finkhaeuser.de"
|
25
|
+
store_ids
|
26
|
+
end
|
27
|
+
|
28
|
+
When(/^I navigate to the best website in the world again$/) do
|
29
|
+
driver.navigate.to "http://finkhaeuser.de"
|
30
|
+
store_ids
|
31
|
+
end
|
32
|
+
|
33
|
+
Then(/^I expect the driver in each case to be the same$/) do
|
34
|
+
if not @driver_ids[0] == @driver_ids[1]
|
35
|
+
raise "Driver instance changed!"
|
36
|
+
end
|
37
|
+
if not @driver_impl_ids[0] == @driver_impl_ids[1]
|
38
|
+
raise "Driver implementation instance changed!"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
When(
|
43
|
+
/^I navigate to the best website in the world with another driver instance$/
|
44
|
+
) do
|
45
|
+
new_driver = driver(:headless, desired_capabilities: { something: :new })
|
46
|
+
new_driver.navigate.to "http://finkhaeuser.de"
|
47
|
+
store_ids(new_driver)
|
48
|
+
end
|
49
|
+
|
50
|
+
Then(/^I expect to have two driver instances$/) do
|
51
|
+
if @driver_ids[0] == @driver_ids[1]
|
52
|
+
raise "Driver instance the same!"
|
53
|
+
end
|
54
|
+
if @driver_impl_ids[0] == @driver_impl_ids[1]
|
55
|
+
raise "Driver implementation instance the same!"
|
56
|
+
end
|
12
57
|
end
|
data/features/world.feature
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
Feature: World
|
2
2
|
|
3
|
+
Background:
|
4
|
+
Given I have no driver IDs stored
|
5
|
+
|
3
6
|
Scenario: Driver and configuration loading
|
4
7
|
Given I navigate to the best website in the world
|
8
|
+
|
9
|
+
Scenario: Driver re-use
|
10
|
+
Given I navigate to the best website in the world
|
11
|
+
When I navigate to the best website in the world again
|
12
|
+
Then I expect the driver in each case to be the same
|
13
|
+
|
14
|
+
Scenario: Multiple drivers
|
15
|
+
Given I navigate to the best website in the world
|
16
|
+
When I navigate to the best website in the world with another driver instance
|
17
|
+
Then I expect to have two driver instances
|
data/lib/unobtainium/version.rb
CHANGED
data/lib/unobtainium/world.rb
CHANGED
@@ -72,6 +72,52 @@ module Unobtainium
|
|
72
72
|
# Returns a driver instance with the given options. If no options are
|
73
73
|
# provided, options from the global configuration are used.
|
74
74
|
def driver(label = nil, options = nil)
|
75
|
+
# Resolve unique options
|
76
|
+
label, options = resolve_options(label, options)
|
77
|
+
|
78
|
+
# Create a key for the label and options. This should always
|
79
|
+
# return the same key for the same label and options.
|
80
|
+
key = options['unobtainium_instance_id']
|
81
|
+
if key.nil?
|
82
|
+
key = identifier('driver', label, options)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Only create a driver with this exact configuration once. Unfortunately
|
86
|
+
# We'll have to bind the destructor to whatever configuration exists at
|
87
|
+
# this point in time, so we have to create a proc here - whether the Driver
|
88
|
+
# gets created or not.
|
89
|
+
at_end = config.fetch("at_end", "quit")
|
90
|
+
dtor = proc do |the_driver|
|
91
|
+
# :nocov:
|
92
|
+
if the_driver.nil?
|
93
|
+
return
|
94
|
+
end
|
95
|
+
|
96
|
+
# We'll rescue Exception here because we really want all destructors
|
97
|
+
# to run.
|
98
|
+
# rubocop:disable Lint/RescueException
|
99
|
+
begin
|
100
|
+
meth = at_end.to_sym
|
101
|
+
the_driver.send(meth)
|
102
|
+
rescue Exception => err
|
103
|
+
puts "Exception in destructor: [#{err.class}] #{err}"
|
104
|
+
end
|
105
|
+
# rubocop:enable Lint/RescueException
|
106
|
+
# :nocov:
|
107
|
+
end
|
108
|
+
return ::Unobtainium::Runtime.instance.store_with_if(key, dtor) do
|
109
|
+
::Unobtainium::Driver.create(label, options)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
##
|
116
|
+
# World's own option resolution ensures that the same options always get
|
117
|
+
# resolved the same, by storing anything resolved from Driver in the Runtime
|
118
|
+
# instance (i.e. asking the Driver only once per unique set of label and
|
119
|
+
# options).
|
120
|
+
def resolve_options(label, options)
|
75
121
|
# Make sure we have a label for the driver
|
76
122
|
if label.nil?
|
77
123
|
label = config["driver"]
|
@@ -106,35 +152,21 @@ module Unobtainium
|
|
106
152
|
options.delete("base")
|
107
153
|
end
|
108
154
|
|
109
|
-
#
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
key = identifier('driver', label, options)
|
155
|
+
# Do we have options already resolved?
|
156
|
+
option_key = identifier('options', label, options)
|
157
|
+
begin
|
158
|
+
stored_opts = ::Unobtainium::Runtime.instance.fetch(option_key)
|
159
|
+
options = ::Collapsium::UberHash.new(options)
|
160
|
+
options.recursive_merge!(stored_opts)
|
161
|
+
rescue KeyError
|
162
|
+
label, options, _ = ::Unobtainium::Driver.resolve_options(label, options)
|
118
163
|
end
|
119
164
|
|
120
|
-
#
|
121
|
-
#
|
122
|
-
|
123
|
-
# gets created or not.
|
124
|
-
at_end = config.fetch("at_end", "quit")
|
125
|
-
dtor = proc do |the_driver|
|
126
|
-
# :nocov:
|
127
|
-
if the_driver.nil?
|
128
|
-
return
|
129
|
-
end
|
165
|
+
# The driver may modify the options; if so, we should let it do that
|
166
|
+
# here. That way our key (below) is based on the expanded options.
|
167
|
+
::Unobtainium::Runtime.instance.store(option_key, options)
|
130
168
|
|
131
|
-
|
132
|
-
the_driver.send(meth)
|
133
|
-
# :nocov:
|
134
|
-
end
|
135
|
-
return ::Unobtainium::Runtime.instance.store_with_if(key, dtor) do
|
136
|
-
::Unobtainium::Driver.create(label, options)
|
137
|
-
end
|
169
|
+
return label, options
|
138
170
|
end
|
139
171
|
end # module World
|
140
172
|
end # module Unobtainium
|
data/spec/driver_spec.rb
CHANGED
@@ -13,8 +13,7 @@ module TestModule
|
|
13
13
|
end
|
14
14
|
end # class << self
|
15
15
|
|
16
|
-
def my_module_func
|
17
|
-
end
|
16
|
+
def my_module_func; end
|
18
17
|
end # module TestModule
|
19
18
|
|
20
19
|
module NonMatchingTestModule
|
@@ -25,8 +24,7 @@ module NonMatchingTestModule
|
|
25
24
|
end
|
26
25
|
end # class << self
|
27
26
|
|
28
|
-
def does_not_exist
|
29
|
-
end
|
27
|
+
def does_not_exist; end
|
30
28
|
end # module NonMatchingTestModule
|
31
29
|
|
32
30
|
module FakeModule
|
@@ -137,6 +137,16 @@ describe ::Unobtainium::Drivers::Phantom do
|
|
137
137
|
expect(resolved['unobtainium_instance_id']).not_to be_nil
|
138
138
|
end
|
139
139
|
|
140
|
+
context "defaults" do
|
141
|
+
it "generates the same ID and port if no input is given" do
|
142
|
+
_, resolved1 = tester.resolve_options(:phantomjs, nil)
|
143
|
+
expect(resolved1['phantomjs.generated_port']).to eql 9134
|
144
|
+
|
145
|
+
_, resolved2 = tester.resolve_options(:phantomjs, nil)
|
146
|
+
expect(resolved2['phantomjs.generated_port']).to eql 9134
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
140
150
|
it "generates new IDs for new options" do
|
141
151
|
opts = ::Collapsium::UberHash.new(
|
142
152
|
phantomjs: {
|
data/spec/mock_driver.rb
CHANGED
data/unobtainium.gemspec
CHANGED
@@ -44,7 +44,7 @@ Gem::Specification.new do |spec|
|
|
44
44
|
"'phantomjs'"
|
45
45
|
|
46
46
|
spec.add_development_dependency "bundler", "~> 1.12"
|
47
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
47
|
+
spec.add_development_dependency "rubocop", "~> 0.46"
|
48
48
|
spec.add_development_dependency "rake", "~> 11.3"
|
49
49
|
spec.add_development_dependency "rspec", "~> 3.5"
|
50
50
|
spec.add_development_dependency "simplecov", "~> 0.12"
|
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.
|
4
|
+
version: 0.10.0
|
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-
|
11
|
+
date: 2016-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.46'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.46'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|