Geminstaller C0 Coverage Information - RCov

lib/geminstaller/noninteractive_chooser.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/geminstaller/noninteractive_chooser.rb 114 89
18.42%
12.36%

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 module GemInstaller
2   # Format for "install" prompt list: "#{spec.name} #{spec.version} (#{spec.platform})"
3   # Format for "uninstall" prompt list: "#{spec.name}-#{spec.version}" for ruby,  "#{spec.name}-#{spec.version}-#{spec.platform}" (gem.full_name) for binary
4   class NoninteractiveChooser
5     def initialize
6       check_rubygems_version
7       @question = nil
8     end
9     
10     def choose(question, list, dependent_gem_name, dependent_gem_version, valid_platforms)
11       @question = question
12       @list = list
13       @dependent_gem_name = dependent_gem_name
14       @dependent_gem_version = dependent_gem_version
15       @valid_platforms = valid_platforms
16       raise GemInstaller::GemInstallerError.new("Internal GemInstaller Error, unexpected choice prompt question: '#{question}'") unless
17         install_list_type? or uninstall_list_type?
18 
19       raise GemInstaller::GemInstallerError.new("valid_platforms must be passed as an array.") unless 
20         valid_platforms.respond_to? :shift
21 
22       raise GemInstaller::GemInstallerError.new("Internal GemInstaller Error, multiple platforms cannot be specified for an uninstall prompt") if
23         uninstall_list_type? and valid_platforms.size > 1
24 
25       index = nil
26       valid_platforms.each do |platform|
27         index = find_matching_line(platform)
28         break if index 
29       end
30       
31       return @list[index], index if index
32       
33       # if we didn't find a match, raise a descriptive error
34       action = install_list_type? ? 'install' : 'uninstall'
35       name = @dependent_gem_name ? "#{@dependent_gem_name}" : "'any name'"
36       version = @dependent_gem_version ? "#{@dependent_gem_version}" : "'any version'"
37       platform = @valid_platforms ? " (#{@valid_platforms.join(' or ')})" : ''
38       error_message = "Error: Unable to select gem from list: \"#{name} #{version}#{platform}\".  Available gems are:\n"
39       list.each do |item|
40         # skip last 'cancel' list entry, it's not a real gem
41         next if item == list.last
42         error_message += "  " + item + "\n"
43       end
44       raise GemInstaller::GemInstallerError.new(error_message)
45     end
46     
47     def find_matching_line(platform)
48       required_list_item_regexp = required_name_and_version_regexp + required_platform_regexp(platform)
49       line_selector = /^#{required_list_item_regexp}$/
50       @list.each_with_index do |item, index|
51         if item =~ line_selector
52           return index
53         end
54       end
55       return nil
56     end
57     
58     def required_name_and_version_regexp
59       required_name_regexp = ".*?"
60       required_version_regexp = ".*?"
61       if uninstall_list_type? or dependent_gem?
62          # match the exact name and version if it's an uninstall prompt or a dependent gem
63         required_name_regexp = Regexp.escape(@dependent_gem_name) if @dependent_gem_name
64         required_version_regexp = Regexp.escape(@dependent_gem_version) if @dependent_gem_version
65       end
66       "#{required_name_regexp}[\s-]{0,1}#{required_version_regexp}"
67     end
68 
69     def required_platform_regexp(platform_to_match)
70       return "" unless platform_to_match
71       required_platform = ""
72       escaped_platform_to_match = Regexp.escape(platform_to_match)
73       platform_regex = nil
74       if dependent_gem?
75         # do an exact match on the platform if this is the dependent gem
76         platform_regex = "#{escaped_platform_to_match}"
77       else
78         # do a wildcard match on the platform if it's not the dependent gem
79         platform_regex = ".*?#{escaped_platform_to_match}.*?"
80       end
81       # install list types always have the platform for each gem in parenthesis, even if it is ruby
82       if (install_list_type?)
83         required_platform = " \\(#{platform_regex}\\)"
84       end
85       # uninstall list types have the gem full_name, which is the platform for each gem appended after a dash, but only if it is not ruby
86       if (uninstall_list_type? && platform_to_match.to_s != GemInstaller::RubyGem.default_platform)
87         required_platform = "-.*?#{platform_regex}.*?"
88       end
89       required_platform
90     end
91     
92     def install_list_type?(question = @question)
93       question =~ /to install/
94     end
95   
96     def uninstall_list_type?(question = @question)
97       question =~ /to uninstall/
98     end
99     
100     def dependent_gem?(dependent_gem_name = @dependent_gem_name, list = @list)
101       # return true if it's an install prompt, and the list contains the gem for which the original install request
102       # was made (in other words, it's a dependent gem, not a dependency gem)
103       install_format_exact_name_match_regexp = /^#{dependent_gem_name}\s.*/
104       install_list_type? and list[0] =~ install_format_exact_name_match_regexp
105     end
106 
107     def check_rubygems_version
108       if GemInstaller::RubyGemsVersionChecker.matches?('>=0.9.5')
109         # noninteractive_chooser is not used for RubyGems >= 0.9.5
110         raise RuntimeError.new("Internal GemInstaller Error: NoninteractiveChooser should not be used for RubyGems >= 0.9.5")
111       end
112     end
113   end
114 end

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