hubless 0.1.0

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Greg Sterndale
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,11 @@
1
+ = hubless
2
+
3
+ Search your local gem repository for gems installed from GitHub that have since moved to Gemcutter and get instructions on how to reinstall them.
4
+
5
+ == Command line usage
6
+
7
+ $ hubless
8
+
9
+ == Copyright
10
+
11
+ Copyright (c) 2010 Greg Sterndale. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "hubless"
8
+ gem.summary = %Q{Search your local gem repository for gems installed from GitHub that have since moved to Gemcutter}
9
+ gem.description = %Q{Search your local gem repository for gems installed from GitHub that have since moved to Gemcutter}
10
+ gem.email = "greg@plectix.com"
11
+ gem.homepage = "http://github.com/gsterndale/hubless"
12
+ gem.authors = ["Greg Sterndale"]
13
+ gem.add_development_dependency "mocha", ">= 0.9.1"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "hubless #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/hubless ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'application'
4
+
5
+ exit Hubless::Application.run(*ARGV)
data/hubless.gemspec ADDED
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{hubless}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Greg Sterndale"]
12
+ s.date = %q{2010-01-17}
13
+ s.default_executable = %q{hubless}
14
+ s.description = %q{Search your local gem repository for gems installed from GitHub that have since moved to Gemcutter}
15
+ s.email = %q{greg@plectix.com}
16
+ s.executables = ["hubless"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/hubless",
29
+ "hubless.gemspec",
30
+ "lib/application.rb",
31
+ "lib/gem_description.rb",
32
+ "lib/hubless.rb",
33
+ "test/helper.rb",
34
+ "test/test_application.rb",
35
+ "test/test_gem_description.rb",
36
+ "test/test_hubless.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/gsterndale/hubless}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.5}
42
+ s.summary = %q{Search your local gem repository for gems installed from GitHub that have since moved to Gemcutter}
43
+ s.test_files = [
44
+ "test/helper.rb",
45
+ "test/test_application.rb",
46
+ "test/test_gem_description.rb",
47
+ "test/test_hubless.rb"
48
+ ]
49
+
50
+ if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
52
+ s.specification_version = 3
53
+
54
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
+ s.add_development_dependency(%q<mocha>, [">= 0.9.1"])
56
+ else
57
+ s.add_dependency(%q<mocha>, [">= 0.9.1"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<mocha>, [">= 0.9.1"])
61
+ end
62
+ end
63
+
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/hubless'
2
+
3
+ class Hubless
4
+ class Application
5
+
6
+ def self.run(*args)
7
+ hubless = Hubless.new
8
+ hubless.gem_breakdown
9
+ hubless.github_repos
10
+ hubless.gemcutter_gems
11
+ hubless.uninstall_instructions
12
+ hubless.install_instructions
13
+ return 0
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,142 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+
4
+ class Hubless
5
+ ServiceError = Class.new(RuntimeError)
6
+
7
+ class GemDescription
8
+
9
+ attr_reader :name
10
+ attr_accessor :version
11
+
12
+ # GemDescriptions of all gems installed locally
13
+ def self.local_gems
14
+ @@local_gems ||= Gem.cache.map {|g| new(g.first) }.sort!{|x,y| y.name <=> x.name }
15
+ end
16
+
17
+ # New GemDescription from a one-liner or options Hash
18
+ # Hubless::GemDescription.new('my-awesome_gem-3.4.5')
19
+ # Hubless::GemDescription.new(:name => 'my-awesome_gem', :version => '3.4.5')
20
+ def initialize(*args)
21
+ case args.first
22
+ when String
23
+ self.attributes_from_one_liner(args.first)
24
+ when Hash
25
+ self.name = args.first[:name]
26
+ self.version = args.first[:version]
27
+ end
28
+ end
29
+
30
+ # Assign gem description name and clear any cached values
31
+ def name=(str)
32
+ self.clear
33
+ @name = str
34
+ end
35
+
36
+ # Does a repo exist on GitHub that matches this gem
37
+ def github?
38
+ if @is_github.nil?
39
+ @is_github = (self.github_like? && self.github_repo_exist?)
40
+ else
41
+ @is_github
42
+ end
43
+ end
44
+
45
+ # Full name of this gem including GitHub username
46
+ def github_name
47
+ self.name if self.github_user_name
48
+ end
49
+
50
+ def github_like?
51
+ self.github_user_name && self.github_repo_name
52
+ end
53
+
54
+ # Does a gem exist on Gemcutter that matches this gem
55
+ def gemcutter?
56
+ if @is_gemcutter.nil?
57
+ @is_gemcutter = self.gemcutter_gem_exist?
58
+ else
59
+ @is_gemcutter
60
+ end
61
+ end
62
+
63
+ # Likely name of this gem on Gemcutter (without the GitHub username)
64
+ def gemcutter_name
65
+ self.github? ? self.github_repo_name : self.name
66
+ end
67
+
68
+ # Command to install gem from Gemcutter
69
+ def install_cmd
70
+ cmd = ["gem install"]
71
+ cmd << self.gemcutter_name
72
+ cmd << "-v #{self.version}" if self.version
73
+ cmd.join(' ')
74
+ end
75
+
76
+ # Command to uninstall gem
77
+ def uninstall_cmd
78
+ cmd = ["gem uninstall"]
79
+ cmd << self.name
80
+ cmd << "-v #{self.version}" if self.version
81
+ cmd.join(' ')
82
+ end
83
+
84
+ protected
85
+
86
+ def clear
87
+ @is_gemcutter = @is_github = nil
88
+ end
89
+
90
+ def github_user_name
91
+ if self.name =~ /^([^-]*)-.*$/
92
+ $1
93
+ end
94
+ end
95
+
96
+ def github_repo_name
97
+ if self.name =~ /^[^-]*-(.*)$/
98
+ $1
99
+ end
100
+ end
101
+
102
+ def github_uri
103
+ URI.parse("http://github.com/api/v2/yaml/repos/show/#{self.github_user_name}/#{self.github_repo_name}")
104
+ end
105
+
106
+ def github_repo_exist?
107
+ response = Net::HTTP.get(self.github_uri)
108
+ case
109
+ when response =~ /error: repository not found/
110
+ false
111
+ when response =~ /error: too many requests/
112
+ raise ServiceError
113
+ else
114
+ true
115
+ end
116
+ end
117
+
118
+ def gemcutter_uri
119
+ URI.parse("http://gemcutter.org/api/v1/gems/#{self.name}.json")
120
+ end
121
+
122
+ def gemcutter_gem_exist?
123
+ response = Net::HTTP.get(self.gemcutter_uri)
124
+ case
125
+ when response =~ /This rubygem could not be found./
126
+ false
127
+ when response =~ /error: too many requests/
128
+ raise ServiceError
129
+ else
130
+ true
131
+ end
132
+ end
133
+
134
+ def attributes_from_one_liner(one_liner)
135
+ if one_liner =~ /^(.*)-([\d\.]+)$/
136
+ self.name = $1
137
+ self.version = $2
138
+ end
139
+ end
140
+
141
+ end
142
+ end
data/lib/hubless.rb ADDED
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__) + '/gem_description'
2
+
3
+ class Hubless
4
+ @@io = $stdout
5
+ @@timeout = 1
6
+
7
+ def self.io=(io)
8
+ @@io = io
9
+ end
10
+
11
+ def self.timeout=(t)
12
+ @@timeout = t
13
+ end
14
+
15
+ def gem_breakdown
16
+ github_like_count = self.gems.select{|g| g.github_like? }.length
17
+ @@io.puts "\nFound #{gems.length} local gems. Of those, #{github_like_count} look like GitHub gems."
18
+ end
19
+
20
+ def github_repos
21
+ @@io.puts("\nSearching GitHub for matching repositories...")
22
+ github_gem_count = 0
23
+ self.gems.each do |g|
24
+ if g.github_like?
25
+ github_gem_count += 1 if is_on_github = g.github?
26
+ @@io.print(is_on_github ? 'Y' : 'N')
27
+ @@io.flush
28
+ sleep @@timeout
29
+ end
30
+ end
31
+ @@io.puts("\nFound #{github_gem_count} repositories on GitHub.")
32
+ end
33
+
34
+ def gemcutter_gems
35
+ @@io.puts("\nSearching for matching gems on Gemcutter...")
36
+ gemcutter_gem_count = 0
37
+ self.gems.each do |g|
38
+ if g.github?
39
+ gemcutter_gem_count += 1 if is_on_gemcutter = g.gemcutter?
40
+ @@io.print(is_on_gemcutter ? 'Y' : 'N')
41
+ @@io.flush
42
+ sleep @@timeout
43
+ end
44
+ end
45
+ @@io.puts("\nFound #{gemcutter_gem_count} gems on Gemcutter.")
46
+ end
47
+
48
+ def uninstall_instructions
49
+ @@io.puts("\nTo uninstall these GitHub gems run:")
50
+ self.gems.each {|g| @@io.puts(g.uninstall_cmd) if g.github? && g.gemcutter? }
51
+ end
52
+
53
+ def install_instructions
54
+ @@io.puts("\nTo reinstall these gems from Gemcutter run:")
55
+ self.gems.each {|g| @@io.puts(g.install_cmd) if g.github? && g.gemcutter? }
56
+ end
57
+
58
+ # def self.reinstall_gems
59
+ # self.gems.each do |g|
60
+ # if g.github? && g.gemcutter?
61
+ # @@io.puts %x(#{g.uninstall_cmd})
62
+ # @@io.puts %x(#{g.install_cmd})
63
+ # end
64
+ # end
65
+ # end
66
+
67
+ protected
68
+
69
+ def gems
70
+ @gems ||= Hubless::GemDescription.local_gems
71
+ end
72
+
73
+ end
74
+
75
+ # Hubless.local_gems_on_github.each{|g| puts g.inspect }
data/test/helper.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'ruby-debug'
4
+ require 'mocha'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ require 'hubless'
9
+ require 'application'
10
+
11
+ class Test::Unit::TestCase
12
+
13
+ def expect_no_request
14
+ Net::HTTP.expects(:get).never
15
+ end
16
+
17
+ def expect_github_request(uri_regex, exist, error=false)
18
+ Net::HTTP.expects(:get).
19
+ once.
20
+ with{|uri| uri.to_s =~ uri_regex }.
21
+ returns case
22
+ when error
23
+ "--- \nerror: \n- error: too many requests\n"
24
+ when exist
25
+ "--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n"
26
+ else
27
+ "--- \nerror: \n- error: repository not found\n"
28
+ end
29
+ end
30
+
31
+ def expect_gemcutter_request(uri_regex, exist, error=false)
32
+ Net::HTTP.expects(:get).
33
+ once.
34
+ with{|uri| uri.to_s =~ uri_regex }.
35
+ returns case
36
+ when error
37
+ "Error"
38
+ when exist
39
+ %Q{{"version_downloads":137674,"info":" Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick\n on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.\n","project_uri":"http://gemcutter.org/gems/rails","name":"rails","version":"2.3.5","gem_uri":"http://gemcutter.org/gems/rails-2.3.5.gem","downloads":218523,"authors":"David Heinemeier Hansson"}}
40
+ else
41
+ "This rubygem could not be found."
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ class TestApplication < Test::Unit::TestCase
4
+
5
+ def test_run
6
+ hubless = mock(
7
+ :gem_breakdown => true,
8
+ :github_repos => true,
9
+ :gemcutter_gems => true,
10
+ :uninstall_instructions => true,
11
+ :install_instructions => true
12
+ )
13
+ Hubless.expects(:new).returns(hubless)
14
+ Hubless::Application.run
15
+ end
16
+
17
+ end
@@ -0,0 +1,218 @@
1
+ require 'helper'
2
+
3
+ class TestGemDescription < Test::Unit::TestCase
4
+
5
+ def test_local_gems
6
+ gems = [
7
+ [ 'my-github_and_gemcutter_gem-0.1.2', mock ],
8
+ [ 'my-github_only_gem-1.2.3', mock ],
9
+ [ 'my-github_look_a_like_on_gemcutter_gem-2.3.4', mock ],
10
+ [ 'my_non_github_gem-3.4.5', mock ]
11
+ ]
12
+ Gem.expects(:cache).once.returns(gems)
13
+ local_gems = Hubless::GemDescription.local_gems
14
+ assert local_gems.all?{|gem_description| gem_description.is_a?(Hubless::GemDescription) }
15
+ assert local_gems.detect{|gem_description| gem_description.name == 'my-github_and_gemcutter_gem' }
16
+ assert local_gems.detect{|gem_description| gem_description.name == 'my-github_only_gem' }
17
+ assert local_gems.detect{|gem_description| gem_description.name == 'my-github_look_a_like_on_gemcutter_gem' }
18
+ assert local_gems.detect{|gem_description| gem_description.name == 'my_non_github_gem' }
19
+ assert_equal gems.length, local_gems.length
20
+ # test number of expected calls to Gem.cache are not exceeded
21
+ Hubless::GemDescription.local_gems
22
+ end
23
+
24
+ def test_new_with_one_liner
25
+ one_liner = 'my-github_and_gemcutter_gem-0.1.2'
26
+ gem_description = Hubless::GemDescription.new(one_liner)
27
+ assert_equal 'my-github_and_gemcutter_gem', gem_description.name
28
+ assert_equal '0.1.2', gem_description.version
29
+ end
30
+
31
+ def test_new_with_attr_hash
32
+ name = 'my-github_and_gemcutter_gem'
33
+ version = '0.1.2'
34
+ gem_description = Hubless::GemDescription.new(:name => name, :version => version)
35
+ assert_equal name, gem_description.name
36
+ assert_equal version, gem_description.version
37
+ end
38
+
39
+ def test_name_attr
40
+ name = 'my-github_and_gemcutter_gem'
41
+ gem_description = Hubless::GemDescription.new
42
+ gem_description.name = name
43
+ assert_equal name, gem_description.name
44
+ end
45
+
46
+ def test_github_name
47
+ user = 'my'
48
+ repo = 'github_and_gemcutter_gem'
49
+ name = "#{user}-#{repo}"
50
+ gem_description = Hubless::GemDescription.new(:name => name)
51
+ assert_equal name, gem_description.github_name
52
+
53
+ name = 'non_github_gem'
54
+ gem_description = Hubless::GemDescription.new(:name => name)
55
+ assert_nil gem_description.github_name
56
+ end
57
+
58
+ def test_github_like?
59
+ user = 'my'
60
+ repo = 'github_and_gemcutter_gem'
61
+ name = "#{user}-#{repo}"
62
+ gem_description = Hubless::GemDescription.new(:name => name)
63
+ assert gem_description.github_like?
64
+
65
+ name = 'non_github_gem'
66
+ gem_description = Hubless::GemDescription.new(:name => name)
67
+ assert ! gem_description.github_like?
68
+ end
69
+
70
+ def test_gemcutter_name
71
+ user = 'my'
72
+ repo = 'github_and_gemcutter_gem'
73
+ name = "#{user}-#{repo}"
74
+ gem_description = Hubless::GemDescription.new(:name => name)
75
+ expect_github_request(/github.*\/#{repo}/, true)
76
+ assert_equal repo, gem_description.gemcutter_name
77
+
78
+ user = 'my'
79
+ repo = 'github_look_a_like_gem'
80
+ name = "#{user}-#{repo}"
81
+ gem_description = Hubless::GemDescription.new(:name => name)
82
+ expect_github_request(/github.*\/#{repo}/, false)
83
+ assert_equal name, gem_description.gemcutter_name
84
+
85
+ name = 'non_github_gem'
86
+ gem_description = Hubless::GemDescription.new(:name => name)
87
+ expect_no_request
88
+ assert_equal name, gem_description.gemcutter_name
89
+ end
90
+
91
+ def test_github?
92
+ user = 'my'
93
+ repo = 'github_gem'
94
+ name = "#{user}-#{repo}"
95
+ github_gem = Hubless::GemDescription.new(:name => name)
96
+ expect_github_request(/github.*\/#{repo}/, true)
97
+ assert github_gem.github?
98
+
99
+ user = 'my'
100
+ repo = 'github_look_a_like_gem'
101
+ name = "#{user}-#{repo}"
102
+ github_look_a_like_gem = Hubless::GemDescription.new(:name => name)
103
+ expect_github_request(/github.*\/#{repo}/, false)
104
+ assert ! github_look_a_like_gem.github?
105
+
106
+ non_github_gem = Hubless::GemDescription.new(:name => 'non_github_gem')
107
+ expect_no_request
108
+ assert ! non_github_gem.github?
109
+
110
+ user = 'my'
111
+ repo = 'one_too_many_requests'
112
+ name = "#{user}-#{repo}"
113
+ github_error_gem = Hubless::GemDescription.new(:name => name)
114
+ expect_github_request(/github.*\/#{repo}/, false, true)
115
+ assert_raise(Hubless::ServiceError) { github_error_gem.github? }
116
+ end
117
+
118
+ def test_multiple_github?
119
+ user = 'my'
120
+ repo = 'github_gem'
121
+ name = "#{user}-#{repo}"
122
+ github_gem = Hubless::GemDescription.new(:name => name)
123
+ expect_github_request(/github.*\/#{repo}/, true)
124
+ assert github_gem.github?
125
+ # tests that number of expected calls is not exceeded
126
+ expect_no_request
127
+ assert github_gem.github?
128
+
129
+ # setting name should clear cache
130
+ user = 'my'
131
+ repo = 'other_github_gem'
132
+ name = "#{user}-#{repo}"
133
+ github_gem.name = name
134
+ expect_github_request(/github.*\/#{repo}/, true)
135
+ assert github_gem.github?
136
+ end
137
+
138
+ def test_gemcutter?
139
+ name = 'my-gemcutter_gem'
140
+ gemcutter_gem = Hubless::GemDescription.new(:name => name)
141
+ expect_gemcutter_request(/gemcutter.*#{name}/, true)
142
+ assert gemcutter_gem.gemcutter?
143
+
144
+ name = 'my-non_gemcutter_gem'
145
+ non_gemcutter_gem = Hubless::GemDescription.new(:name => name)
146
+ expect_gemcutter_request(/gemcutter.*#{name}/, false)
147
+ assert ! non_gemcutter_gem.gemcutter?
148
+ end
149
+
150
+ def test_multiple_gemcutter?
151
+ name = 'my-gemcutter_gem'
152
+ gemcutter_gem = Hubless::GemDescription.new(:name => name)
153
+ expect_gemcutter_request(/gemcutter.*#{name}/, true)
154
+ assert gemcutter_gem.gemcutter?
155
+ # tests that number of expected calls is not exceeded
156
+ expect_no_request
157
+ assert gemcutter_gem.gemcutter?
158
+
159
+ # setting name should clear cache
160
+ name = 'my-other_gemcutter_gem'
161
+ gemcutter_gem.name = name
162
+ expect_gemcutter_request(/gemcutter.*#{name}/, true)
163
+ assert gemcutter_gem.gemcutter?
164
+ end
165
+
166
+ def test_install_cmd
167
+ user = 'my'
168
+ repo = 'github_gem'
169
+ name = "#{user}-#{repo}"
170
+ version = '0.1.2'
171
+ gem_description = Hubless::GemDescription.new(:name => name, :version => version)
172
+ expect_github_request(/github.*\/#{repo}/, true)
173
+ assert_equal "gem install #{repo} -v #{version}", gem_description.install_cmd
174
+
175
+ user = 'my'
176
+ repo = 'github_gem'
177
+ name = "#{user}-#{repo}"
178
+ version = nil
179
+ gem_description = Hubless::GemDescription.new(:name => name, :version => version)
180
+ expect_github_request(/github.*\/#{repo}/, true)
181
+ assert_equal "gem install #{repo}", gem_description.install_cmd
182
+
183
+ user = 'my'
184
+ repo = 'github_look_a_like_gem'
185
+ name = "#{user}-#{repo}"
186
+ version = '0.1.2'
187
+ gem_description = Hubless::GemDescription.new(:name => name, :version => version)
188
+ expect_github_request(/github.*\/#{repo}/, false)
189
+ assert_equal "gem install #{name} -v #{version}", gem_description.install_cmd
190
+ end
191
+
192
+ def test_uninstall_cmd
193
+ user = 'my'
194
+ repo = 'github_gem'
195
+ name = "#{user}-#{repo}"
196
+ version = '0.1.2'
197
+ gem_description = Hubless::GemDescription.new(:name => name, :version => version)
198
+ expect_no_request
199
+ assert_equal "gem uninstall #{name} -v #{version}", gem_description.uninstall_cmd
200
+
201
+ user = 'my'
202
+ repo = 'github_gem'
203
+ name = "#{user}-#{repo}"
204
+ version = nil
205
+ gem_description = Hubless::GemDescription.new(:name => name, :version => version)
206
+ expect_no_request
207
+ assert_equal "gem uninstall #{name}", gem_description.uninstall_cmd
208
+
209
+ user = 'my'
210
+ repo = 'github_look_a_like_gem'
211
+ name = "#{user}-#{repo}"
212
+ version = '0.1.2'
213
+ gem_description = Hubless::GemDescription.new(:name => name, :version => version)
214
+ expect_no_request
215
+ assert_equal "gem uninstall #{name} -v #{version}", gem_description.uninstall_cmd
216
+ end
217
+
218
+ end
@@ -0,0 +1,196 @@
1
+ require 'helper'
2
+
3
+ class TestHubless < Test::Unit::TestCase
4
+
5
+ def setup
6
+ Hubless.io = mock_io
7
+ Hubless.timeout = 0
8
+ end
9
+
10
+ def mock_io
11
+ @io = mock
12
+ @io.stubs(:print).returns(nil)
13
+ @io.stubs(:flush).returns(nil)
14
+ @io.stubs(:puts).returns(nil)
15
+ @io
16
+ end
17
+
18
+ def test_local_gem_breakdown
19
+ local_gems = [
20
+ mock(:github_like? => true),
21
+ mock(:github_like? => true),
22
+ mock(:github_like? => false)
23
+ ]
24
+ gem_count = 3
25
+ github_like_count = 2
26
+ Hubless::GemDescription.expects(:local_gems).once.returns(local_gems)
27
+ @io.expects(:puts).
28
+ with{|s| s =~ /Found #{gem_count} local gems. Of those, #{github_like_count} look like GitHub gems./ }
29
+ hubless = Hubless.new
30
+ hubless.gem_breakdown
31
+ end
32
+
33
+ def test_github_repos
34
+ local_gems = [
35
+ mock(:github_like? => true, :github? => true),
36
+ mock(:github_like? => true, :github? => false),
37
+ mock(:github_like? => false)
38
+ ]
39
+ github_count = 1
40
+ Hubless::GemDescription.expects(:local_gems).once.returns(local_gems)
41
+ @io.expects(:puts).with{|s| s =~ /Searching GitHub for matching repositories.../ }
42
+ @io.expects(:print).once.with('Y')
43
+ @io.expects(:print).once.with('N')
44
+ @io.expects(:flush).times(2)
45
+ @io.expects(:puts).with{|s| s =~ /Found #{github_count} repositories on GitHub./ }
46
+ hubless = Hubless.new
47
+ hubless.github_repos
48
+ end
49
+
50
+ def test_gemcutter_gems
51
+ local_gems = [
52
+ mock(:github? => true, :gemcutter? => true),
53
+ mock(:github? => true, :gemcutter? => false),
54
+ mock(:github? => false)
55
+ ]
56
+ gemcutter_count = 1
57
+ Hubless::GemDescription.expects(:local_gems).once.returns(local_gems)
58
+ @io.expects(:puts).with{|s| s =~ /Searching for matching gems on Gemcutter.../ }
59
+ @io.expects(:print).once.with('Y')
60
+ @io.expects(:print).once.with('N')
61
+ @io.expects(:flush).times(2)
62
+ @io.expects(:puts).with{|s| s =~ /Found #{gemcutter_count} gems on Gemcutter./ }
63
+ hubless = Hubless.new
64
+ hubless.gemcutter_gems
65
+ end
66
+
67
+ def test_uninstall_instructions
68
+ local_gems = [
69
+ mock(:uninstall_cmd => 'foo', :github? => true, :gemcutter? => true),
70
+ mock(:uninstall_cmd => 'bar', :github? => true, :gemcutter? => true),
71
+ mock(:uninstall_cmd => 'abc', :github? => true, :gemcutter? => true),
72
+ mock(:github? => true, :gemcutter? => false),
73
+ mock(:github? => false)
74
+ ]
75
+ Hubless::GemDescription.expects(:local_gems).once.returns(local_gems)
76
+ @io.expects(:puts).with{|s| s =~ /To uninstall these GitHub gems run:/ }
77
+ @io.expects(:puts).once.with{|s| s =~ /foo/ }
78
+ @io.expects(:puts).once.with{|s| s =~ /bar/ }
79
+ @io.expects(:puts).once.with{|s| s =~ /abc/ }
80
+ hubless = Hubless.new
81
+ hubless.uninstall_instructions
82
+ end
83
+
84
+ def test_install_instructions
85
+ local_gems = [
86
+ mock(:install_cmd => 'foo', :github? => true, :gemcutter? => true),
87
+ mock(:install_cmd => 'bar', :github? => true, :gemcutter? => true),
88
+ mock(:install_cmd => 'abc', :github? => true, :gemcutter? => true),
89
+ mock(:github? => true, :gemcutter? => false),
90
+ mock(:github? => false)
91
+ ]
92
+ Hubless::GemDescription.expects(:local_gems).once.returns(local_gems)
93
+ @io.expects(:puts).with{|s| s =~ /To reinstall these gems from Gemcutter run:/ }
94
+ @io.expects(:puts).once.with{|s| s =~ /foo/ }
95
+ @io.expects(:puts).once.with{|s| s =~ /bar/ }
96
+ @io.expects(:puts).once.with{|s| s =~ /abc/ }
97
+ hubless = Hubless.new
98
+ hubless.install_instructions
99
+ end
100
+
101
+
102
+ # def setup
103
+ # @gems = [
104
+ # [ 'my-github_and_gemcutter_gem-0.1.2', mock ],
105
+ # [ 'my-github_only_gem-1.2.3', mock ],
106
+ # [ 'my-github_look_a_like_on_gemcutter_gem-2.3.4', mock ],
107
+ # [ 'my_non_github_gem-3.4.5', mock ]
108
+ # ]
109
+ # Gem.stubs(:cache).returns(@gems)
110
+ # end
111
+ #
112
+ # def teardown
113
+ # Hubless.clear
114
+ # end
115
+ #
116
+ # def test_local_gems
117
+ # local_gems = Hubless.local_gems
118
+ # assert local_gems.detect{|gem_description| gem_description.name == 'my-github_and_gemcutter_gem' }
119
+ # assert local_gems.detect{|gem_description| gem_description.name == 'my-github_only_gem' }
120
+ # assert local_gems.detect{|gem_description| gem_description.name == 'my-github_look_a_like_on_gemcutter_gem' }
121
+ # assert local_gems.detect{|gem_description| gem_description.name == 'my_non_github_gem' }
122
+ # assert_equal @gems.length, local_gems.length
123
+ # end
124
+ #
125
+ # def test_local_github_like_gems
126
+ # local_github_like_gems = Hubless.local_github_like_gems
127
+ # assert local_github_like_gems.detect{|gem_description| gem_description.name == 'my-github_and_gemcutter_gem' }
128
+ # assert local_github_like_gems.detect{|gem_description| gem_description.name == 'my-github_only_gem' }
129
+ # assert local_github_like_gems.detect{|gem_description| gem_description.name == 'my-github_look_a_like_on_gemcutter_gem' }
130
+ # assert ! local_github_like_gems.detect{|gem_description| gem_description.name == 'my_non_github_gem' }
131
+ # end
132
+ #
133
+ # def test_local_gems_on_github
134
+ # Net::HTTP.expects(:get).times(3).
135
+ # returns("--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n").
136
+ # returns("--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n").
137
+ # returns("--- \nerror: \n- error: repository not found\n")
138
+ # local_gems_on_github = Hubless.local_gems_on_github
139
+ # assert local_gems_on_github.detect{|gem_description| gem_description.name == 'my-github_and_gemcutter_gem' }
140
+ # assert local_gems_on_github.detect{|gem_description| gem_description.name == 'my-github_only_gem' }
141
+ # assert ! local_gems_on_github.detect{|gem_description| gem_description.name == 'my-github_look_a_like_on_gemcutter_gem' }
142
+ # assert ! local_gems_on_github.detect{|gem_description| gem_description.name == 'my_non_github_gem' }
143
+ # end
144
+ #
145
+ # def test_local_gems_on_github_with_github_error
146
+ # Net::HTTP.expects(:get).times(2).
147
+ # returns("--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n").
148
+ # returns("--- \nerror: \n- error: too many requests\n")
149
+ # assert_raise(ServiceError) { Hubless.local_gems_on_github }
150
+ # end
151
+ #
152
+ # def test_local_gems_on_github_and_gemcutter
153
+ # Net::HTTP.expects(:get).times(5).
154
+ # returns("--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n").
155
+ # returns("--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n").
156
+ # returns("--- \nerror: \n- error: repository not found\n").
157
+ # returns(%Q{{"version_downloads":137674,"info":" Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick\n on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.\n","project_uri":"http://gemcutter.org/gems/rails","name":"rails","version":"2.3.5","gem_uri":"http://gemcutter.org/gems/rails-2.3.5.gem","downloads":218523,"authors":"David Heinemeier Hansson"}}).
158
+ # returns("This rubygem could not be found.")
159
+ # local_gems_on_github_and_gemcutter = Hubless.local_gems_on_github_and_gemcutter
160
+ # assert local_gems_on_github_and_gemcutter.detect{|gem_description| gem_description.name == 'my-github_and_gemcutter_gem' }
161
+ # assert ! local_gems_on_github_and_gemcutter.detect{|gem_description| gem_description.name == 'my-github_only_gem' }
162
+ # assert ! local_gems_on_github_and_gemcutter.detect{|gem_description| gem_description.name == 'my-github_look_a_like_on_gemcutter_gem' }
163
+ # assert ! local_gems_on_github_and_gemcutter.detect{|gem_description| gem_description.name == 'my_non_github_gem' }
164
+ # end
165
+ #
166
+ # def test_clear
167
+ # Net::HTTP.expects(:get).times(5).
168
+ # returns("--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n").
169
+ # returns("--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n").
170
+ # returns("--- \nerror: \n- error: repository not found\n").
171
+ # returns(%Q{{"version_downloads":137674,"info":" Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick\n on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.\n","project_uri":"http://gemcutter.org/gems/rails","name":"rails","version":"2.3.5","gem_uri":"http://gemcutter.org/gems/rails-2.3.5.gem","downloads":218523,"authors":"David Heinemeier Hansson"}}).
172
+ # returns("This rubygem could not be found.")
173
+ #
174
+ # Hubless.local_gems_on_github_and_gemcutter
175
+ #
176
+ # Net::HTTP.expects(:get).times(0)
177
+ #
178
+ # Hubless.local_gems_on_github_and_gemcutter
179
+ #
180
+ # Hubless.clear
181
+ #
182
+ # Net::HTTP.expects(:get).times(5).
183
+ # returns("--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n").
184
+ # returns("--- \nrepository: \n :description: Description here\n :forks: 0\n :url: http://github.com/some_user/some_repo\n :fork: false\n :open_issues: 0\n :watchers: 1\n :private: false\n :name: some_repo\n :owner: some_user\n").
185
+ # returns("--- \nerror: \n- error: repository not found\n").
186
+ # returns(%Q{{"version_downloads":137674,"info":" Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick\n on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.\n","project_uri":"http://gemcutter.org/gems/rails","name":"rails","version":"2.3.5","gem_uri":"http://gemcutter.org/gems/rails-2.3.5.gem","downloads":218523,"authors":"David Heinemeier Hansson"}}).
187
+ # returns("This rubygem could not be found.")
188
+ #
189
+ # Hubless.local_gems_on_github_and_gemcutter
190
+ # end
191
+ def test_nothin
192
+ assert true
193
+ end
194
+
195
+
196
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hubless
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Greg Sterndale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-17 00:00:00 -05:00
13
+ default_executable: hubless
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mocha
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.1
24
+ version:
25
+ description: Search your local gem repository for gems installed from GitHub that have since moved to Gemcutter
26
+ email: greg@plectix.com
27
+ executables:
28
+ - hubless
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - bin/hubless
42
+ - hubless.gemspec
43
+ - lib/application.rb
44
+ - lib/gem_description.rb
45
+ - lib/hubless.rb
46
+ - test/helper.rb
47
+ - test/test_application.rb
48
+ - test/test_gem_description.rb
49
+ - test/test_hubless.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/gsterndale/hubless
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.5
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Search your local gem repository for gems installed from GitHub that have since moved to Gemcutter
78
+ test_files:
79
+ - test/helper.rb
80
+ - test/test_application.rb
81
+ - test/test_gem_description.rb
82
+ - test/test_hubless.rb