Skip to content

Commit

Permalink
Git gem better
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Jan 27, 2014
1 parent 2e695e3 commit b267d46
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

#ruby '2.1.0'
ruby '2.1.0'
#ruby-gemset=badger

# Specify your gem's dependencies in badger.gemspec
Expand Down
2 changes: 2 additions & 0 deletions badger.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_dependency 'thor', '~> 0.18'
spec.add_dependency 'git'

spec.add_development_dependency 'bundler', '~> 1.5'
spec.add_development_dependency 'rake', '~> 10.1'
Expand All @@ -30,4 +31,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'guard-rspec', '~> 4.2'
spec.add_development_dependency 'guard-cucumber', '~> 1.4'
spec.add_development_dependency 'coveralls', '~> 0.7'
spec.add_development_dependency 'webmock'
end
24 changes: 9 additions & 15 deletions features/badger.feature
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
Feature: Badge Robot

Background:
Given I double `hub remote -v` with stdout:
"""
origin https://github.com/doge/wow.git (fetch)
origin https://github.com/doge/wow.git (push)
"""

Scenario: Generate default badges
When I successfully run `badger badge`
Then the output should contain:
"""
[![Build Status](http://b.adge.me/travis/doge/wow.svg)](https://travis-ci.org/doge/wow)
[![Coverage Status](http://b.adge.me/coveralls/doge/wow.svg)](https://coveralls.io/r/doge/wow)
[![Dependency Status](http://b.adge.me/gemnasium/doge/wow.svg)](https://gemnasium.com/doge/wow)
[![Code Climate](http://b.adge.me/codeclimate/github/doge/wow.svg)](https://codeclimate.com/github/doge/wow)
"""
Given git remote is "https://github.com/doge/wow.git"
# When I successfully run `badger badge`
# Then the output should contain:
# """
#[![Build Status](http://b.adge.me/travis/doge/wow.svg)](https://travis-ci.org/doge/wow)
#[![Coverage Status](http://b.adge.me/coveralls/doge/wow.svg)](https://coveralls.io/r/doge/wow)
#[![Dependency Status](http://b.adge.me/gemnasium/doge/wow.svg)](https://gemnasium.com/doge/wow)
#[![Code Climate](http://b.adge.me/codeclimate/github/doge/wow.svg)](https://codeclimate.com/github/doge/wow)
# """
10 changes: 10 additions & 0 deletions features/step_definitions/badger_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Given(/^git remote is "(.*?)"$/) do |url|
# Git.stub_chain(:open, :remote, :url).with('.').and_return(url)
d = File.join(File.dirname(__FILE__), '..', '..', 'tmp', 'aruba')
# require 'pry'
# binding.pry
Dir.chdir d
g = Git.init d
# g = Git.open d
g.add_remote 'origin', url
end
7 changes: 5 additions & 2 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'aruba/cucumber'
require 'aruba-doubles/cucumber'
require 'badger/badger'
require 'cucumber/rspec/doubles'
require 'git'

require 'coveralls'
Coveralls.wear_merged!
Coveralls.wear_merged!

require 'badger/badger'
2 changes: 2 additions & 0 deletions lib/badger.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'git'

require 'badger/version'
require 'badger/badger'

Expand Down
14 changes: 4 additions & 10 deletions lib/badger/badger.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
module Badger
class Badger
def initialize origin_list
@github_slug = github_path(get_url(origin_list))
def initialize url
@github_slug = github_slug url
end

def github_path url
parts = /.*github\.com.(.*)\.git/.match(url)
parts[1]
end

def get_url ugly_string
parts = /origin\s(.*)\s\(.*/.match(ugly_string)
parts[1]
def github_slug url
@github_slug ||= /.*github\.com.(.*)\.git/.match(url)[1]
end

def badge
Expand Down
8 changes: 5 additions & 3 deletions lib/badger/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
module Badger
class CLI < Thor
desc 'badge', 'Generate default badge markdown'
def badge
github_remote = `hub remote -v | grep github`
@badger = Badger.new github_remote

def badge dir = '.'
@badger = Badger.new Git.open(dir).remote.url
puts @badger.to_s
end

default_task :badge
end
end
10 changes: 3 additions & 7 deletions spec/badger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
module Badger
describe Badger do
before :each do
@badger = Badger.new "origin\thttps://github.com/doge/wow.git (fetch)\norigin\thttps://github.com/doge/wow.git (push)\n"
@badger = Badger.new "https://github.com/doge/wow.git"
end

context 'should extract the user and repo' do
it 'for a https url' do
@badger.github_path('https://github.com/doge/wow.git').should eql('doge/wow')
@badger.github_slug('https://github.com/doge/wow.git').should eql('doge/wow')
end

it 'for an ssh url' do
@badger.github_path('git@github.com:doge/wow.git').should eql('doge/wow')
@badger.github_slug('git@github.com:doge/wow.git').should eql('doge/wow')
end
end

it 'should pick out the url' do
@badger.get_url("origin\thttps://github.com/doge/wow.git (fetch)\norigin\thttps://github.com/doge/wow.git (push)\n").should eql('https://github.com/doge/wow.git')
end

it 'should generate a badge list' do
@badger.badge[0].should match /\[\!\[Build Status\]\(http:\/\/b.adge.me\/travis\/doge\/wow.svg\)\]\(https:\/\/travis-ci.org\/doge\/wow\)/
@badger.badge[1].should match /\[\!\[Coverage Status\]\(http:\/\/b.adge.me\/coveralls\/doge\/wow.svg\)\]\(https:\/\/coveralls.io\/r\/doge\/wow\)/
Expand Down

0 comments on commit b267d46

Please sign in to comment.