gem-check-sources 1.0.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 +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +41 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/gem-check-sources.gemspec +64 -0
- data/lib/gem_check_sources.rb +2 -0
- data/lib/gem_check_sources/commands/check_sources_command.rb +59 -0
- data/lib/gem_check_sources/sources.rb +88 -0
- data/lib/rubygems_plugin.rb +6 -0
- data/spec/gem_check_sources/commands/check_sources_command_spec.rb +123 -0
- data/spec/gem_check_sources/sources_spec.rb +103 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +13 -0
- metadata +106 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Britt Crawford
|
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,41 @@
|
|
1
|
+
= gem-check-sources
|
2
|
+
|
3
|
+
gem-check-sources keeps your local list of gem sources in sync and removes any gem servers that might be unavailable.
|
4
|
+
|
5
|
+
== Why?
|
6
|
+
|
7
|
+
Imagine you work at a company that hosts its own gem server within the corporate network. At work you need to install and update gems hosted on the corporate
|
8
|
+
server, but when you take your laptop home and try to work on a side project all your remote gem commands fail.
|
9
|
+
|
10
|
+
So, you end up typing 'gem sources -a' and 'gem sources -r' a lot.
|
11
|
+
|
12
|
+
gem-check-sources solves this problem by maintaining two list of gem servers (active and inactive). If a server is unavailable it gets put on the inactive list and removed from your gem sources. It will get added back when it becomes available again.
|
13
|
+
|
14
|
+
== Installation
|
15
|
+
|
16
|
+
gem install gem-check-sources
|
17
|
+
|
18
|
+
== Usage
|
19
|
+
|
20
|
+
gem check_sources
|
21
|
+
|
22
|
+
That's it. If something is inactive and you want to add it back just run the command again.
|
23
|
+
|
24
|
+
== Links
|
25
|
+
|
26
|
+
* Issue tracking: http://github.com/britt/gem-check-sources/issues
|
27
|
+
* Code Metrics: http://getcaliper.com/caliper/project?repo=git://github.com/britt/gem-check-sources.git
|
28
|
+
|
29
|
+
== Note on Patches/Pull Requests
|
30
|
+
|
31
|
+
* Fork the project.
|
32
|
+
* Make your feature addition or bug fix.
|
33
|
+
* Add tests for it. This is important so I don't break it in a
|
34
|
+
future version unintentionally.
|
35
|
+
* Commit, do not mess with rakefile, version, or history.
|
36
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
37
|
+
* Send me a pull request. Bonus points for topic branches.
|
38
|
+
|
39
|
+
== Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2010 Britt Crawford. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "gem-check-sources"
|
8
|
+
|
9
|
+
gem.summary = <<-SUMMARY
|
10
|
+
gem-check-sources keeps your local list of gem sources in sync and removes any gem servers that might be unavailable.
|
11
|
+
SUMMARY
|
12
|
+
|
13
|
+
gem.description = <<-WTF
|
14
|
+
gem-check-sources keeps your local list of gem sources in sync and removes any gem servers that might be unavailable.
|
15
|
+
WTF
|
16
|
+
|
17
|
+
gem.email = "britt.v.crawford@gmail.com"
|
18
|
+
gem.homepage = "http://github.com/britt/gem-check-sources"
|
19
|
+
gem.authors = ["Britt Crawford"]
|
20
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
21
|
+
gem.add_development_dependency "yard", ">= 0"
|
22
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
23
|
+
end
|
24
|
+
Jeweler::GemcutterTasks.new
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'spec/rake/spectask'
|
30
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
36
|
+
spec.libs << 'lib' << 'spec'
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
+
spec.rcov = true
|
39
|
+
end
|
40
|
+
|
41
|
+
task :spec => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
begin
|
46
|
+
require 'yard'
|
47
|
+
YARD::Rake::YardocTask.new
|
48
|
+
rescue LoadError
|
49
|
+
task :yardoc do
|
50
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
51
|
+
end
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,64 @@
|
|
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{gem-check-sources}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Britt Crawford"]
|
12
|
+
s.date = %q{2010-04-19}
|
13
|
+
s.description = %q{gem-check-sources keeps your local list of gem sources in sync and removes any gem servers that might be unavailable.
|
14
|
+
}
|
15
|
+
s.email = %q{britt.v.crawford@gmail.com}
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"gem-check-sources.gemspec",
|
28
|
+
"lib/gem_check_sources.rb",
|
29
|
+
"lib/gem_check_sources/commands/check_sources_command.rb",
|
30
|
+
"lib/gem_check_sources/sources.rb",
|
31
|
+
"lib/rubygems_plugin.rb",
|
32
|
+
"spec/gem_check_sources/commands/check_sources_command_spec.rb",
|
33
|
+
"spec/gem_check_sources/sources_spec.rb",
|
34
|
+
"spec/spec.opts",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/britt/gem-check-sources}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.6}
|
41
|
+
s.summary = %q{gem-check-sources keeps your local list of gem sources in sync and removes any gem servers that might be unavailable.}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/gem_check_sources/commands/check_sources_command_spec.rb",
|
44
|
+
"spec/gem_check_sources/sources_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
57
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
61
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems/command'
|
2
|
+
|
3
|
+
module Gem
|
4
|
+
module Commands
|
5
|
+
class CheckSourcesCommand < Gem::Command
|
6
|
+
include Gem::Sources
|
7
|
+
|
8
|
+
def self.sources_file
|
9
|
+
File.join(ENV['HOME'], '.gem', 'ruby', 'sources.yml')
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
super('check_sources', 'Check which gem sources are currently available.')
|
14
|
+
defaults.merge!(:sources_to_add => [], :sources_to_remove => [], :verbose? => false)
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute
|
18
|
+
if File.exist?(CheckSourcesCommand.sources_file)
|
19
|
+
check_sources
|
20
|
+
else
|
21
|
+
initialize_sources
|
22
|
+
end
|
23
|
+
list
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize_sources
|
27
|
+
@sources = List.new(:unchecked => currently_loaded_sources)
|
28
|
+
@sources.verify
|
29
|
+
@sources.sync
|
30
|
+
@sources.dump(CheckSourcesCommand.sources_file)
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_sources
|
34
|
+
sources.unchecked.concat(currently_loaded_sources)
|
35
|
+
sources.verify
|
36
|
+
sources.sync
|
37
|
+
sources.dump(CheckSourcesCommand.sources_file)
|
38
|
+
end
|
39
|
+
|
40
|
+
def list
|
41
|
+
puts "*** CURRENT SOURCES ***"
|
42
|
+
puts ""
|
43
|
+
puts "** ACTIVE SOURCES **"
|
44
|
+
puts ""
|
45
|
+
sources.active.each { |source| puts source }
|
46
|
+
puts ""
|
47
|
+
puts "** INACTIVE SOURCES **"
|
48
|
+
puts ""
|
49
|
+
sources.inactive.each { |source| puts source }
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def sources
|
55
|
+
@sources ||= Gem::Sources::List.load_file(CheckSourcesCommand.sources_file)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Gem
|
5
|
+
module Sources
|
6
|
+
def currently_loaded_sources
|
7
|
+
`gem sources`.split("\n").select { |s| /http/ =~ s }
|
8
|
+
end
|
9
|
+
|
10
|
+
class List
|
11
|
+
include Gem::Sources
|
12
|
+
|
13
|
+
attr_accessor :active, :inactive, :unchecked
|
14
|
+
|
15
|
+
def self.load_file(file_name)
|
16
|
+
List.new(YAML.load_file(file_name))
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(sources = {})
|
20
|
+
self.active = sources[:active] || []
|
21
|
+
self.inactive = sources[:inactive] || []
|
22
|
+
self.unchecked = sources[:unchecked] || []
|
23
|
+
end
|
24
|
+
|
25
|
+
def verify
|
26
|
+
@active, @inactive = all.partition { |source| source_available?(source) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def sync
|
30
|
+
current_sources = currently_loaded_sources
|
31
|
+
(active - current_sources).each { |source| add_system_source(source) }
|
32
|
+
(inactive & current_sources).each { |source| remove_system_source(source) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def add(source)
|
36
|
+
available = source_available?(source)
|
37
|
+
if available
|
38
|
+
self.active << source
|
39
|
+
else
|
40
|
+
self.inactive << source
|
41
|
+
end
|
42
|
+
available
|
43
|
+
end
|
44
|
+
|
45
|
+
def remove(source)
|
46
|
+
[@active, @unchecked, @inactive].each { |list| list.delete(source) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def all
|
50
|
+
(active + inactive + unchecked).uniq
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_h
|
54
|
+
{:active => active, :inactive => inactive}
|
55
|
+
end
|
56
|
+
|
57
|
+
def dump(file_name)
|
58
|
+
File.open(file_name, 'w') do |sources_file|
|
59
|
+
YAML.dump(to_h, sources_file)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def size
|
64
|
+
all.size
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def source_available?(host)
|
70
|
+
uri = URI.parse(host)
|
71
|
+
gemspec_path = uri.path[-1,1] == '/' ? "specs.4.8.gz" : "/specs.4.8.gz"
|
72
|
+
response = nil
|
73
|
+
Net::HTTP.start(uri.host, uri.port) {|http| response = http.head(uri.path + gemspec_path)}
|
74
|
+
response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPFound) || response.is_a?(Net::HTTPNotModified)
|
75
|
+
rescue
|
76
|
+
false
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_system_source(source)
|
80
|
+
system("gem source -a #{source}")
|
81
|
+
end
|
82
|
+
|
83
|
+
def remove_system_source(source)
|
84
|
+
system("gem source -r #{source}")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Gem::Commands::CheckSourcesCommand do
|
4
|
+
include Gem::Sources
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
$stdout = StringIO.new
|
8
|
+
# Dump the sources file in a temp dir so its easy to clean up.
|
9
|
+
@test_sources_file = Dir.tmpdir + "/test_gem_sources.yml"
|
10
|
+
Gem::Commands::CheckSourcesCommand.stub!(:sources_file).and_return(@test_sources_file)
|
11
|
+
|
12
|
+
@command = Gem::Commands::CheckSourcesCommand.new
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:each) do
|
16
|
+
File.delete(@test_sources_file) if File.exist?(@test_sources_file)
|
17
|
+
end
|
18
|
+
|
19
|
+
def stub_system_gem_sources_command(command, sources)
|
20
|
+
command.stub!(:currently_loaded_sources).and_return(sources)
|
21
|
+
end
|
22
|
+
|
23
|
+
def stub_source_checking(command, list, &block)
|
24
|
+
list.stub!(:source_available?, &block)
|
25
|
+
Gem::Sources::List.stub!(:new).and_return(list)
|
26
|
+
command.stub!(:sources).and_return(list)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "check" do
|
30
|
+
context "when the sources file does not exist" do
|
31
|
+
before(:each) do
|
32
|
+
@sources = ['http://active.example.com','http://inactive.example.com']
|
33
|
+
stub_system_gem_sources_command(@command, @sources)
|
34
|
+
|
35
|
+
@list = Gem::Sources::List.new(:unchecked => @sources)
|
36
|
+
stub_source_checking(@command, @list) { |source| source == 'http://active.example.com' }
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should create ~/.gem/ruby/sources.yml" do
|
40
|
+
@list.stub!(:sync)
|
41
|
+
@command.invoke
|
42
|
+
File.exist?(@test_sources_file).should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should add all of the existing sources" do
|
46
|
+
@list.stub!(:sync)
|
47
|
+
@command.invoke
|
48
|
+
sources = Gem::Sources::List.load_file(@test_sources_file)
|
49
|
+
@sources.each do |source|
|
50
|
+
sources.all.should include(source)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should add unavailable sources to the inactive list" do
|
55
|
+
@list.stub!(:sync)
|
56
|
+
@command.invoke
|
57
|
+
sources = Gem::Sources::List.load_file(@test_sources_file)
|
58
|
+
sources.active.should == ['http://active.example.com']
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should add available sources to the active list" do
|
62
|
+
@list.stub!(:sync)
|
63
|
+
@command.invoke
|
64
|
+
sources = Gem::Sources::List.load_file(@test_sources_file)
|
65
|
+
sources.inactive.should == ['http://inactive.example.com']
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should synchronize the system source list with the available sources" do
|
69
|
+
@list.should_receive(:sync).once
|
70
|
+
@command.invoke
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when the sources file already exists" do
|
75
|
+
def invoke_with_stubbed_synchronization
|
76
|
+
@initial_list.stub!(:sync)
|
77
|
+
@command.invoke
|
78
|
+
@list = Gem::Sources::List.load_file(@test_sources_file)
|
79
|
+
end
|
80
|
+
|
81
|
+
before(:each) do
|
82
|
+
#Create a source list
|
83
|
+
@sources = ['http://active.example.com','http://inactive.example.com', 'http://another.example.com']
|
84
|
+
@initial_list = Gem::Sources::List.new(:active => ['http://active.example.com'], :inactive => ['http://inactive.example.com'])
|
85
|
+
@initial_list.dump(Gem::Commands::CheckSourcesCommand.sources_file)
|
86
|
+
|
87
|
+
stub_system_gem_sources_command(@command, @sources)
|
88
|
+
stub_source_checking(@command, @initial_list) { |source| source == 'http://active.example.com' }
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should load the sources list from ~/.gem/ruby/sources.yml" do
|
92
|
+
invoke_with_stubbed_synchronization
|
93
|
+
@list.all.should include('http://active.example.com')
|
94
|
+
@list.all.should include('http://inactive.example.com')
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should should add any new sources that have been added using 'gem source add'" do
|
98
|
+
invoke_with_stubbed_synchronization
|
99
|
+
@list.all.should include('http://another.example.com')
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should add unavailable sources to the inactive list" do
|
103
|
+
invoke_with_stubbed_synchronization
|
104
|
+
@list.inactive.sort.should == ['http://inactive.example.com', 'http://another.example.com'].sort
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should add available sources to the active list" do
|
108
|
+
invoke_with_stubbed_synchronization
|
109
|
+
@list.active.should == ['http://active.example.com']
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should add sources to the list only once" do
|
113
|
+
invoke_with_stubbed_synchronization
|
114
|
+
@list.all.should == @list.all.uniq
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should synchronize the system source list with the available sources" do
|
118
|
+
@initial_list.should_receive(:sync).once
|
119
|
+
@command.invoke
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Gem::Sources do
|
4
|
+
include Gem::Sources
|
5
|
+
|
6
|
+
describe "#currently_loaded_sources" do
|
7
|
+
it "should load all of the sources from 'gem sources'" do
|
8
|
+
currently_loaded_sources.should == `gem sources`.split("\n").select { |s| /http/ =~ s }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Gem::Sources::List do
|
13
|
+
before(:each) do
|
14
|
+
@sources = {
|
15
|
+
:active => ['http://active.example.com'],
|
16
|
+
:inactive => ['http://inactive.example.com']
|
17
|
+
}
|
18
|
+
@list = Gem::Sources::List.new(@sources)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "##load_file" do
|
22
|
+
it "should load the given YAML" do
|
23
|
+
@test_sources_file = Dir.tmpdir + "/test_gem_sources.yml"
|
24
|
+
File.open(@test_sources_file, 'w+') {|out| YAML.dump(@sources, out) }
|
25
|
+
|
26
|
+
file_list = Gem::Sources::List.load_file(@test_sources_file)
|
27
|
+
file_list.active.should == @list.active
|
28
|
+
file_list.inactive.should == @list.inactive
|
29
|
+
|
30
|
+
File.delete @test_sources_file
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#all" do
|
35
|
+
it "should include both active and inactive sources" do
|
36
|
+
@list.all.sort.should == ['http://active.example.com', 'http://inactive.example.com'].sort
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#to_h" do
|
41
|
+
it "should serialize to a hash" do
|
42
|
+
@list.to_h.should == @sources
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#dump" do
|
47
|
+
it "should dump the hash representation to the given file" do
|
48
|
+
io = mock('FILE')
|
49
|
+
File.stub(:open).and_yield(io)
|
50
|
+
YAML.should_receive(:dump).once.with(@list.to_h, io)
|
51
|
+
@list.dump('file')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#verify" do
|
56
|
+
it "should check all sources" do
|
57
|
+
@list.should_receive(:source_available?).exactly(@list.size).times.and_return(true)
|
58
|
+
@list.verify
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should sort the sources into active and inactive" do
|
62
|
+
@list.stub!(:source_available?).and_return(true, false)
|
63
|
+
@list.verify
|
64
|
+
@list.active.should_not be_empty
|
65
|
+
@list.inactive.should_not be_empty
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#add" do
|
70
|
+
it "should check if the source is available it to the appropriate list" do
|
71
|
+
@list.stub!(:source_available?).and_return(false)
|
72
|
+
@list.add('http://yas.example.com')
|
73
|
+
@list.inactive.should include('http://yas.example.com')
|
74
|
+
@list.active.should_not include('http://yas.example.com')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#remove" do
|
79
|
+
it "should remove the source from all lists" do
|
80
|
+
@list.remove('http://active.example.com')
|
81
|
+
@list.all.should_not include('http://active.example.com')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#sync" do
|
86
|
+
before(:each) do
|
87
|
+
@list.stub!(:currently_loaded_sources).and_return(['http://inactive.example.com'])
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should add all active sources that are not currently loaded" do
|
91
|
+
@list.should_receive(:add_system_source).once.with('http://active.example.com')
|
92
|
+
@list.stub!(:remove_system_source)
|
93
|
+
@list.sync
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should remove any inactive sources that are currently loaded" do
|
97
|
+
@list.should_receive(:remove_system_source).once.with('http://inactive.example.com')
|
98
|
+
@list.stub!(:add_system_source)
|
99
|
+
@list.sync
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'gem_check_sources'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
require 'pp'
|
7
|
+
require 'tmpdir'
|
8
|
+
|
9
|
+
ENV['QUIET'] = 'true'
|
10
|
+
|
11
|
+
Spec::Runner.configure do |config|
|
12
|
+
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-check-sources
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Britt Crawford
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-19 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
31
|
+
version: 1.2.9
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: yard
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
description: |
|
47
|
+
gem-check-sources keeps your local list of gem sources in sync and removes any gem servers that might be unavailable.
|
48
|
+
|
49
|
+
email: britt.v.crawford@gmail.com
|
50
|
+
executables: []
|
51
|
+
|
52
|
+
extensions: []
|
53
|
+
|
54
|
+
extra_rdoc_files:
|
55
|
+
- LICENSE
|
56
|
+
- README.rdoc
|
57
|
+
files:
|
58
|
+
- .document
|
59
|
+
- .gitignore
|
60
|
+
- LICENSE
|
61
|
+
- README.rdoc
|
62
|
+
- Rakefile
|
63
|
+
- VERSION
|
64
|
+
- gem-check-sources.gemspec
|
65
|
+
- lib/gem_check_sources.rb
|
66
|
+
- lib/gem_check_sources/commands/check_sources_command.rb
|
67
|
+
- lib/gem_check_sources/sources.rb
|
68
|
+
- lib/rubygems_plugin.rb
|
69
|
+
- spec/gem_check_sources/commands/check_sources_command_spec.rb
|
70
|
+
- spec/gem_check_sources/sources_spec.rb
|
71
|
+
- spec/spec.opts
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/britt/gem-check-sources
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --charset=UTF-8
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.3.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: gem-check-sources keeps your local list of gem sources in sync and removes any gem servers that might be unavailable.
|
103
|
+
test_files:
|
104
|
+
- spec/gem_check_sources/commands/check_sources_command_spec.rb
|
105
|
+
- spec/gem_check_sources/sources_spec.rb
|
106
|
+
- spec/spec_helper.rb
|