Geminstaller C0 Coverage Information - RCov

spec/functional/gem_command_manager_spec.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/functional/gem_command_manager_spec.rb 144 117
75.69%
78.63%

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 "a GemCommandManager instance" do
5   before(:each) do
6     GemInstaller::TestGemHome.use
7     extra_install_options = install_options_for_testing
8     extra_install_options << "-y" << "--backtrace"
9     @sample_gem_with_extra_install_options = GemInstaller::RubyGem.new(sample_gem_name, :version => sample_gem_version, :install_options => extra_install_options)
10     @sample_gem = sample_gem
11     @sample_dependent_gem = sample_dependent_gem
12     @sample_multiplatform_gem = sample_multiplatform_gem
13     @sample_dependent_multiplatform_gem = sample_dependent_multiplatform_gem
14     @nonexistent_version_sample_gem = GemInstaller::RubyGem.new(sample_gem_name, :version => "0.0.37", :install_options => install_options_for_testing)
15     @unspecified_version_sample_gem = GemInstaller::RubyGem.new(sample_gem_name,:install_options => install_options_for_testing)
16     @registry = GemInstaller::create_registry
17     @gem_command_manager = @registry.gem_command_manager
18     @gem_spec_manager = @registry.gem_spec_manager
19     @valid_platform_selector = @registry.valid_platform_selector
20   end
21 
22   it "should be able to install, uninstall, and check for existence of specific versions of a gem" do
23     install_gem(@sample_gem_with_extra_install_options)
24   
25     @gem_spec_manager.is_gem_installed?(@sample_gem).should==(true)
26     @gem_spec_manager.is_gem_installed?(@nonexistent_version_sample_gem).should==(false)
27   end
28   
29   it "should be able to list remote gems" do
30     Gem::SourceInfoCache.cache.reset_cache_data if GemInstaller::RubyGemsVersionChecker.matches?('>1.0.1')
31     @sample_gem.name = 'stubgem-multiplatform'
32     list = @gem_command_manager.list_remote_gem(@sample_gem, [])
33     
34     if GemInstaller::RubyGemsVersionChecker.matches?('=0.9.5')
35       # bug in 0.9.5 that double-lists versions
36       expected_versions = "1.0.1, 1.0.1, 1.0.0"
37     else
38       expected_versions = "1.0.1, 1.0.0"
39     end
40     
41     expected_list = /.*stubgem-multiplatform \(#{expected_versions}\).*Multiplatform stub gem for testing geminstaller/m
42     list.join.should match(expected_list)
43   end
44   
45   if GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4') # Rubygems 0.9.5 and later automatically installs dependencies
46   it "should raise an error if attempting to install a gem with dependencies without -y option" do
47     # ensure dependency gem is uninstalled
48     @gem_command_manager.uninstall_gem(@sample_gem)
49     sample_dependent_gem = @sample_dependent_gem.dup
50     sample_dependent_gem.install_options = install_options_for_testing.dup
51     exception = nil
52     begin
53       @gem_command_manager.install_gem(sample_dependent_gem)
54     rescue GemInstaller::UnauthorizedDependencyPromptError => error
55       exception = error
56       expected_error_message = /RubyGems is prompting to install a required dependency.*Gem command was:.*install dependent-stubgem.*Gem command output was:.*Install required dependency stubgem/m
57       error.message.should match(expected_error_message)
58     end
59     exception.class.should==(GemInstaller::UnauthorizedDependencyPromptError)
60   end
61   end
62   
63   it "should be able to install and uninstall similarly named gems without a prompt (using exact name matching)" do
64     gems = [@sample_gem, @sample_multiplatform_gem]
65     gems.each do |gem|
66       install_gem(gem)
67     end
68   end
69   
70   it "should be able to install two gems with the same version but different platforms" do
71     @sample_multiplatform_gem_for_another_platform = sample_multiplatform_gem.dup
72     @sample_multiplatform_gem_for_another_platform.platform = 'ruby'
73     uninstall_gem(@sample_multiplatform_gem)
74     uninstall_gem(@sample_multiplatform_gem_for_another_platform)
75     gems = [@sample_multiplatform_gem, @sample_multiplatform_gem_for_another_platform]
76     gems.each do |gem|
77       install_gem(gem)
78     end
79   end
80   
81   it "should be able to automatically install a dependency gem when dependent gem is installed" do
82     @sample_dependency_gem = sample_gem
83     uninstall_gem(@sample_dependent_gem)
84     uninstall_gem(@sample_gem)
85     @sample_dependent_gem.install_options << "-y"
86     install_gem(@sample_dependent_gem)
87     @gem_spec_manager.is_gem_installed?(@sample_gem).should==(true)
88   end
89   
90   it "should be able to automatically install a multiplatform dependency gem when a multiplatform dependent gem is installed" do
91     uninstall_gem(@sample_dependent_multiplatform_gem)
92     uninstall_gem(@sample_multiplatform_gem)
93     @sample_dependent_multiplatform_gem.install_options << "-y"
94     install_gem(@sample_dependent_multiplatform_gem)
95     @gem_spec_manager.is_gem_installed?(@sample_multiplatform_gem).should==(true)
96   end
97   
98   if GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4')
99   # Can't do this test on RubyGems 0.9.5 or above, because it handles platforms internally
100   # rather than using ValidPlatformSelector, so we can't control ruby_platform.
101   # We would have to somehow make a stubgem that matches current platform, which is hard
102   # to make work on multiple platforms (because stubgems in spec/gems are manually created)
103   it "should be able to install and uninstall a gem with the 'current' platform" do
104     gem = @sample_gem
105 
106     # force ruby platform to match 'remote' gem's platform
107     @valid_platform_selector.ruby_platform = gem.platform
108 
109     # reset gem's platform to current
110     gem.platform = 'current'
111     @gem_spec_manager.is_gem_installed?(gem).should==(false)
112     @gem_command_manager.install_gem(gem)
113     @gem_spec_manager.is_gem_installed?(gem).should==(true)
114   end
115   end
116   
117   it "should be able to list dependencies based on exact name match" do
118     nonmatching_gem = sample_dependent_multiplatform_gem
119     nonmatching_gem.install_options << '--include-dependencies'
120     install_gem(nonmatching_gem)
121     
122     matching_gem = sample_dependent_gem
123     matching_gem.install_options << '--include-dependencies'
124     install_gem(matching_gem)
125     dependency_output_gems = @gem_command_manager.dependency(sample_dependent_gem.name, sample_dependent_gem.version, sample_dependent_gem.install_options)
126     dependency_output_gems.size.should==(1)
127     dependency_output_gems[0].name.should==('stubgem')
128     dependency_output_gems[0].version.should==('>= 1.0.0')
129   end
130 
131   def install_gem(gem)
132     @gem_command_manager.install_gem(gem)
133     @gem_spec_manager.is_gem_installed?(gem).should==(true)
134   end
135   
136   def uninstall_gem(gem)
137     @gem_command_manager.uninstall_gem(gem)
138     @gem_spec_manager.is_gem_installed?(gem).should==(false)
139   end
140   
141   after(:each) do
142     GemInstaller::TestGemHome.uninstall_all_test_gems
143   end
144 end

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