Skip to content

Commit

Permalink
Show hint to remove the app you just installed
Browse files Browse the repository at this point in the history
added rspec tests
few tweaks
  • Loading branch information
cesarferreira committed Aug 20, 2015
1 parent 22a5202 commit 0a5fd27
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .rspec
@@ -0,0 +1,5 @@
--require spec_helper
--tty
--color
--format documentation
--format html -o "tmp/rspec_result.html"
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,4 +1,4 @@
language: ruby
rvm:
- 1.9.3
- 2.2.1
before_install: gem install bundler -v 1.10.6
2 changes: 1 addition & 1 deletion README.md
@@ -1,5 +1,5 @@
# dryrun
[![Gem Version](https://badge.fury.io/rb/dryrun.svg)](http://badge.fury.io/rb/dryrun)
![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)

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

Expand Down
10 changes: 10 additions & 0 deletions Rakefile
@@ -1 +1,11 @@
require "bundler/gem_tasks"

require 'rspec/core/rake_task'

# Default directory to look in is `/specs`
# Run with `rake spec`
RSpec::Core::RakeTask.new(:spec) do |task|
task.rspec_opts = ['--color', '--format', 'nested']
end

task :default => :spec
8 changes: 6 additions & 2 deletions dryrun.gemspec
Expand Up @@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
spec.authors = ["cesar ferreira"]
spec.email = ["cesar.manuel.ferreira@gmail.com"]

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

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

spec.add_dependency 'colorize', '~> 0.7'
spec.add_dependency 'nokogiri', '~> 1.6.6.2'
Expand Down
3 changes: 3 additions & 0 deletions lib/dryrun.rb
Expand Up @@ -41,8 +41,11 @@ def self.initialize(url)
exit 1
end

# clean and install the apk
project.clean_install

puts "\n> If you want to remove the app you just installed, execute:\n#{project.get_uninstall_command.yellow}\n\n"

end
end
end
14 changes: 6 additions & 8 deletions lib/dryrun/android_project.rb
Expand Up @@ -51,7 +51,6 @@ def clean_install

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


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

execute_line = get_execute_line("#{full_path}/src/main/AndroidManifest.xml")

if execute_line
#puts "\nTHE SAMPLE IS HERE #{full_path.green}:\n"
#system("tree #{full_path}")
return full_path, execute_line
end
return full_path, execute_line if execute_line

end
return false, false
end

def get_uninstall_command
"adb uninstall #{@package}"
end

def uninstall
system("adb uninstall #{@package}")
system("#{self.get_uninstall_command} > /dev/null 2>&1")
end


Expand Down
38 changes: 22 additions & 16 deletions lib/dryrun/github.rb
@@ -1,36 +1,42 @@
require 'tmpdir'
require 'fileutils'
require 'uri'
require 'colorize'
require 'pry'

module DryRun

class Github
def initialize(url)
@base_url = url

begin
@resource = URI.parse(url)
rescue Exception => e
puts "Invalid github url".red
puts "Valid example: #{'https://github.com/cesarferreira/colorize'.green}"
exit 1
end
@destination = get_destination
end

def path
@resource.path
def get_destination
destiny = @base_url.gsub('.git','')
destiny = destiny.split('/')
"#{destiny.last(2).join('/')}"
end

def is_valid
return true
end

def clonable_url
# if @base_url.split(//).last(4).join.eql? ".git" or @base_url.split(//).first(4).join.eql? "git@"
# @base_url
# else
"#{@base_url}.git"
starts_with_git = @base_url.split(//).first(4).join.eql? "git@"
ends_with_git = @base_url.split(//).last(4).join.eql? ".git"

# ends with git but doesnt start with git
if ends_with_git and !starts_with_git
return @base_url
end

# ends with git but doesnt start with git
if !ends_with_git and !starts_with_git
return "#{@base_url}.git"
end

@base_url

# end
end

Expand All @@ -40,7 +46,7 @@ def clonable_url
def clone
clonable = self.clonable_url

tmpdir = Dir.tmpdir+"#{path}"
tmpdir = Dir.tmpdir+"dryrun/#{@destination}"
FileUtils.rm_rf(tmpdir)

system("git clone #{clonable} #{tmpdir}")
Expand Down
2 changes: 1 addition & 1 deletion lib/dryrun/version.rb
@@ -1,3 +1,3 @@
module DryRun
VERSION = "0.2.2"
VERSION = "0.3.1"
end
15 changes: 15 additions & 0 deletions spec/android_project_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'
require 'pry'
require 'dryrun/android_project'


# RSpec.describe "something" do
# context "in one context" do
# it "does one thing" do
# end
# end
# context "in another context" do
# it "does another thing" do
# end
# end
# end
1 change: 1 addition & 0 deletions spec/dryrun_spec.rb
@@ -0,0 +1 @@
require 'spec_helper'
52 changes: 52 additions & 0 deletions spec/github_spec.rb
@@ -0,0 +1,52 @@
require 'spec_helper'
require 'pry'
require 'dryrun/github'


describe '#github' do

context 'when given github url\'s' do

it 'is a regular url' do
url="https://github.com/cesarferreira/android-helloworld"
github = DryRun::Github.new(url)
expected = "https://github.com/cesarferreira/android-helloworld.git"
expect(github.clonable_url == expected).to be true
end


it 'ends in .git' do
url = 'https://github.com/googlesamples/google-services.git'
github = DryRun::Github.new(url)
expected = 'https://github.com/googlesamples/google-services.git'
expect(github.clonable_url == expected).to be true
end


it 'is from ssh' do
url = 'git@github.com:cesarferreira/android-helloworld.git'
github = DryRun::Github.new(url)
expected = 'git@github.com:cesarferreira/android-helloworld.git'
expect(github.clonable_url == expected).to be true
end
end


context 'when needing a destination to clone the project' do
it 'is a regular url' do
url = 'https://github.com/cesarferreira/android-helloworld'
github = DryRun::Github.new(url)
expected = 'cesarferreira/android-helloworld'
expect(github.get_destination == expected).to be true
end

it 'ends in .git' do
url = 'https://github.com/googlesamples/google-services.git'
github = DryRun::Github.new(url)
expected = 'googlesamples/google-services'
expect(github.get_destination == expected).to be true
end
end


end
27 changes: 27 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,27 @@
require 'dryrun'

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end

end

0 comments on commit 0a5fd27

Please sign in to comment.