ADB 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/ChangeLog +4 -0
- data/lib/ADB.rb +2 -0
- data/lib/ADB/instrumentation.rb +51 -0
- data/lib/ADB/version.rb +1 -1
- data/spec/lib/ADB/instrumentation_spec.rb +39 -0
- metadata +7 -4
data/.gitignore
CHANGED
data/ChangeLog
CHANGED
data/lib/ADB.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'ADB/instrumentation'
|
1
2
|
require 'ADB/version'
|
2
3
|
require 'ADB/errors'
|
3
4
|
require 'childprocess'
|
@@ -8,6 +9,7 @@ require 'date'
|
|
8
9
|
# which is a part of the android toolset.
|
9
10
|
#
|
10
11
|
module ADB
|
12
|
+
include ADB::Instrumentation
|
11
13
|
|
12
14
|
attr_reader :last_stdout, :last_stderr
|
13
15
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'ADB/errors'
|
2
|
+
|
3
|
+
module ADB
|
4
|
+
module Instrumentation
|
5
|
+
#
|
6
|
+
# send instrumentation requests
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# instrument "com.example/android.test.InstrumentationTestRunner"
|
10
|
+
# # will run all of the tests within the 'com.example' package using the 'android.test.InstrumentationTestRunner'
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# instrument "com.example/android.test.InstrumentationTestRunner", :class => "com.example.test.SomeTestClass"
|
14
|
+
#
|
15
|
+
# # will execute all of the tests within 'com.example.test.SomeTestClass'
|
16
|
+
#
|
17
|
+
# @param [String] runner indicates the package/runner to instrument
|
18
|
+
# @param [Hash] collection of key/value pairs to be sent as arguments to the instrumentation runner
|
19
|
+
#
|
20
|
+
def instrument(runner, args = {})
|
21
|
+
with(the(args) << using_the(runner))
|
22
|
+
raise ADBError, last_stdout unless last_stdout.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def with(args)
|
27
|
+
shell *"am instrument #{args.strip}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def using_the(runner)
|
31
|
+
runner.insert(0, "-w ") unless single_test?
|
32
|
+
runner
|
33
|
+
end
|
34
|
+
|
35
|
+
def the(args)
|
36
|
+
@args = args
|
37
|
+
to_args(args).join
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_args(args)
|
41
|
+
args.map do |name, value|
|
42
|
+
"-e #{name} #{value} "
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def single_test?
|
47
|
+
@args.has_key? :class
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
data/lib/ADB/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class InstrumentingClass
|
4
|
+
include ADB
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ADB::Instrumentation do
|
8
|
+
let(:instrumenter) { InstrumentingClass.new }
|
9
|
+
let(:runner) { 'com.example/com.example.TestRunner' }
|
10
|
+
let(:base_args) { "am instrument " }
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
instrumenter.stub(:shell)
|
14
|
+
instrumenter.stub(:last_stdout).and_return('')
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when instrumenting through ADB" do
|
18
|
+
it "should be able to run all of the tests" do
|
19
|
+
instrumenter.should_receive(:shell).with(*base_args.concat("-w #{runner}"))
|
20
|
+
instrumenter.instrument(runner)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should run tests in a single test class only" do
|
24
|
+
instrumenter.should_receive(:shell).with(*base_args.concat("-e class com.example.class #{runner}"))
|
25
|
+
instrumenter.instrument(runner, :class => 'com.example.class')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be able to take extra arguments" do
|
29
|
+
instrumenter.should_receive(:shell).with(*base_args.concat("-e any thing -e should be -e able to -e be passed -w #{runner}"))
|
30
|
+
instrumenter.instrument(runner, :any => 'thing', :should => 'be', :able => 'to', :be => 'passed')
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should raise an error if anything is in stderr" do
|
34
|
+
instrumenter.stub(:last_stdout).and_return('some problem')
|
35
|
+
lambda { instrumenter.instrument(runner) }.should raise_error(exception=ADBError, message="some problem")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ADB
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: childprocess
|
@@ -85,7 +85,9 @@ files:
|
|
85
85
|
- features/support/env.rb
|
86
86
|
- lib/ADB.rb
|
87
87
|
- lib/ADB/errors.rb
|
88
|
+
- lib/ADB/instrumentation.rb
|
88
89
|
- lib/ADB/version.rb
|
90
|
+
- spec/lib/ADB/instrumentation_spec.rb
|
89
91
|
- spec/lib/ADB_spec.rb
|
90
92
|
- spec/spec_helper.rb
|
91
93
|
homepage: http://github.com/cheezy/ADB
|
@@ -102,7 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
104
|
version: '0'
|
103
105
|
segments:
|
104
106
|
- 0
|
105
|
-
hash:
|
107
|
+
hash: 2061536077942189474
|
106
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
109
|
none: false
|
108
110
|
requirements:
|
@@ -111,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
113
|
version: '0'
|
112
114
|
segments:
|
113
115
|
- 0
|
114
|
-
hash:
|
116
|
+
hash: 2061536077942189474
|
115
117
|
requirements: []
|
116
118
|
rubyforge_project:
|
117
119
|
rubygems_version: 1.8.24
|
@@ -123,5 +125,6 @@ test_files:
|
|
123
125
|
- features/step_definitions/adb_steps.rb
|
124
126
|
- features/support/ApiDemos.apk
|
125
127
|
- features/support/env.rb
|
128
|
+
- spec/lib/ADB/instrumentation_spec.rb
|
126
129
|
- spec/lib/ADB_spec.rb
|
127
130
|
- spec/spec_helper.rb
|