Geminstaller C0 Coverage Information - RCov

spec/functional/geminstaller_spec.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/functional/geminstaller_spec.rb 269 219
91.08%
93.61%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 dir = File.dirname(__FILE__)
2 require File.expand_path("#{dir}/../helper/spec_helper")
3 
4 describe "The geminstaller command line application" do
5   before(:each) do
6     GemInstaller::TestGemHome.use
7     
8     @mock_output_proxy = mock("Mock Output Proxy")
9     @registry = GemInstaller::create_registry
10     @application = @registry.app
11     @output_filter = @registry.output_filter
12     @output_filter.output_proxy = @mock_output_proxy
13     
14     @gem_command_manager = @registry.gem_command_manager
15     @gem_spec_manager = @registry.gem_spec_manager
16     @valid_platform_selector = @registry.valid_platform_selector
17     @sample_gem = sample_gem
18   end
19 
20   it "should print usage if --help arg is specified" do
21     @application.args = ["--help"]
22     @mock_output_proxy.should_receive(:sysout).with(/^Usage.*/)
23     @application.install
24   end
25   
26   it "should install gem if it is not already installed" do
27     @application.args = geminstaller_spec_test_args
28     @application.install
29     @gem_spec_manager.is_gem_installed?(@sample_gem).should==(true)
30   end
31 
32   if GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4')
33   # This test only applies on older versions, since it involves faking out ruby_platform in
34   # valid_platform_selector, which is not used in newer versions
35   it "should handle 'current' as a valid platform" do
36     # force ruby platform to match 'remote' gem's platform
37     @valid_platform_selector.ruby_platform = @sample_gem.platform
38   
39     # reset gem's platform to current
40     @sample_gem.platform = 'current'
41   
42     @application.args = geminstaller_spec_test_args
43     @application.install
44     @gem_spec_manager.is_gem_installed?(@sample_gem).should==(true)
45   end
46   end
47   
48   it "should print startup message in debug mode" do
49     @gem_command_manager.install_gem(@sample_gem)
50     args = ["--geminstaller-output=debug","--config=#{geminstaller_spec_live_config_path}"]
51     @application.args = args
52     @mock_output_proxy.should_receive(:sysout).with(/^GemInstaller is verifying gem installation: #{sample_gem_name}.*/)
53     @mock_output_proxy.should_receive(:sysout).any_number_of_times.with(anything())
54     @application.install
55   end
56   
57 
58   it "should print message if gem is already installed" do
59     @gem_command_manager.install_gem(@sample_gem)
60     args = ["--geminstaller-output=debug","--config=#{geminstaller_spec_live_config_path}"]
61     @application.args = args
62     @mock_output_proxy.should_receive(:sysout).with(/^Gem .* is already installed/)
63     @mock_output_proxy.should_receive(:sysout).any_number_of_times.with(anything())
64     @application.install
65   end
66   
67   it "should print error if --sudo option is specified (it's only supported if geminstaller is invoked via GemInstaller class, which strips out the option)" do
68     @application.args = ["--sudo","--config=#{geminstaller_spec_live_config_path}"]
69     @mock_output_proxy.should_receive(:syserr).once().with(/^The sudo option is not .* supported/)
70     @application.install
71   end
72   
73   it "redirects stderr to stdout" do
74     begin
75       @application.args = ["--config=bogus_config_file.yml","--redirect-stderr-to-stdout"]
76       @original_stdout = $stdout
77       @mock_stdout = MockStdout.new
78       $stdout = @mock_stdout
79       @original_stderr = $stderr
80       @mock_stderr = MockStderr.new
81       $stderr = @mock_stderr
82       @output_proxy = @registry.output_proxy
83       @output_filter.output_proxy = @output_proxy
84       @application.install
85       @mock_stdout.out.should match(/^Error/)
86       @mock_stderr.err.should ==(nil)
87     ensure
88       $stdout = @original_stdout
89       $stderr = @original_stderr
90     end
91   end
92   
93   it "should install a platform-specific binary gem" do
94     @sample_multiplatform_gem = sample_multiplatform_gem
95     @gem_command_manager.uninstall_gem(@sample_multiplatform_gem) if @gem_spec_manager.is_gem_installed?(@sample_multiplatform_gem)
96     @application.args = ["--silent","--config=#{dir}/live_geminstaller_config_2.yml"]
97     @application.install
98     @gem_spec_manager.is_gem_installed?(@sample_multiplatform_gem).should==(true)
99   end
100   
101   it "should install correctly even if install_options is not specified on the gem" do
102     @application.args = ["--silent","--config=#{dir}/live_geminstaller_config_3.yml"]
103     @application.install
104     @gem_spec_manager.is_gem_installed?(@sample_gem).should==(true)
105   end
106   
107   it "should not give an error if a config file with no gems is loaded" do
108     @application.args = ["--config=#{dir}/empty_geminstaller_config.yml"]
109     @mock_output_proxy.should_receive(:sysout).any_number_of_times.with(/No gems found/m)
110     @application.install
111   end
112   
113   it "should show error if a version specification is not met" do
114     @application.args = ["--config=#{dir}/live_geminstaller_config_4.yml"]
115     @mock_output_proxy.should_receive(:syserr).with(/^The specified version requirement '> 1.0.0' for gem 'stubgem' is not met by any of the available versions: 1.0.0./)
116     @mock_output_proxy.should_receive(:sysout).any_number_of_times.with(anything())
117     @application.install
118     @gem_spec_manager.is_gem_installed?(@sample_gem).should==(false)
119   end
120    
121   it "should handle a multiplatform dependency chain" do
122     @application.args = ["--config=#{dir}/live_geminstaller_config_5.yml"]
123     @mock_output_proxy.should_receive(:sysout).with(/^Invoking gem install for #{sample_dependent_depends_on_multiplatform_gem.name}.*/)
124     @mock_output_proxy.should_receive(:sysout).with(/^Rubygems automatically installed dependency gem #{sample_multiplatform_gem.name}-#{sample_multiplatform_gem.version}/)
125     @mock_output_proxy.should_receive(:sysout).any_number_of_times.with(anything())
126     @application.install
127     @gem_spec_manager.is_gem_installed?(sample_dependent_depends_on_multiplatform_gem).should==(true)
128     expected_dependency_gem = nil
129     if RUBY_PLATFORM =~ /mswin/ && GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4')
130       # The binary mswin32 platform will only be installed be installed when using
131       # the old valid_platform_selector under RubyGems <= 0.9.4.  On RubyGems >= 0.9.5,
132       # the built-in RubyGems platform selection is used, which installs the ruby
133       # platform before the mswin32 platform by default.
134       expected_dependency_gem = sample_multiplatform_gem
135     else
136       expected_dependency_gem = sample_multiplatform_gem_ruby
137     end
138     @gem_spec_manager.is_gem_installed?(expected_dependency_gem).should==(true)
139   end
140 
141   after(:each) do
142     GemInstaller::TestGemHome.uninstall_all_test_gems
143   end
144    
145 end
146 
147 describe "The geminstaller command line application created via GemInstaller.install method" do
148   before(:each) do
149     GemInstaller::TestGemHome.use
150     @registry = GemInstaller::create_registry
151     @gem_spec_manager = @registry.gem_spec_manager
152   end
153 
154   it "should run successfully" do
155     @gem_spec_manager.is_gem_installed?(sample_gem).should be_false
156     result = GemInstaller.install(geminstaller_spec_test_args)
157     result.should equal(0)
158     @gem_spec_manager.is_gem_installed?(sample_gem).should be_true
159   end
160 
161   it "should run successfully via the 'GemInstaller.run' method" do
162     @gem_spec_manager.is_gem_installed?(sample_gem).should be_false
163     result = GemInstaller.run(geminstaller_spec_test_args)
164     result.should equal(0)
165     @gem_spec_manager.is_gem_installed?(sample_gem).should be_true
166   end
167 
168   after(:each) do
169     GemInstaller::TestGemHome.uninstall_all_test_gems
170   end
171 end
172 
173 describe "The GemInstaller.autogem method" do
174   before(:each) do
175     GemInstaller::TestGemHome.use
176     @registry = GemInstaller::create_registry
177     @gem_spec_manager = @registry.gem_spec_manager
178     @gem_runner_proxy = @registry.gem_runner_proxy
179     # Clear out loaded specs in rubygems, otherwise the gem call won't do anything
180     Gem.instance_eval { @loaded_specs.clear if @loaded_specs }
181 
182     if GemInstaller::RubyGemsVersionChecker.matches?('>=1.0.0')
183       # architecture got auto-added to gem names in RubyGems 1.0.0 and above
184       win32_platform = 'x86-mswin32'
185     else
186       win32_platform = 'mswin32'
187     end
188     @expected_load_path_entry = "#{test_gem_home_dir}/gems/#{sample_gem_name}-#{sample_gem_version}/lib"
189     @expected_load_path_entry_bin = "#{test_gem_home_dir}/gems/#{sample_gem_name}-#{sample_gem_version}/bin"
190     @expected_load_path_entry_2 = "#{test_gem_home_dir}/gems/#{sample_multiplatform_gem_name}-#{sample_multiplatform_gem_version}-#{win32_platform}/lib"
191     @expected_load_path_entry_2_bin = "#{test_gem_home_dir}/gems/#{sample_multiplatform_gem_name}-#{sample_multiplatform_gem_version}-#{win32_platform}/bin"
192     GemInstaller.install(["--silent","--config=#{geminstaller_spec_live_config_path},#{geminstaller_spec_live_config_2_path}"])
193     @gem_spec_manager.is_gem_installed?(sample_gem).should==(true)
194     @gem_spec_manager.is_gem_installed?(sample_multiplatform_gem).should==(true)
195     $:.delete(@expected_load_path_entry)
196     $:.delete(@expected_load_path_entry_bin)
197     $:.delete(@expected_load_path_entry_2)
198     $:.delete(@expected_load_path_entry_2_bin)
199     $:.should_not include(@expected_load_path_entry)
200     $:.should_not include(@expected_load_path_entry_bin)
201     $:.should_not include(@expected_load_path_entry_2)
202     $:.should_not include(@expected_load_path_entry_2_bin)
203   end
204 
205   it "should add a specified gem to the load path" do
206 
207     # These lines are required or else the GemInstaller.autogem command can't find the stubgem in the
208     # test gem home.  I'm not sure why.
209     if GemInstaller::RubyGemsVersionChecker.matches?('< 0.9')
210       runner = Gem::GemRunner.new()
211     else
212       runner = Gem::GemRunner.new(:command_manager => Gem::CommandManager)
213     end
214     runner.do_configuration(['list'])    
215 
216     added_gems = GemInstaller.autogem("--config=#{geminstaller_spec_live_config_path},#{geminstaller_spec_live_config_2_path} --exceptions")
217     added_gems.should be_a_kind_of(Array)
218     added_gems.should include(sample_gem)
219     added_gems.should include(sample_multiplatform_gem)
220     $:.should include(@expected_load_path_entry)
221     $:.should include(@expected_load_path_entry_bin)
222     $:.should include(@expected_load_path_entry_2)
223     $:.should include(@expected_load_path_entry_2_bin)
224   end
225 
226   it "should handle ignored args like sudo" do
227     # These lines are required or else the GemInstaller.autogem command can't find the stubgem in the
228     # test gem home.  I'm not sure why.
229     if GemInstaller::RubyGemsVersionChecker.matches?('< 0.9')
230       runner = Gem::GemRunner.new()
231     else
232       runner = Gem::GemRunner.new(:command_manager => Gem::CommandManager)
233     end
234     runner.do_configuration(['list'])
235 
236     args_that_should_be_ignored_by_autogem = '-d -p -rall -s'
237     added_gems = GemInstaller.autogem("--config=#{geminstaller_spec_live_config_path},#{geminstaller_spec_live_config_2_path} -e -gall #{args_that_should_be_ignored_by_autogem}")
238     added_gems.should be_a_kind_of(Array)
239     added_gems.should include(sample_gem)
240     added_gems.should include(sample_multiplatform_gem)
241     $:.should include(@expected_load_path_entry)
242     $:.should include(@expected_load_path_entry_bin)
243     $:.should include(@expected_load_path_entry_2)
244     $:.should include(@expected_load_path_entry_2_bin)
245   end
246 
247   it "should handle exceptions" do
248     result = GemInstaller.autogem('-cbogus_config_path')
249     result.should ==(1)
250   end
251 
252   after(:each) do
253     GemInstaller::TestGemHome.uninstall_all_test_gems
254   end
255 end
256 
257 def geminstaller_spec_live_config_path
258   dir = File.dirname(__FILE__)
259   "#{dir}/live_geminstaller_config.yml"
260 end
261 
262 def geminstaller_spec_live_config_2_path
263   dir = File.dirname(__FILE__)
264   "#{dir}/live_geminstaller_config_2.yml"
265 end
266 
267 def geminstaller_spec_test_args
268   ["--silent","--config=#{geminstaller_spec_live_config_path}"]
269 end

Generated on Mon May 10 23:40:29 -0700 2010 with rcov 0.9.8