gem-manage-sources 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,6 +17,5 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
- *.gemspec
21
20
 
22
21
  ## PROJECT::SPECIFIC
data/README.rdoc CHANGED
@@ -1,51 +1,30 @@
1
- = gem-manage-sources
1
+ = gem-check-sources
2
2
 
3
- gem-manage-sources is a replacement for the 'gem sources' command that allows you to easily use sources that may not always be available.
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?
4
6
 
5
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
6
- server, but when you take your laptop home and try to work on some side projects (that don't use the company gems) all your remote gem commands fail. So, you end up typing 'gem sources -a' and 'gem sources -r' a lot.
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.
7
11
 
8
- gem-manage-sources solves this problem by maintaining two list of gem servers (active and inactive) and checking whether or not gem servers are available. If a server is unavailable it gets put on the inactive list and removed form your gem sources. When it becomes availabl again it gets re-added to your list of gem sources.
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.
9
13
 
10
14
  == Installation
11
15
 
12
- gem install gem-manage-sources
16
+ gem install gem-check-sources
13
17
 
14
18
  == Usage
15
19
 
16
- Before you use gem-manage-sources you need to initialize the lists of gem sources using:
17
-
18
- gem manage_sources --init
19
-
20
- Now whenever you switch networks or want to check whether some of your sources are available use:
21
-
22
- gem manage_sources --check
23
-
24
- gem-manage-sources is effectively a replacement for
25
-
26
- gem sources
20
+ gem check_sources
27
21
 
28
- In order to keep your gem sources in sync you should always use
29
-
30
- gem manage_sources --add
31
- gem manage_sources --remove
32
-
33
- in place of
34
-
35
- gem sources -a
36
- gem sources -r
37
-
38
- I consider monkey-patching all of this functionality into the existing sources command, but that seemed really intrusive, especially before the whole idea has proven out.
22
+ That's it. If something is inactive and you want to add it back just run the command again.
39
23
 
40
24
  == Links
41
25
 
42
- * Bugtracker: http://github.com/britt/gem-manage-sources/issues
43
- * Code Metrics: http://bit.ly/6CJtPx
44
-
45
- == TODO
46
-
47
- * JRuby (and *Ruby) support
48
- * Find a better name
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
49
28
 
50
29
  == Note on Patches/Pull Requests
51
30
 
@@ -59,4 +38,4 @@ I consider monkey-patching all of this functionality into the existing sources c
59
38
 
60
39
  == Copyright
61
40
 
62
- Copyright (c) 2009 Britt Crawford. See LICENSE for details.
41
+ Copyright (c) 2010 Britt Crawford. See LICENSE for details.
data/Rakefile CHANGED
@@ -7,15 +7,15 @@ begin
7
7
  gem.name = "gem-manage-sources"
8
8
 
9
9
  gem.summary = <<-SUMMARY
10
- A replacement for the 'gem sources' command that allows you to easily use sources that may not always be available (e.g. inside a firewall).
11
- SUMMARY
10
+ gem-manage-sources is now gem-check-sources http://rubygems.org/gems/gem-check-sources this gem will no longer be updated.
11
+ SUMMARY
12
12
 
13
13
  gem.description = <<-WTF
14
- gem-manage-sources is a replacement for the 'gem sources' command that allows you to easily use sources that may not always be available.
14
+ gem-manage-sources is now gem-check-sources http://rubygems.org/gems/gem-check-sources this gem will no longer be updated.
15
15
  WTF
16
16
 
17
17
  gem.email = "britt.v.crawford@gmail.com"
18
- gem.homepage = "http://github.com/britt/gem-manage-sources"
18
+ gem.homepage = "http://github.com/britt/gem-check-sources"
19
19
  gem.authors = ["Britt Crawford"]
20
20
  gem.add_development_dependency "rspec", ">= 1.2.9"
21
21
  gem.add_development_dependency "yard", ">= 0"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
@@ -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,2 @@
1
+ require 'gem_check_sources/sources'
2
+ require 'gem_check_sources/commands/check_sources_command'
@@ -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
@@ -71,7 +71,7 @@ module Gem
71
71
  gemspec_path = uri.path[-1,1] == '/' ? "specs.4.8.gz" : "/specs.4.8.gz"
72
72
  response = nil
73
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)
74
+ response.is_a?(Net::HTTPOK) || response.is_a?(Net::HTTPFound) || response.is_a?(Net::HTTPNotModified)
75
75
  rescue
76
76
  false
77
77
  end
@@ -1,6 +1,6 @@
1
- require 'gem_manage_sources'
1
+ require 'gem_check_sources'
2
2
  require 'rubygems/command_manager'
3
3
 
4
- Gem::CommandManager.instance.register_command :manage_sources
4
+ Gem::CommandManager.instance.register_command :check_sources
5
5
 
6
6
 
@@ -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
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'gem_manage_sources'
3
+ require 'gem_check_sources'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
6
  require 'pp'
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-manage-sources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 7
9
+ version: 0.2.7
5
10
  platform: ruby
6
11
  authors:
7
12
  - Britt Crawford
@@ -9,31 +14,37 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-23 00:00:00 -08:00
17
+ date: 2010-04-19 00:00:00 -07:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
23
31
  version: 1.2.9
24
- version:
32
+ type: :development
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: yard
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
33
43
  version: "0"
34
- version:
44
+ type: :development
45
+ version_requirements: *id002
35
46
  description: |
36
- gem-manage-sources is a replacement for the 'gem sources' command that allows you to easily use sources that may not always be available.
47
+ gem-manage-sources is now gem-check-sources http://rubygems.org/gems/gem-check-sources this gem will no longer be updated.
37
48
 
38
49
  email: britt.v.crawford@gmail.com
39
50
  executables: []
@@ -50,16 +61,17 @@ files:
50
61
  - README.rdoc
51
62
  - Rakefile
52
63
  - VERSION
53
- - lib/gem_manage_sources.rb
54
- - lib/gem_manage_sources/commands/manage_sources_command.rb
55
- - lib/gem_manage_sources/sources.rb
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
56
68
  - lib/rubygems_plugin.rb
57
- - spec/gem_manage_sources/commands/manage_sources_command_spec.rb
58
- - spec/gem_manage_sources/sources_spec.rb
69
+ - spec/gem_check_sources/commands/check_sources_command_spec.rb
70
+ - spec/gem_check_sources/sources_spec.rb
59
71
  - spec/spec.opts
60
72
  - spec/spec_helper.rb
61
73
  has_rdoc: true
62
- homepage: http://github.com/britt/gem-manage-sources
74
+ homepage: http://github.com/britt/gem-check-sources
63
75
  licenses: []
64
76
 
65
77
  post_install_message:
@@ -71,22 +83,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
83
  requirements:
72
84
  - - ">="
73
85
  - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
74
88
  version: "0"
75
- version:
76
89
  required_rubygems_version: !ruby/object:Gem::Requirement
77
90
  requirements:
78
91
  - - ">="
79
92
  - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
80
95
  version: "0"
81
- version:
82
96
  requirements: []
83
97
 
84
98
  rubyforge_project:
85
- rubygems_version: 1.3.5
99
+ rubygems_version: 1.3.6
86
100
  signing_key:
87
101
  specification_version: 3
88
- summary: A replacement for the 'gem sources' command that allows you to easily use sources that may not always be available (e.g. inside a firewall).
102
+ summary: gem-manage-sources is now gem-check-sources http://rubygems.org/gems/gem-check-sources this gem will no longer be updated.
89
103
  test_files:
90
- - spec/gem_manage_sources/commands/manage_sources_command_spec.rb
91
- - spec/gem_manage_sources/sources_spec.rb
104
+ - spec/gem_check_sources/commands/check_sources_command_spec.rb
105
+ - spec/gem_check_sources/sources_spec.rb
92
106
  - spec/spec_helper.rb
@@ -1,2 +0,0 @@
1
- require 'gem_manage_sources/sources'
2
- require 'gem_manage_sources/commands/manage_sources_command'
@@ -1,107 +0,0 @@
1
- require 'rubygems/command'
2
- require 'gem_manage_sources/sources'
3
-
4
- module Gem
5
- module Commands
6
- class ManageSourcesCommand < Gem::Command
7
- include Gem::Sources
8
-
9
- def self.sources_file
10
- File.join(ENV['HOME'], '.gem', 'ruby', 'sources.yml')
11
- end
12
-
13
- def initialize
14
- super('manage_sources', 'Manage the sources RubyGems use to search for gems. (USE INSTEAD OF: sources)')
15
- defaults.merge!(:sources_to_add => [], :sources_to_remove => [], :check_sources? => false, :init? => false, :verbose? => false)
16
-
17
- add_option('-a', '--add SOURCE_URL', 'Add a gem source') do |value, options|
18
- options[:sources_to_add] << value
19
- end
20
-
21
- add_option('-r', '--remove SOURCE_URL', 'Remove a gem source') do |value, options|
22
- options[:sources_to_remove] << value
23
- end
24
-
25
- add_option('-c', '--check', 'Check gem sources. This will add or remove sources depending on availability.') do |value, options|
26
- options[:check_sources?] = true
27
- end
28
-
29
- add_option('-i', '--init', 'Generate the sources.yml file from your existing gem sources.') do |value, options|
30
- options[:init?] = true
31
- end
32
- end
33
-
34
- def execute
35
- if options[:init?]
36
- initialize_sources
37
- elsif options[:check_sources?]
38
- check_sources
39
- elsif !options[:sources_to_add].empty?
40
- add_sources(options[:sources_to_add])
41
- elsif !options[:sources_to_remove].empty?
42
- remove_sources(options[:sources_to_remove])
43
- else
44
- list
45
- end
46
- end
47
-
48
- def initialize_sources
49
- unless File.exist?(ManageSourcesCommand.sources_file)
50
- @sources = List.new(:unchecked => currently_loaded_sources)
51
- @sources.verify
52
- @sources.dump(ManageSourcesCommand.sources_file)
53
- end
54
- list
55
- end
56
-
57
- def check_sources
58
- sources.unchecked.concat(currently_loaded_sources)
59
- sources.verify
60
- sources.sync
61
- sources.dump(ManageSourcesCommand.sources_file)
62
- list
63
- end
64
-
65
- def add_sources(sources_to_add)
66
- sources_to_add.each do |source|
67
- if sources.add(source)
68
- say "Added #{source} to gem sources."
69
- else
70
- say "** #{source} Unavailable ** Added to the list of inactive sources. "
71
- end
72
- end
73
- sources.dump(ManageSourcesCommand.sources_file)
74
- end
75
-
76
- def remove_sources(sources_to_remove)
77
- sources_to_remove.each do |source|
78
- sources.remove(source)
79
- say "Removed #{source} from gem sources."
80
- end
81
- sources.dump(ManageSourcesCommand.sources_file)
82
- end
83
-
84
- def list
85
- say "*** CURRENT SOURCES ***"
86
- say ""
87
- say "** ACTIVE SOURCES **"
88
- say ""
89
- sources.active.each { |source| say source }
90
- say ""
91
- say "** INACTIVE SOURCES **"
92
- say ""
93
- sources.inactive.each { |source| say source }
94
- end
95
-
96
- private
97
-
98
- def sources
99
- @sources ||= Gem::Sources::List.load_file(ManageSourcesCommand.sources_file)
100
- end
101
-
102
- def say(message)
103
- super(message) unless ENV['QUIET']
104
- end
105
- end
106
- end
107
- end
@@ -1,182 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
2
-
3
- describe Gem::Commands::ManageSourcesCommand do
4
- include Gem::Sources
5
-
6
- before(:each) do
7
- @test_sources_file = Dir.tmpdir + "/test_gem_sources.yml"
8
- @command = Gem::Commands::ManageSourcesCommand.new
9
- Gem::Commands::ManageSourcesCommand.stub!(:sources_file).and_return(@test_sources_file)
10
- end
11
-
12
- after(:each) do
13
- File.delete(@test_sources_file) if File.exist?(@test_sources_file)
14
- end
15
-
16
- describe "options" do
17
- before(:each) do
18
- @command.when_invoked {}
19
- end
20
-
21
- describe "add" do
22
- it "should be -a, --add" do
23
- @command.invoke("-a", "http://gems.example.com")
24
- @command.invoke("--add", "http://gems.example.com")
25
-
26
- @command.options[:args].should be_empty
27
- end
28
-
29
- it "should add the given source to :sources_to_add" do
30
- @command.invoke("-a", "http://gems.example.com")
31
- @command.options[:sources_to_add].should include("http://gems.example.com")
32
- end
33
- end
34
-
35
- describe "remove" do
36
- it "should be -r, --remove" do
37
- @command.invoke("-r", "http://gems.example.com")
38
- @command.invoke("--remove", "http://gems.example.com")
39
-
40
- @command.options[:args].should be_empty
41
- end
42
-
43
- it "should add the given source to :sources_to_add" do
44
- @command.invoke("-r", "http://gems.example.com")
45
- @command.options[:sources_to_remove].should include("http://gems.example.com")
46
- end
47
- end
48
-
49
- describe "check" do
50
- it "should be -c, --check" do
51
- @command.invoke("-c")
52
- @command.invoke("--check")
53
-
54
- @command.options[:args].should be_empty
55
- end
56
-
57
- it "check_sources? should be true" do
58
- @command.invoke("-c")
59
-
60
- @command.options[:check_sources?].should be_true
61
- end
62
- end
63
-
64
- describe "init" do
65
- it "should be -i, --init" do
66
- @command.invoke("-i")
67
- @command.invoke("--init")
68
-
69
- @command.options[:args].should be_empty
70
- end
71
-
72
- it "init? should be true" do
73
- @command.invoke("-i")
74
-
75
- @command.options[:init?].should be_true
76
- end
77
- end
78
- end
79
-
80
- describe "init" do
81
- context "when there is no existing sources file" do
82
- before(:each) do
83
- Gem::Commands::ManageSourcesCommand.stub!(:sources_file).and_return(@test_sources_file)
84
- File.exist?(@test_sources_file).should be_false
85
-
86
- @sources = ['http://active.example.com','http://inactive.example.com']
87
- @list = Gem::Sources::List.new(:unchecked => @sources)
88
-
89
- @list.stub!(:source_available?) do |source|
90
- source == 'http://active.example.com'
91
- end
92
-
93
- Gem::Sources::List.stub!(:new).and_return(@list)
94
-
95
- @command.stub!(:currently_loaded_sources).and_return(@sources)
96
- @command.stub!(:sources).and_return(@list)
97
- @command.invoke('-i')
98
- end
99
-
100
- it "should create ~/.gem/ruby/sources.yml" do
101
- File.exist?(@test_sources_file).should be_true
102
- end
103
-
104
- it "should add all of the existing sources" do
105
- sources = Gem::Sources::List.load_file(@test_sources_file)
106
- @sources.each do |source|
107
- sources.all.should include(source)
108
- end
109
- end
110
-
111
- it "should add unavailable sources to the inactive list" do
112
- sources = Gem::Sources::List.load_file(@test_sources_file)
113
- sources.active.should == ['http://active.example.com']
114
- end
115
-
116
- it "should add available sources to the active list" do
117
- sources = Gem::Sources::List.load_file(@test_sources_file)
118
- sources.inactive.should == ['http://inactive.example.com']
119
- end
120
- end
121
- end
122
-
123
- describe "check" do
124
- before(:each) do
125
- @sources = ['http://active.example.com','http://inactive.example.com']
126
- @list = Gem::Sources::List.new(:unchecked => @sources)
127
-
128
- @list.stub!(:sync)
129
- @list.stub!(:source_available?) do |source|
130
- source == 'http://active.example.com'
131
- end
132
- @list.verify
133
- @list.dump(@test_sources_file)
134
-
135
- @sources << 'http://another.example.com'
136
- @command.stub!(:currently_loaded_sources).and_return(@sources)
137
- @command.stub!(:sources).and_return(@list)
138
-
139
- @command.invoke('-c')
140
- @list = Gem::Sources::List.load_file(@test_sources_file)
141
- end
142
-
143
- it "should should add any new sources that have been added using 'gem source add'" do
144
- @list.all.should include('http://another.example.com')
145
- end
146
-
147
- it "should add unavailable sources to the inactive list" do
148
- @list.inactive.sort.should == ['http://inactive.example.com', 'http://another.example.com'].sort
149
- end
150
-
151
- it "should add available sources to the active list" do
152
- @list.active.should == ['http://active.example.com']
153
- end
154
- end
155
-
156
- describe "verbosity" do
157
- before(:each) do
158
- @sources = ['http://active.example.com','http://inactive.example.com']
159
- @list = Gem::Sources::List.new(:unchecked => @sources)
160
-
161
- @list.stub!(:sync)
162
- @list.stub!(:source_available?) do |source|
163
- source == 'http://active.example.com'
164
- end
165
- @list.verify
166
- @list.dump(@test_sources_file)
167
-
168
- @sources << 'http://another.example.com'
169
- @command.stub!(:currently_loaded_sources).and_return(@sources)
170
- @command.stub!(:sources).and_return(@list)
171
-
172
- @command.invoke('-c')
173
- @list = Gem::Sources::List.load_file(@test_sources_file)
174
- end
175
-
176
- it "should be verbose" do
177
-
178
- pp @command.options
179
- pending
180
- end
181
- end
182
- end