rubotium 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1b0f0bd231baeeb352f147b7eed2517a2bbf3c0
4
- data.tar.gz: c7cfcc8c601126f54bc4dfea8c6a11575cfb7f40
3
+ metadata.gz: 0b9bfc8633530e1490ee76cc637163c96b6b3dbc
4
+ data.tar.gz: 4d65fbd91f0bd74450d76258881a35a680238f86
5
5
  SHA512:
6
- metadata.gz: e22610e5725858e4c8a5af4e9868e1fc5ed7dc03c229a393239e153c76bf62b122bbaa3273435530892d38b01ed6e6feeed82e9275f7b24f4f2f993ad027be8f
7
- data.tar.gz: 4a976b43dfdd6ebd0105bbcce1742897256b01bc3aaa457c7ede59db7b66325039e0c7a8e2c6d52b2a0c7a7bf7853bd26ebf8d087eae9147202e816279e38015
6
+ metadata.gz: f8ce8e1a7e9f348fb2d6cc6fa6760a322e984dde2f73177f7a9987fdb08df5404394dd147a2b2bf435d130e313f0c61a3b96abe9cd1d2ed81538c50b0d15c7b9
7
+ data.tar.gz: 08b5304e3cac70a3db5270e6fe175075206049afb01fd4c15fb4ea84651882cff8279308a4485bb2fec750a5284bab0faca744a9933325e7fefc9430c014fd05
@@ -44,7 +44,7 @@ module Rubotium
44
44
  end
45
45
  rescue NoMethodError
46
46
  CMD.run_command(adb_command + ' ' + commands)
47
- end
47
+ end.result
48
48
  end
49
49
 
50
50
  private
@@ -3,7 +3,7 @@ module Rubotium
3
3
  class Devices
4
4
 
5
5
  def attached
6
- parse.map{|device_serial|
6
+ get_device_list.map{|device_serial|
7
7
  create_device(device_serial)
8
8
  }
9
9
  end
@@ -14,12 +14,16 @@ module Rubotium
14
14
  end
15
15
 
16
16
  def adb_devices_command
17
- CMD.run_command('adb devices', { :timeout => 5 } )
17
+ CMD.run_command('adb kill-server')
18
+ CMD.run_command('adb start-server')
19
+ CMD.run_command('adb devices', { :timeout => 5 } ).result
18
20
  end
19
21
 
20
- def parse
21
- list = adb_devices_command.split("\n")
22
- list.shift
22
+ def get_device_list
23
+ tries = 4
24
+ while ((list = adb_devices_command.split("\n")[1..-1]).empty? && tries > 0)
25
+ tries -= 1
26
+ end
23
27
  attached_devices list
24
28
  end
25
29
 
@@ -26,15 +26,15 @@ module Rubotium
26
26
 
27
27
  def results
28
28
  @results ||= aapt.dump(@path)
29
- if $?.exitstatus != 0 or @results.index("ERROR: dump failed")
30
- raise(RuntimeError, @results)
29
+ if @results.status_code != 0
30
+ raise(RuntimeError, @results.result)
31
31
  end
32
32
  @results
33
33
  end
34
34
 
35
35
  def parsed_aapt
36
36
  vars = Hash.new
37
- results.split("\n").each do |line|
37
+ results.result.split("\n").each do |line|
38
38
  key, value = _parse_line(line)
39
39
  next if key.nil?
40
40
  if vars.key?(key)
data/lib/rubotium/cmd.rb CHANGED
@@ -1,17 +1,45 @@
1
1
  require 'timeout'
2
2
  module Rubotium
3
3
  class CMD
4
+ attr_reader :read, :write
5
+ attr_reader :command_to_run, :buffer, :pid
6
+
4
7
  class << self
8
+
5
9
  def run_command(command_to_run, opts = {})
6
10
  begin
7
- Timeout::timeout(opts[:timeout] || 10 * 60) {
11
+ Timeout::timeout(opts[:timeout] || 150) {
8
12
  Rubotium.logger.debug "[EXECUTING]: #{command_to_run}"
9
- `#{command_to_run}`
13
+ new(command_to_run).execute
10
14
  }
11
15
  rescue Timeout::Error
12
16
  ""
13
17
  end
14
18
  end
15
19
  end
20
+
21
+ def initialize(command_to_run)
22
+ @command_to_run = command_to_run
23
+ @read, @write = IO.pipe
24
+ @buffer = ''
25
+ end
26
+
27
+ def execute
28
+ spawn_process
29
+ read_buffer
30
+ _, status = Process.waitpid2(pid)
31
+ CmdResult.new(status, buffer)
32
+ end
33
+
34
+ def read_buffer
35
+ while (!read.closed? && !read.eof? && line=read.readline)
36
+ buffer << line
37
+ end
38
+ end
39
+
40
+ def spawn_process
41
+ @pid = spawn(command_to_run, out: write, err: write)
42
+ write.close
43
+ end
16
44
  end
17
45
  end
@@ -0,0 +1,10 @@
1
+ module Rubotium
2
+ class CmdResult
3
+ attr_reader :status_code, :result
4
+
5
+ def initialize(status_code, result)
6
+ @status_code = status_code
7
+ @result = result
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Rubotium
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
data/lib/rubotium.rb CHANGED
@@ -2,6 +2,7 @@ require 'rubotium/version'
2
2
  require 'rubotium/adb'
3
3
  require 'rubotium/apk'
4
4
  require 'rubotium/cmd'
5
+ require 'rubotium/cmd_result'
5
6
  require 'rubotium/device'
6
7
  require 'rubotium/devices'
7
8
  require 'rubotium/tests_runner'
@@ -3,19 +3,23 @@ module Fixtures
3
3
  module Devices
4
4
  class << self
5
5
  def two_devices_attached_one_is_offline
6
- "List of devices attached \nemulator-5554\toffline\nemulator-5556\tdevice\n\n"
6
+ Rubotium::CmdResult.new(0,"List of devices attached \nemulator-5554\toffline\nemulator-5556\tdevice\n\n")
7
7
  end
8
8
 
9
9
  def two_devices_attached
10
- "List of devices attached \nemulator-5554\tdevice\nemulator-5556\tdevice\n\n"
10
+ Rubotium::CmdResult.new(0, "List of devices attached \nemulator-5554\tdevice\nemulator-5556\tdevice\n\n")
11
11
  end
12
12
 
13
- def one_device_offline
14
- "List of devices attached \nemulator-5554\toffline\n\n"
13
+ def one_device_attached_and_offline
14
+ Rubotium::CmdResult.new(0, "List of devices attached \nemulator-5554\toffline\n\n")
15
15
  end
16
16
 
17
- def one_device
18
- "List of devices attached \nemulator-5554\tdevice\n\n"
17
+ def one_device_attached
18
+ Rubotium::CmdResult.new(0, "List of devices attached \nemulator-5554\tdevice\n\n")
19
+ end
20
+
21
+ def no_devices_attached
22
+ Rubotium::CmdResult.new(0, "List of devices attached \n\n")
19
23
  end
20
24
  end
21
25
  end
@@ -9,9 +9,9 @@ describe Rubotium::Adb::Devices do
9
9
  }
10
10
  end
11
11
 
12
- context 'with one device attached' do
12
+ context 'when one device is attached' do
13
13
  before do
14
- Rubotium::CMD.stub(:run_command).and_return(Fixtures::Adb::Devices.one_device)
14
+ Rubotium::CMD.stub(:run_command).and_return(Fixtures::Adb::Devices.one_device_attached)
15
15
  end
16
16
 
17
17
  it 'should return one device' do
@@ -32,7 +32,7 @@ describe Rubotium::Adb::Devices do
32
32
  end
33
33
  end
34
34
 
35
- context 'with offline devices' do
35
+ context 'when two devices are attached and one is offline' do
36
36
  before do
37
37
  Rubotium::CMD.stub(:run_command).and_return(Fixtures::Adb::Devices.two_devices_attached_one_is_offline)
38
38
  end
@@ -45,11 +45,24 @@ describe Rubotium::Adb::Devices do
45
45
  end
46
46
  end
47
47
 
48
- context 'with no devices attached' do
48
+ context 'when one device is attached and offline' do
49
49
  before do
50
- Rubotium::CMD.stub(:run_command).and_return(Fixtures::Adb::Devices.one_device_offline)
50
+ Rubotium::CMD.stub(:run_command).and_return(Fixtures::Adb::Devices.one_device_attached_and_offline)
51
51
  end
52
+ it 'should return zero devices if none are online' do
53
+ devices.attached.should == []
54
+ end
55
+ end
56
+
57
+ context 'when no devices are attached' do
58
+ it 'should run adb_devices_command 5 times' do
59
+ devices.should_receive(:adb_devices_command).exactly(5).times
60
+ .and_return(Fixtures::Adb::Devices.no_devices_attached.result)
61
+ devices.attached
62
+ end
63
+
52
64
  it 'should return zero devices if none are attached' do
65
+ Rubotium::CMD.stub(:run_command).and_return(Fixtures::Adb::Devices.no_devices_attached)
53
66
  devices.attached.should == []
54
67
  end
55
68
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Rubotium::Adb::Commands::Command do
4
4
  let(:subject) { described_class.new(serial) }
5
5
  let(:adb_command) { 'the command' }
6
- let(:result) { 'result' }
6
+ let(:result) { Rubotium::CmdResult.new(0, 'result') }
7
7
  let(:command_to_run) { double(Object) }
8
8
 
9
9
  before do
@@ -16,7 +16,7 @@ describe Rubotium::Adb::Commands::Command do
16
16
  let(:shell_command) { "adb #{adb_command}" }
17
17
 
18
18
  it 'executes the command without a serial' do
19
- expect(subject.execute(command_to_run)).to eq result
19
+ expect(subject.execute(command_to_run)).to eq 'result'
20
20
  end
21
21
  end
22
22
 
@@ -25,7 +25,7 @@ describe Rubotium::Adb::Commands::Command do
25
25
  let(:shell_command) { "adb #{adb_command}" }
26
26
 
27
27
  it 'executes the command without a serial' do
28
- expect(subject.execute(command_to_run)).to eq result
28
+ expect(subject.execute(command_to_run)).to eq 'result'
29
29
  end
30
30
  end
31
31
 
@@ -34,7 +34,7 @@ describe Rubotium::Adb::Commands::Command do
34
34
  let(:shell_command) { "adb -s #{serial} #{adb_command}" }
35
35
 
36
36
  it 'executes the command with a serial' do
37
- expect(subject.execute(command_to_run)).to eq result
37
+ expect(subject.execute(command_to_run)).to eq 'result'
38
38
  end
39
39
  end
40
40
  end
@@ -24,8 +24,8 @@ describe Rubotium::Apk::AndroidApk do
24
24
  let(:apk) { described_class.new(aapt, dummy_file_path) }
25
25
 
26
26
  it 'should raise exception' do
27
- expect(aapt).to receive(:dump).and_return "W/zipro (77199): Error opening archive spec/lib/rubotium/apk/mock/dummy.apk: Invalid file
28
- ERROR: dump failed because assets could not be loaded"
27
+ expect(aapt).to receive(:dump).and_return Rubotium::CmdResult.new(1, "W/zipro (77199): Error opening archive spec/lib/rubotium/apk/mock/dummy.apk: Invalid file
28
+ ERROR: dump failed because assets could not be loaded")
29
29
  expect{apk.package_name}.to raise_error(RuntimeError)
30
30
  end
31
31
  end
@@ -34,7 +34,7 @@ ERROR: dump failed because assets could not be loaded"
34
34
  let(:apk) { described_class.new(aapt, sample_file_path) }
35
35
 
36
36
  it 'should read package_name' do
37
- expect(aapt).to receive(:dump).and_return "package: name='com.example.sample' versionCode='1' versionName='1.0' platformBuildVersionName=''
37
+ expect(aapt).to receive(:dump).and_return Rubotium::CmdResult.new(0, "package: name='com.example.sample' versionCode='1' versionName='1.0' platformBuildVersionName=''
38
38
  sdkVersion:'7'
39
39
  targetSdkVersion:'15'
40
40
  application-label:'sample'
@@ -50,7 +50,7 @@ feature-group: label=''
50
50
  supports-screens: 'small' 'normal' 'large' 'xlarge'
51
51
  supports-any-density: 'true'
52
52
  locales: '--_--' 'ja'
53
- densities: '160' '240' '320'"
53
+ densities: '160' '240' '320'")
54
54
  expect(apk.package_name).to eql 'com.example.sample'
55
55
  end
56
56
 
data/test.rb CHANGED
@@ -1,42 +1,11 @@
1
- require "observer"
1
+ require 'parallel'
2
2
 
3
- class Ticker ### Periodically fetch a stock price.
4
- include Observable
3
+ q = Queue.new
5
4
 
6
- def test_changed(msg)
7
- changed
5
+ (0..10).to_a.each{|e| q.push(e)}
6
+ b = (1..4).to_a
7
+ Parallel.map(b, :in_processes => 10){|executor|
8
+ until(q.empty?)
9
+ puts q.pop
8
10
  end
9
-
10
- def test_notify(msg)
11
- notify_observers(msg)
12
- end
13
- end
14
-
15
- class Observer
16
- def initialize(ticker, name)
17
- @ticker = ticker
18
- @name = name
19
- ticker.add_observer(self)
20
- end
21
-
22
- def unsubscribe
23
- @ticker.delete_observer(self)
24
- end
25
-
26
- def update(*args)
27
- puts @name
28
- p *args
29
- end
30
-
31
- def message_missing(*args)
32
- puts @name
33
- p args
34
- end
35
-
36
- end
37
-
38
-
39
- ticker = Ticker.new()
40
- observer = Observer.new(ticker, "observer1")
41
-
42
-
11
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubotium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Slawomir Smiechura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-28 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -160,6 +160,7 @@ files:
160
160
  - lib/rubotium/apk/aapt.rb
161
161
  - lib/rubotium/apk/android_apk.rb
162
162
  - lib/rubotium/cmd.rb
163
+ - lib/rubotium/cmd_result.rb
163
164
  - lib/rubotium/device.rb
164
165
  - lib/rubotium/devices.rb
165
166
  - lib/rubotium/formatters/html_formatter.css