acouchi 0.0.4 → 0.0.5

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.
@@ -4,5 +4,7 @@ require "acouchi/solo"
4
4
  require "acouchi/test_runner"
5
5
  require "acouchi/configuration"
6
6
  require "acouchi/apk_modifier"
7
+ require "acouchi/apk_installer"
7
8
  require "acouchi/process_launcher"
8
9
  require "acouchi/which"
10
+ require "acouchi/executables"
@@ -0,0 +1,24 @@
1
+ module Acouchi
2
+ class ApkInstaller
3
+ def initialize configuration
4
+ @configuration = configuration
5
+ @apk_path = File.join(configuration.project_path, "bin", configuration.apk)
6
+ end
7
+
8
+ def install_apk
9
+ ProcessLauncher.new(
10
+ Executables.adb,
11
+ "install",
12
+ @apk_path
13
+ ).start_and_crash_if_process_fails
14
+ end
15
+
16
+ def uninstall_apk
17
+ ProcessLauncher.new(
18
+ Executables.adb,
19
+ "uninstall",
20
+ @configuration.target_package
21
+ ).start
22
+ end
23
+ end
24
+ end
@@ -32,16 +32,12 @@ module Acouchi
32
32
  @apktool ||= Which.find_executable("apktool.bat", "apktool")
33
33
  end
34
34
 
35
- def execute_apktool command
36
- ProcessLauncher.new(apktool, command)
37
- end
38
-
39
35
  def decompile_apk
40
- ProcessLauncher.new(apktool, "d", @apk, @output_path).start_and_crash_if_process_fails
36
+ ProcessLauncher.new(apktool, "d", @apk, @output_path).with_inherited_io.start_and_crash_if_process_fails
41
37
  end
42
38
 
43
39
  def compile_apk
44
- ProcessLauncher.new(apktool, "b", @output_path).start_and_crash_if_process_fails
40
+ ProcessLauncher.new(apktool, "b", @output_path).with_inherited_io.start_and_crash_if_process_fails
45
41
  end
46
42
 
47
43
  def sign_apk_in_debug_mode
@@ -58,11 +54,11 @@ module Acouchi
58
54
  "android",
59
55
  @new_apk,
60
56
  "androiddebugkey"
61
- ).start_and_crash_if_process_fails
57
+ ).with_inherited_io.start_and_crash_if_process_fails
62
58
  end
63
59
 
64
60
  def overwrite_original_apk
65
- FileUtils.mv(@new_apk, @apk)
61
+ FileUtils.mv(@new_apk, @apk)
66
62
  end
67
63
  end
68
64
  end
@@ -0,0 +1,7 @@
1
+ module Acouchi
2
+ class Executables
3
+ def self.adb
4
+ @adb ||= Which.find_executable("adb.exe", "adb")
5
+ end
6
+ end
7
+ end
@@ -1,37 +1,41 @@
1
+ require "childprocess"
2
+
1
3
  module Acouchi
2
4
  class ProcessLauncher
5
+ DEFAULT_START_OPTIONS = {:inherit_io => true}
6
+
3
7
  def initialize(*arguments)
4
8
  @arguments = arguments
5
9
  @process = ChildProcess.build(*@arguments)
10
+ self
11
+ end
12
+
13
+ def with_inherited_io
6
14
  @process.io.inherit!
15
+ self
7
16
  end
8
17
 
9
18
  def start
10
- write_out_arguments
11
19
  @process.start
20
+ self
21
+ end
22
+
23
+ def wait
12
24
  @process.wait
25
+ self
13
26
  end
14
27
 
15
28
  def start_in_background
16
- write_out_arguments
17
29
  @process.start
18
- end
19
-
20
- def stop
21
- @process.stop
30
+ self
22
31
  end
23
32
 
24
33
  def start_and_crash_if_process_fails
25
- start
26
-
34
+ start.wait
27
35
  if @process.crashed?
28
36
  raise "A process exited with a non-zero exit code.\nThe command executed was \"#{@arguments.join(" ")}\""
29
37
  end
38
+ self
30
39
  end
31
-
32
- private
33
- def write_out_arguments
34
- p @arguments
35
- end
36
40
  end
37
41
  end
@@ -21,7 +21,6 @@ module Acouchi
21
21
 
22
22
  apk_path = File.join(configuration.project_path, "bin", configuration.apk)
23
23
  modify_manifest(apk_path)
24
- install_apk(apk_path)
25
24
  end
26
25
 
27
26
  def temporarily_copy_over_source_files
@@ -76,23 +75,14 @@ module Acouchi
76
75
  end
77
76
  end
78
77
 
79
- def adb
80
- Which.which?("adb.exe") || Which.which?("adb")
81
- end
82
-
83
78
  def ant
84
- Which.which?("ant.exe") || Which.which?("ant")
79
+ Which.find_executable("ant.exe", "ant")
85
80
  end
86
81
 
87
82
  def build_apk
88
83
  Dir.chdir configuration.project_path do
89
- ProcessLauncher.new(ant, "clean", "debug").start_and_crash_if_process_fails
84
+ ProcessLauncher.new(ant, "clean", "debug").with_inherited_io.start_and_crash_if_process_fails
90
85
  end
91
86
  end
92
-
93
- def install_apk apk_path
94
- ProcessLauncher.new(adb, "uninstall", configuration.target_package).start
95
- ProcessLauncher.new(adb, "install", apk_path).start_and_crash_if_process_fails
96
- end
97
87
  end
98
88
  end
@@ -1,19 +1,16 @@
1
- require "childprocess"
2
-
3
1
  module Acouchi
4
2
  class TestRunner
5
3
  def initialize configuration
6
4
  @configuration = configuration
7
5
  end
8
6
 
9
- def adb
10
- @adb ||= Which.find_executable("adb")
11
- end
12
-
13
7
  def start
14
- force_stop
15
- ProcessLauncher.new(adb, "forward", "tcp:7103", "tcp:7103").start_and_crash_if_process_fails
16
- @test_runner_process = ProcessLauncher.new(adb, "shell", "am", "instrument", "-w", "#{@configuration.target_package}/android.test.InstrumentationTestRunner")
8
+ apk_installer = ApkInstaller.new(@configuration)
9
+ apk_installer.uninstall_apk
10
+ apk_installer.install_apk
11
+
12
+ ProcessLauncher.new(Executables.adb, "forward", "tcp:7103", "tcp:7103").start_and_crash_if_process_fails
13
+ @test_runner_process = ProcessLauncher.new(Executables.adb, "shell", "am", "instrument", "-w", "#{@configuration.target_package}/android.test.InstrumentationTestRunner")
17
14
  @test_runner_process.start_in_background
18
15
 
19
16
  while ready? == false
@@ -23,16 +20,11 @@ module Acouchi
23
20
 
24
21
  def stop
25
22
  HTTParty.get("http://127.0.0.1:7103/finish") rescue nil
26
- @test_runner_process.stop
27
23
  end
28
24
 
29
25
  private
30
26
  def ready?
31
27
  HTTParty.get("http://127.0.0.1:7103/").body == "Acouchi" rescue false
32
28
  end
33
-
34
- def force_stop
35
- ChildProcess.build(adb, "shell", "am", "force-stop", @configuration.target_package).start.wait
36
- end
37
29
  end
38
30
  end
@@ -1,3 +1,3 @@
1
1
  module Acouchi
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,16 +1,5 @@
1
1
  module Acouchi
2
2
  class Which
3
- def self.which? command
4
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
5
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
6
- exts.each { |ext|
7
- exe = "#{path}/#{command}#{ext}"
8
- return exe if File.executable? exe
9
- }
10
- end
11
- return nil
12
- end
13
-
14
3
  def self.find_executable *aliases
15
4
  if executable = aliases.find {|a| which? a}
16
5
  executable
@@ -18,5 +7,17 @@ module Acouchi
18
7
  raise %{Couldn't find any matches for the aliases "#{aliases.join(", ")}"}
19
8
  end
20
9
  end
10
+
11
+ private
12
+ def self.which? command
13
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
14
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
15
+ exts.each { |ext|
16
+ exe = "#{path}/#{command}#{ext}"
17
+ return exe if File.executable? exe
18
+ }
19
+ end
20
+ return nil
21
+ end
21
22
  end
22
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acouchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-18 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -92,9 +92,11 @@ files:
92
92
  - jars/gson-2.2.2.jar
93
93
  - jars/robotium-solo-3.4.1.jar
94
94
  - lib/acouchi.rb
95
+ - lib/acouchi/apk_installer.rb
95
96
  - lib/acouchi/apk_modifier.rb
96
97
  - lib/acouchi/configuration.rb
97
98
  - lib/acouchi/cucumber.rb
99
+ - lib/acouchi/executables.rb
98
100
  - lib/acouchi/process_launcher.rb
99
101
  - lib/acouchi/project_builder.rb
100
102
  - lib/acouchi/rspec/matchers.rb