replicant-adb 0.0.1 → 1.0.1

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.
@@ -1,90 +0,0 @@
1
- require 'helper'
2
-
3
- class CommandSpec < CommandSpecBase
4
-
5
- describe "command loading" do
6
- it "loads the EnvCommand when command is '?'" do
7
- command = Command.load(@repl, "?")
8
- command.must_be_instance_of EnvCommand
9
- end
10
-
11
- it "loads the ListCommand when command is '!'" do
12
- command = Command.load(@repl, "!")
13
- command.must_be_instance_of ListCommand
14
- end
15
-
16
- it "returns nil if !-command cannot be resolved" do
17
- Command.load(@repl, "!unknown").must_be_nil
18
- end
19
-
20
- it "loads the AdbCommand for commands not starting in '!'" do
21
- command = Command.load(@repl, "shell ps")
22
- command.must_be_instance_of AdbCommand
23
- end
24
-
25
- describe "arguments" do
26
- it "injects the arguments for loaded command objects" do
27
- command = Command.load(@repl, "shell ps")
28
- command.args.must_equal "shell ps"
29
- end
30
- end
31
- end
32
-
33
- describe "command listing" do
34
- it "does not include the ListCommand" do
35
- Command.all.map{|c|c.class}.wont_include(ListCommand)
36
- end
37
-
38
- it "does not include the AdbCommand" do
39
- Command.all.map{|c|c.class}.wont_include(AdbCommand)
40
- end
41
-
42
- it "does not include the EnvCommand" do
43
- Command.all.map{|c|c.class}.wont_include(EnvCommand)
44
- end
45
- end
46
-
47
- describe "the command interface" do
48
- before do
49
- class ::TestCommand < Command; end
50
- @command = silent TestCommand.new(@repl)
51
- end
52
-
53
- it "allows resolving the command name via type inspection" do
54
- @command.name.must_equal "!test"
55
- end
56
-
57
- it "triggers the run method when calling 'execute'" do
58
- @command.expects(:run).once
59
- @command.execute
60
- end
61
-
62
- it "does not trigger the run method when arguments are invalid" do
63
- @command.expects(:valid_args?).returns(false)
64
- @command.expects(:run).never
65
- @command.execute
66
- end
67
- end
68
-
69
- describe "command options" do
70
- before do
71
- class ::TestCommand < Command
72
- def run
73
- output "this is a test"
74
- end
75
- end
76
- end
77
-
78
- it "can silence console output" do
79
- command = TestCommand.new(@repl, nil, :silent => true)
80
- lambda { command.execute }.must_be_silent
81
- end
82
- end
83
-
84
- describe "arguments" do
85
- it "strips argument whitespace when creating command instance" do
86
- command = TestCommand.new(@repl, " ")
87
- command.args.must_equal ""
88
- end
89
- end
90
- end
@@ -1,30 +0,0 @@
1
- class Command
2
- attr_reader :backtick_capture
3
- attr_reader :system_capture
4
- # capture system calls on all commands
5
- def `(cmd)
6
- @backtick_capture = cmd
7
- nil
8
- end
9
- def system(cmd)
10
- @system_capture = cmd
11
- nil
12
- end
13
- end
14
-
15
- class CommandSpecBase < MiniTest::Spec
16
-
17
- before do
18
- @repl = Replicant::REPL.new
19
- end
20
-
21
- def silent(command)
22
- def command.output(s)
23
- @output = s
24
- end
25
- def command.output_capture
26
- @output
27
- end
28
- command
29
- end
30
- end
@@ -1,40 +0,0 @@
1
- require 'helper'
2
-
3
- class DeviceCommandSpec < CommandSpecBase
4
-
5
- describe "given a valid list of devices" do
6
- before do
7
- @device0 = Device.new("emulator-5554", "Emulator 1")
8
- @device1 = Device.new("emulator-5556", "Emulator 2")
9
- DevicesCommand.any_instance.stubs(:execute).returns([@device0, @device1])
10
- end
11
-
12
- it "can select a device by index" do
13
- silent(DeviceCommand.new(@repl, "0")).execute
14
- @repl.default_device.must_equal @device0
15
- silent(DeviceCommand.new(@repl, "1")).execute
16
- @repl.default_device.must_equal @device1
17
- end
18
-
19
- it "can select a device by device id" do
20
- silent(DeviceCommand.new(@repl, "emulator-5554")).execute
21
- @repl.default_device.must_equal @device0
22
- silent(DeviceCommand.new(@repl, "emulator-5556")).execute
23
- @repl.default_device.must_equal @device1
24
- end
25
-
26
- it "outputs an error message if selected device doesn't exist" do
27
- command = DeviceCommand.new(@repl, "emulator-bogus")
28
- lambda { command.execute }.must_output "No such device\n"
29
- end
30
- end
31
-
32
- describe "given an empty list of devices" do
33
- it "outputs an error message when selecting a device" do
34
- DevicesCommand.any_instance.stubs(:execute).returns([])
35
- command = DeviceCommand.new(@repl, "emulator-5554")
36
- lambda { command.execute }.must_output "No such device\n"
37
- end
38
- end
39
-
40
- end
@@ -1,65 +0,0 @@
1
- require 'helper'
2
-
3
- ADB_NO_DEVICES = <<-OUTPUT
4
- * daemon not running. starting it now on port 5037 *
5
- * daemon started successfully *
6
- List of devices attached
7
-
8
- OUTPUT
9
-
10
- ADB_DEVICES = <<-OUTPUT
11
- * daemon not running. starting it now on port 5037 *
12
- * daemon started successfully *
13
- List of devices attached
14
- 192.168.56.101:5555 device product:vbox86p model:Nexus_4___4_3___API_18___768x1280 device:vbox86p
15
- 005de387d71505d6 device usb:1D110000 product:occam model:Nexus_4 device:mako
16
- emulator-5554 device
17
-
18
- OUTPUT
19
-
20
- REPLICANT_DEVICES = <<-OUTPUT
21
-
22
- [0] Genymotion Nexus 4 API 18 768x1280 | 192.168.56.101:5555
23
- [1] Nexus 4 | 005de387d71505d6
24
- [2] Android emulator | emulator-5554
25
-
26
- OUTPUT
27
-
28
- class DevicesCommandSpec < CommandSpecBase
29
-
30
- describe "when no devices were found" do
31
- before do
32
- AdbCommand.any_instance.expects(:execute).returns(ADB_NO_DEVICES)
33
- end
34
-
35
- it "returns an empty device list" do
36
- command = silent DevicesCommand.new(@repl)
37
- command.execute.must_equal []
38
- end
39
-
40
- it "prints a message and exits" do
41
- command = DevicesCommand.new(@repl)
42
- lambda { command.execute }.must_output("\nNo devices found\n\n")
43
- end
44
- end
45
-
46
- describe "when devices were found" do
47
- before do
48
- AdbCommand.any_instance.expects(:execute).returns(ADB_DEVICES)
49
- end
50
-
51
- it "returns the list of devices" do
52
- command = silent DevicesCommand.new(@repl)
53
- devices = command.execute
54
- devices.map { |d| d.id }.must_equal [
55
- "192.168.56.101:5555", "005de387d71505d6", "emulator-5554"
56
- ]
57
- end
58
-
59
- it "outputs a prettified, indexed list of devices" do
60
- command = DevicesCommand.new(@repl)
61
- lambda { command.execute }.must_output(REPLICANT_DEVICES)
62
- end
63
- end
64
-
65
- end
@@ -1,30 +0,0 @@
1
- require 'helper'
2
-
3
- class EnvCommandSpec < CommandSpecBase
4
-
5
- BLANK_ENV_OUTPUT = <<-OUT
6
- Package: Not set
7
- Device: Not set
8
- OUT
9
-
10
- ACTIVE_ENV_OUTPUT = <<-OUT
11
- Package: com.myapp
12
- Device: Emulator 1 (emulator-5554)
13
- OUT
14
-
15
- describe "with no device and no package fixed" do
16
- it "lists no devices and packages as selected" do
17
- command = EnvCommand.new(@repl)
18
- lambda { command.execute }.must_output(BLANK_ENV_OUTPUT)
19
- end
20
- end
21
-
22
- describe "with a device and package fixed" do
23
- it "lists no devices and packages as selected" do
24
- @repl.default_device = Device.new("emulator-5554", "Emulator 1")
25
- @repl.default_package = 'com.myapp'
26
- command = EnvCommand.new(@repl)
27
- lambda { command.execute }.must_output(ACTIVE_ENV_OUTPUT)
28
- end
29
- end
30
- end
@@ -1,13 +0,0 @@
1
- require 'helper'
2
-
3
- class ListCommandSpec < CommandSpecBase
4
-
5
- describe "listing commands" do
6
- it "prints a list of available commands" do
7
- command = silent ListCommand.new(@repl)
8
- command.execute
9
- command.output_capture.must_match /^!\w+/
10
- end
11
- end
12
-
13
- end
@@ -1,34 +0,0 @@
1
- require 'helper'
2
-
3
- class PackageCommandSpec < CommandSpecBase
4
-
5
- describe "with valid arguments" do
6
- it "accepts a package with one element" do
7
- command = silent PackageCommand.new(@repl, "myapp")
8
- command.execute
9
- @repl.default_package.must_equal "myapp"
10
- end
11
-
12
- it "accepts a package with two elements" do
13
- command = silent PackageCommand.new(@repl, "com.myapp")
14
- command.execute
15
- @repl.default_package.must_equal "com.myapp"
16
- end
17
- end
18
-
19
- describe "with invalid arguments" do
20
- it "refuses a package not starting with alphanumeric characters" do
21
- command = silent PackageCommand.new(@repl, "%myapp")
22
- command.expects(:run).never
23
- command.execute
24
- @repl.default_package.must_be_nil
25
- end
26
-
27
- it "refuses a package containing non-alphanumeric characters" do
28
- command = silent PackageCommand.new(@repl, "myapp.some$thing")
29
- command.expects(:run).never
30
- command.execute
31
- @repl.default_package.must_be_nil
32
- end
33
- end
34
- end
@@ -1,16 +0,0 @@
1
- begin
2
- Bundler.require(:default, :test)
3
- rescue Bundler::BundlerError => e
4
- $stderr.puts e.message
5
- $stderr.puts "Run `bundle install` to install missing gems"
6
- exit e.status_code
7
- end
8
-
9
- # additional test modules
10
- require 'minitest/pride'
11
- require 'commands/command_spec_base'
12
-
13
- # application module
14
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
- $LOAD_PATH.unshift(File.dirname(__FILE__))
16
- require 'replicant'