Skip to content

Commit 0a5fd27

Browse files
committed
Show hint to remove the app you just installed
added rspec tests few tweaks
1 parent 22a5202 commit 0a5fd27

13 files changed

+150
-29
lines changed

.rspec

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--require spec_helper
2+
--tty
3+
--color
4+
--format documentation
5+
--format html -o "tmp/rspec_result.html"

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: ruby
22
rvm:
3+
- 1.9.3
34
- 2.2.1
4-
before_install: gem install bundler -v 1.10.6

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# dryrun
2-
[![Gem Version](https://badge.fury.io/rb/dryrun.svg)](http://badge.fury.io/rb/dryrun)
2+
![Header](https://travis-ci.org/cesarferreira/dryrun.svg?branch=master) [![Gem Version](https://badge.fury.io/rb/dryrun.svg)](http://badge.fury.io/rb/dryrun)
33

44
**Try** an **android** library on your **smartphone** **directly** from the **command line**
55

Rakefile

+10
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
require "bundler/gem_tasks"
2+
3+
require 'rspec/core/rake_task'
4+
5+
# Default directory to look in is `/specs`
6+
# Run with `rake spec`
7+
RSpec::Core::RakeTask.new(:spec) do |task|
8+
task.rspec_opts = ['--color', '--format', 'nested']
9+
end
10+
11+
task :default => :spec

dryrun.gemspec

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
1414
spec.authors = ["cesar ferreira"]
1515
spec.email = ["[email protected]"]
1616

17-
spec.summary = %q{try an android library directly from the command line}
18-
spec.description = %q{try an android library directly from the command line}
17+
spec.summary = %q{Tool which allows to quickly try the demo project of an Android Library}
18+
spec.description = %q{Tool which allows to quickly try the demo project of an Android Library}
1919
spec.homepage = "https://github.com/cesarferreira/dryrun"
2020

2121
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -26,6 +26,10 @@ Gem::Specification.new do |spec|
2626
spec.add_development_dependency "bundler", "~> 1.10"
2727
spec.add_development_dependency "rake", "~> 10.0"
2828
spec.add_development_dependency 'pry-byebug', '~> 3.1'
29+
spec.add_development_dependency "rspec"
30+
spec.add_development_dependency "rspec-nc"
31+
spec.add_development_dependency "guard"
32+
spec.add_development_dependency "guard-rspec"
2933

3034
spec.add_dependency 'colorize', '~> 0.7'
3135
spec.add_dependency 'nokogiri', '~> 1.6.6.2'

lib/dryrun.rb

+3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ def self.initialize(url)
4141
exit 1
4242
end
4343

44+
# clean and install the apk
4445
project.clean_install
4546

47+
puts "\n> If you want to remove the app you just installed, execute:\n#{project.get_uninstall_command.yellow}\n\n"
48+
4649
end
4750
end
4851
end

lib/dryrun/android_project.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def clean_install
5151

5252
system("#{builder} clean assembleDebug installDebug")
5353

54-
5554
puts "Installing #{@package.green}...\n"
5655
puts "executing: #{execute_line}"
5756
system(execute_line)
@@ -64,19 +63,18 @@ def sample_project
6463
full_path = "#{@base_path}#{child.first}"
6564

6665
execute_line = get_execute_line("#{full_path}/src/main/AndroidManifest.xml")
67-
68-
if execute_line
69-
#puts "\nTHE SAMPLE IS HERE #{full_path.green}:\n"
70-
#system("tree #{full_path}")
71-
return full_path, execute_line
72-
end
66+
return full_path, execute_line if execute_line
7367

7468
end
7569
return false, false
7670
end
7771

72+
def get_uninstall_command
73+
"adb uninstall #{@package}"
74+
end
75+
7876
def uninstall
79-
system("adb uninstall #{@package}")
77+
system("#{self.get_uninstall_command} > /dev/null 2>&1")
8078
end
8179

8280

lib/dryrun/github.rb

+22-16
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
11
require 'tmpdir'
22
require 'fileutils'
33
require 'uri'
4-
require 'colorize'
4+
require 'pry'
55

66
module DryRun
77

88
class Github
99
def initialize(url)
1010
@base_url = url
11-
12-
begin
13-
@resource = URI.parse(url)
14-
rescue Exception => e
15-
puts "Invalid github url".red
16-
puts "Valid example: #{'https://github.com/cesarferreira/colorize'.green}"
17-
exit 1
18-
end
11+
@destination = get_destination
1912
end
2013

21-
def path
22-
@resource.path
14+
def get_destination
15+
destiny = @base_url.gsub('.git','')
16+
destiny = destiny.split('/')
17+
"#{destiny.last(2).join('/')}"
2318
end
2419

2520
def is_valid
2621
return true
2722
end
2823

2924
def clonable_url
30-
# if @base_url.split(//).last(4).join.eql? ".git" or @base_url.split(//).first(4).join.eql? "git@"
31-
# @base_url
32-
# else
33-
"#{@base_url}.git"
25+
starts_with_git = @base_url.split(//).first(4).join.eql? "git@"
26+
ends_with_git = @base_url.split(//).last(4).join.eql? ".git"
27+
28+
# ends with git but doesnt start with git
29+
if ends_with_git and !starts_with_git
30+
return @base_url
31+
end
32+
33+
# ends with git but doesnt start with git
34+
if !ends_with_git and !starts_with_git
35+
return "#{@base_url}.git"
36+
end
37+
38+
@base_url
39+
3440
# end
3541
end
3642

@@ -40,7 +46,7 @@ def clonable_url
4046
def clone
4147
clonable = self.clonable_url
4248

43-
tmpdir = Dir.tmpdir+"#{path}"
49+
tmpdir = Dir.tmpdir+"dryrun/#{@destination}"
4450
FileUtils.rm_rf(tmpdir)
4551

4652
system("git clone #{clonable} #{tmpdir}")

lib/dryrun/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module DryRun
2-
VERSION = "0.2.2"
2+
VERSION = "0.3.1"
33
end

spec/android_project_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper'
2+
require 'pry'
3+
require 'dryrun/android_project'
4+
5+
6+
# RSpec.describe "something" do
7+
# context "in one context" do
8+
# it "does one thing" do
9+
# end
10+
# end
11+
# context "in another context" do
12+
# it "does another thing" do
13+
# end
14+
# end
15+
# end

spec/dryrun_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'spec_helper'

spec/github_spec.rb

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
require 'spec_helper'
2+
require 'pry'
3+
require 'dryrun/github'
4+
5+
6+
describe '#github' do
7+
8+
context 'when given github url\'s' do
9+
10+
it 'is a regular url' do
11+
url="https://github.com/cesarferreira/android-helloworld"
12+
github = DryRun::Github.new(url)
13+
expected = "https://github.com/cesarferreira/android-helloworld.git"
14+
expect(github.clonable_url == expected).to be true
15+
end
16+
17+
18+
it 'ends in .git' do
19+
url = 'https://github.com/googlesamples/google-services.git'
20+
github = DryRun::Github.new(url)
21+
expected = 'https://github.com/googlesamples/google-services.git'
22+
expect(github.clonable_url == expected).to be true
23+
end
24+
25+
26+
it 'is from ssh' do
27+
url = '[email protected]:cesarferreira/android-helloworld.git'
28+
github = DryRun::Github.new(url)
29+
expected = '[email protected]:cesarferreira/android-helloworld.git'
30+
expect(github.clonable_url == expected).to be true
31+
end
32+
end
33+
34+
35+
context 'when needing a destination to clone the project' do
36+
it 'is a regular url' do
37+
url = 'https://github.com/cesarferreira/android-helloworld'
38+
github = DryRun::Github.new(url)
39+
expected = 'cesarferreira/android-helloworld'
40+
expect(github.get_destination == expected).to be true
41+
end
42+
43+
it 'ends in .git' do
44+
url = 'https://github.com/googlesamples/google-services.git'
45+
github = DryRun::Github.new(url)
46+
expected = 'googlesamples/google-services'
47+
expect(github.get_destination == expected).to be true
48+
end
49+
end
50+
51+
52+
end

spec/spec_helper.rb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'dryrun'
2+
3+
RSpec.configure do |config|
4+
# rspec-expectations config goes here. You can use an alternate
5+
# assertion/expectation library such as wrong or the stdlib/minitest
6+
# assertions if you prefer.
7+
config.expect_with :rspec do |expectations|
8+
# This option will default to `true` in RSpec 4. It makes the `description`
9+
# and `failure_message` of custom matchers include text for helper methods
10+
# defined using `chain`, e.g.:
11+
# be_bigger_than(2).and_smaller_than(4).description
12+
# # => "be bigger than 2 and smaller than 4"
13+
# ...rather than:
14+
# # => "be bigger than 2"
15+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
16+
end
17+
18+
# rspec-mocks config goes here. You can use an alternate test double
19+
# library (such as bogus or mocha) by changing the `mock_with` option here.
20+
config.mock_with :rspec do |mocks|
21+
# Prevents you from mocking or stubbing a method that does not exist on
22+
# a real object. This is generally recommended, and will default to
23+
# `true` in RSpec 4.
24+
mocks.verify_partial_doubles = true
25+
end
26+
27+
end

0 commit comments

Comments
 (0)