unobtainium 0.8.1 → 0.9.0

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.
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ require_relative '../lib/unobtainium/support/identifiers'
3
+
4
+ describe ::Unobtainium::Support::Identifiers do
5
+ let(:tester) { Class.new { extend ::Unobtainium::Support::Identifiers } }
6
+
7
+ it "creates IDs starting with the given scope" do
8
+ expect(tester.identifier('noodle', 'foo')).to start_with 'noodle'
9
+ end
10
+
11
+ it "creates the same ID for identical input" do
12
+ opts = { foo: 'bar', "baz" => 42 }
13
+ first = tester.identifier('test', 'mylabel', opts.dup)
14
+ second = tester.identifier('test', 'mylabel', opts.dup)
15
+ expect(first).to eql second
16
+ end
17
+
18
+ context "different input" do
19
+ it "creates different IDs for different scopes" do
20
+ opts = { foo: 'bar', "baz" => 42 }
21
+ first = tester.identifier('scope1', 'mylabel', opts.dup)
22
+ second = tester.identifier('scope2', 'mylabel', opts.dup)
23
+ expect(first).not_to eql second
24
+ end
25
+
26
+ it "creates different IDs for different labels" do
27
+ opts = { foo: 'bar', "baz" => 42 }
28
+ first = tester.identifier('test', 'label1', opts.dup)
29
+ second = tester.identifier('test', 'label2', opts.dup)
30
+ expect(first).not_to eql second
31
+ end
32
+
33
+ it "creates different IDs for different options" do
34
+ opts1 = { foo: 'bar', "baz" => 42 }
35
+ opts2 = opts1.dup
36
+ opts2['baz'] = 123
37
+ first = tester.identifier('test', 'mylabel', opts1)
38
+ second = tester.identifier('test', 'mylabel', opts2)
39
+ expect(first).not_to eql second
40
+ end
41
+ end
42
+ end
@@ -47,6 +47,27 @@ describe ::Unobtainium::Support::PortScanner do
47
47
  tester.port_open?('localhost', 1234, :FOO)
48
48
  end.to raise_error(ArgumentError)
49
49
  end
50
+
51
+ it "handles unsupported protocols gracefully" do
52
+ allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
53
+ Errno::EINVAL # or EAFNOSUPPORT
54
+ )
55
+ expect(tester.port_open?('localhost', 1234, [:INET, :INET6])).to be_falsy
56
+ end
57
+
58
+ it "retries for several seconds if a socket is being created" do
59
+ allow_any_instance_of(Socket).to receive(:connect_nonblock).and_raise(
60
+ Errno::EINPROGRESS
61
+ )
62
+ before = Time.now.utc
63
+ expect(tester.port_open?('localhost', 1234, [:INET, :INET6])).to be_falsy
64
+ after = Time.now.utc
65
+
66
+ elapsed = after - before
67
+ expected_max_time = ::Unobtainium::Support::PortScanner::MAX_RETRIES \
68
+ * ::Unobtainium::Support::PortScanner::RETRY_DELAY
69
+ expect(elapsed).to be <= expected_max_time
70
+ end
50
71
  end
51
72
 
52
73
  describe "scan" do
@@ -113,6 +134,14 @@ describe ::Unobtainium::Support::PortScanner do
113
134
  expect(tester.scan('localhost', 1230..4330, amount: :first)).to eql [1234]
114
135
  end
115
136
 
137
+ it "can return successfully after the first find" do
138
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
139
+ connect_mock(sock, addr)
140
+ end
141
+
142
+ expect(tester.scan('localhost', 1230..4330, amount: :first)).to eql [1234]
143
+ end
144
+
116
145
  it "can scan for closed/available ports" do
117
146
  allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
118
147
  connect_mock(sock, addr)
@@ -121,6 +150,26 @@ describe ::Unobtainium::Support::PortScanner do
121
150
  expect(tester.scan('localhost', 1233..1234, for: :closed)).to eql [1233]
122
151
  end
123
152
 
153
+ it "can scan for the first closed/available port" do
154
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
155
+ connect_mock(sock, addr)
156
+ end
157
+
158
+ opts = {
159
+ amount: :first,
160
+ for: :closed,
161
+ }
162
+ expect(tester.scan('localhost', 1232..1234, opts)).to eql [1232]
163
+ end
164
+
165
+ it "can scan for the first string port" do
166
+ allow_any_instance_of(Socket).to receive(:connect_nonblock) do |sock, addr|
167
+ connect_mock(sock, addr)
168
+ end
169
+
170
+ expect(tester.scan('localhost', '1234', amount: :first)).to eql [1234]
171
+ end
172
+
124
173
  it "rejects bad amounts" do
125
174
  expect do
126
175
  tester.scan('localhost', 1230..4330, amount: :foo)
File without changes
File without changes
data/spec/world_spec.rb CHANGED
@@ -19,6 +19,11 @@ describe ::Unobtainium::World do
19
19
  @tester = Tester.new
20
20
  end
21
21
 
22
+ it "has set the config file as expected" do
23
+ expect(::Unobtainium::World.config_file).to end_with \
24
+ File.join('data', 'driverconfig.yml')
25
+ end
26
+
22
27
  it "loads the global config" do
23
28
  expect(@tester.config["drivers.mock.mockoption"]).to eql 42
24
29
  end
@@ -32,7 +37,40 @@ describe ::Unobtainium::World do
32
37
  end
33
38
 
34
39
  it "extends driver options, but doesn't pass 'base' on" do
35
- expect(@tester.config["drivers.leaf.base"]).to eql %w(.drivers.mock)
40
+ expect(@tester.config["drivers.leaf.base"]).to eql %w(.global
41
+ .drivers.mock
42
+ .drivers.branch1
43
+ .drivers.branch2)
36
44
  expect(@tester.driver.passed_options["base"]).to be_nil
37
45
  end
46
+
47
+ context "object identity" do
48
+ context "#driver" do
49
+ it "returns the same object for the same config" do
50
+ first = @tester.driver.object_id
51
+ second = @tester.driver.object_id
52
+ expect(first).to eql second
53
+ end
54
+
55
+ it "returns a different object for different config" do
56
+ first = @tester.driver(:mock, foo: true).object_id
57
+ second = @tester.driver(:mock, foo: false).object_id
58
+ expect(first).not_to eql second
59
+ end
60
+ end
61
+
62
+ context "driver.impl" do
63
+ it "returns the same object for the same config" do
64
+ first = @tester.driver.impl.object_id
65
+ second = @tester.driver.impl.object_id
66
+ expect(first).to eql second
67
+ end
68
+
69
+ it "returns a different object for different config" do
70
+ first = @tester.driver(:mock, foo: true).impl.object_id
71
+ second = @tester.driver(:mock, foo: false).impl.object_id
72
+ expect(first).not_to eql second
73
+ end
74
+ end
75
+ end
38
76
  end
data/unobtainium.gemspec CHANGED
@@ -57,7 +57,7 @@ Gem::Specification.new do |spec|
57
57
 
58
58
  spec.add_dependency "sys-proctable", "~> 1.1"
59
59
  spec.add_dependency "ptools", "~> 1.3"
60
- spec.add_dependency "collapsium", "~> 0.6"
60
+ spec.add_dependency "collapsium", "~> 0.8"
61
61
  spec.add_dependency "collapsium-config", "~> 0.4"
62
62
  end
63
63
  # rubocop:enable Metrics/BlockLength
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.8.1
4
+ version: 0.9.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-08 00:00:00.000000000 Z
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -198,14 +198,14 @@ dependencies:
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: '0.6'
201
+ version: '0.8'
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '0.6'
208
+ version: '0.8'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: collapsium-config
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +253,7 @@ files:
253
253
  - lib/unobtainium/drivers/phantom.rb
254
254
  - lib/unobtainium/drivers/selenium.rb
255
255
  - lib/unobtainium/runtime.rb
256
+ - lib/unobtainium/support/identifiers.rb
256
257
  - lib/unobtainium/support/port_scanner.rb
257
258
  - lib/unobtainium/support/runner.rb
258
259
  - lib/unobtainium/support/util.rb
@@ -262,12 +263,16 @@ files:
262
263
  - media/video.ogv
263
264
  - spec/data/driverconfig.yml
264
265
  - spec/driver_spec.rb
266
+ - spec/drivers_appium_spec.rb
267
+ - spec/drivers_phantom_spec.rb
268
+ - spec/drivers_selenium_spec.rb
265
269
  - spec/mock_driver.rb
266
- - spec/port_scanner_spec.rb
267
- - spec/runner_spec.rb
268
270
  - spec/runtime_spec.rb
269
271
  - spec/spec_helper.rb
270
- - spec/utility_spec.rb
272
+ - spec/support_identifiers_spec.rb
273
+ - spec/support_port_scanner_spec.rb
274
+ - spec/support_runner_spec.rb
275
+ - spec/support_utility_spec.rb
271
276
  - spec/world_spec.rb
272
277
  - unobtainium.gemspec
273
278
  homepage: https://github.com/jfinkhaeuser/unobtainium
@@ -301,10 +306,14 @@ test_files:
301
306
  - features/world.feature
302
307
  - spec/data/driverconfig.yml
303
308
  - spec/driver_spec.rb
309
+ - spec/drivers_appium_spec.rb
310
+ - spec/drivers_phantom_spec.rb
311
+ - spec/drivers_selenium_spec.rb
304
312
  - spec/mock_driver.rb
305
- - spec/port_scanner_spec.rb
306
- - spec/runner_spec.rb
307
313
  - spec/runtime_spec.rb
308
314
  - spec/spec_helper.rb
309
- - spec/utility_spec.rb
315
+ - spec/support_identifiers_spec.rb
316
+ - spec/support_port_scanner_spec.rb
317
+ - spec/support_runner_spec.rb
318
+ - spec/support_utility_spec.rb
310
319
  - spec/world_spec.rb