Change soft-fail to use the config, rather than env
[rbx.git] / test / rubygems / test_gem_commands_update_command.rb
blob11da1f8a838e0e3d6f871c410bf239d19cac02eb
1 require 'test/unit'
2 require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities')
3 require 'rubygems/commands/update_command'
5 class TestGemCommandsUpdateCommand < RubyGemTestCase
7   def setup
8     super
10     @cmd = Gem::Commands::UpdateCommand.new
12     util_setup_fake_fetcher
14     @a1_path = File.join @gemhome, 'cache', "#{@a1.full_name}.gem"
15     @a2_path = File.join @gemhome, 'cache', "#{@a2.full_name}.gem"
17     util_setup_spec_fetcher @a1, @a2
19     @fetcher.data["#{@gem_repo}gems/#{@a1.full_name}.gem"] =
20       read_binary @a1_path
21     @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] =
22       read_binary @a2_path
23   end
25   def test_execute
26     util_clear_gems
28     Gem::Installer.new(@a1_path).install
30     @cmd.options[:args] = []
32     use_ui @ui do
33       @cmd.execute
34     end
36     out = @ui.output.split "\n"
37     assert_equal "Updating installed gems", out.shift
38     assert_equal "Updating #{@a2.name}", out.shift
39     assert_equal "Successfully installed #{@a2.full_name}", out.shift
40     assert_equal "Gems updated: #{@a2.name}", out.shift
42     assert out.empty?, out.inspect
43   end
45   # before:
46   #   a1 -> c1.2
47   # after:
48   #   a2 -> b2 # new dependency
49   #   a2 -> c2
51   def test_execute_dependencies
52     @a1.add_dependency 'c', '1.2'
54     @c2 = quick_gem 'c', '2' do |s|
55       s.files = %w[lib/code.rb]
56       s.require_paths = %w[lib]
57     end
59     @a2.add_dependency 'c', '2'
60     @a2.add_dependency 'b', '2'
62     @b2_path = File.join @gemhome, 'cache', "#{@b2.full_name}.gem"
63     @c1_2_path = File.join @gemhome, 'cache', "#{@c1_2.full_name}.gem"
64     @c2_path = File.join @gemhome, 'cache', "#{@c2.full_name}.gem"
66     @source_index = Gem::SourceIndex.new
67     @source_index.add_spec @a1
68     @source_index.add_spec @a2
69     @source_index.add_spec @b2
70     @source_index.add_spec @c1_2
71     @source_index.add_spec @c2
73     util_build_gem @a1
74     util_build_gem @a2
75     util_build_gem @c2
77     @fetcher.data["#{@gem_repo}gems/#{@a1.full_name}.gem"] = read_binary @a1_path
78     @fetcher.data["#{@gem_repo}gems/#{@a2.full_name}.gem"] = read_binary @a2_path
79     @fetcher.data["#{@gem_repo}gems/#{@b2.full_name}.gem"] = read_binary @b2_path
80     @fetcher.data["#{@gem_repo}gems/#{@c1_2.full_name}.gem"] =
81       read_binary @c1_2_path
82     @fetcher.data["#{@gem_repo}gems/#{@c2.full_name}.gem"] = read_binary @c2_path
84     util_setup_spec_fetcher @a1, @a2, @b2, @c1_2, @c2
85     util_clear_gems
87     Gem::Installer.new(@c1_2_path).install
88     Gem::Installer.new(@a1_path).install
90     @cmd.options[:args] = []
92     use_ui @ui do
93       @cmd.execute
94     end
96     out = @ui.output.split "\n"
97     assert_equal "Updating installed gems", out.shift
98     assert_equal "Updating #{@a2.name}", out.shift
99     assert_equal "Successfully installed #{@c2.full_name}", out.shift
100     assert_equal "Successfully installed #{@b2.full_name}", out.shift
101     assert_equal "Successfully installed #{@a2.full_name}", out.shift
102     assert_equal "Gems updated: #{@c2.name}, #{@b2.name}, #{@a2.name}",
103                  out.shift
105     assert out.empty?, out.inspect
106   end
108   def test_execute_named
109     util_clear_gems
111     Gem::Installer.new(@a1_path).install
113     @cmd.options[:args] = [@a1.name]
115     use_ui @ui do
116       @cmd.execute
117     end
119     out = @ui.output.split "\n"
120     assert_equal "Updating installed gems", out.shift
121     assert_equal "Updating #{@a2.name}", out.shift
122     assert_equal "Successfully installed #{@a2.full_name}", out.shift
123     assert_equal "Gems updated: #{@a2.name}", out.shift
125     assert out.empty?, out.inspect
126   end
128   def test_execute_named_up_to_date
129     util_clear_gems
131     Gem::Installer.new(@a2_path).install
133     @cmd.options[:args] = [@a2.name]
135     use_ui @ui do
136       @cmd.execute
137     end
139     out = @ui.output.split "\n"
140     assert_equal "Updating installed gems", out.shift
141     assert_equal "Nothing to update", out.shift
143     assert out.empty?, out.inspect
144   end
146   def test_execute_up_to_date
147     util_clear_gems
149     Gem::Installer.new(@a2_path).install
151     @cmd.options[:args] = []
153     use_ui @ui do
154       @cmd.execute
155     end
157     out = @ui.output.split "\n"
158     assert_equal "Updating installed gems", out.shift
159     assert_equal "Nothing to update", out.shift
161     assert out.empty?, out.inspect
162   end