Geminstaller C0 Coverage Information - RCov

spec/unit/noninteractive_chooser_spec.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/unit/noninteractive_chooser_spec.rb 145 120
2.76%
2.50%

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 if GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4')
5 # noninteractive_chooser is not used for RubyGems >= 0.9.5
6 describe "a NoninteractiveChooser instance which is passed an install-formatted list of both non-binary and binary gems" do
7   before(:each) do
8     @noninteractive_chooser = GemInstaller::NoninteractiveChooser.new
9     @question = "Select which gem to install for your platform (i686-darwin8.7.1)"
10     @list = [
11       "stubgem-multiplatform 2.0.0 (ruby)",
12       "stubgem-multiplatform 1.0.1 (mswin32)",
13       "stubgem-multiplatform 1.0.1 (ruby)",
14       "stubgem-multiplatform 1.0.0 (mswin32)",
15       "stubgem-multiplatform 1.0.0 (ruby)",
16       "Cancel installation"
17       ]
18   end
19 
20   it "should properly select with a binary platform" do
21     should_choose(1, "stubgem-multiplatform", "1.0.1", ["mswin32"])
22   end
23 
24   it "should properly select with a substring of a binary platform if the list is not for the dependent gem" do
25     should_choose(1, "stubgem", "1.0.1", ["mswin"])
26   end
27 
28   it "should properly select with a ruby platform" do
29     should_choose(2, "stubgem-multiplatform", "1.0.1", ["ruby"])
30   end
31 
32   it "should properly select with a binary platform and nil name/version" do
33     should_choose(1, nil, nil, ["mswin32"])
34   end
35   
36   it "should properly select with a ruby platform and nil name/version" do
37     should_choose(0, nil, nil, ["ruby"])
38   end
39   
40   it "should select first matching platform if list does not match name exactly (it's a dependency gem)" do
41     should_choose(1, 'stubgem', '1.2.3', ["mswin32"])
42   end
43 end
44 
45 describe "a NoninteractiveChooser instance which is passed an install-formatted list for a dependent gem" do
46   before(:each) do
47     @noninteractive_chooser = GemInstaller::NoninteractiveChooser.new
48     @question = "Select which gem to install for your platform (i686-darwin8.7.1)"
49     @list = [
50       "stubgem-dependency 2.0.0 (ruby)",
51       "stubgem-dependency 1.0.1 (mswin32)",
52       "stubgem-dependency 1.0.1 (ruby)",
53       "stubgem-dependency 1.0.0 (mswin32)",
54       "stubgem-dependency 1.0.0 (ruby)",
55       "Cancel installation"
56       ]
57   end
58 
59   it "should select the first matching platform" do
60     should_choose(1, 'stubgem', '1.2.3', ["mswin32"])
61   end
62 
63   it "should raise error if there is no match" do
64     should_raise_error("stubgem-nomatch", "1.0.0", ["solaris"])
65   end
66 
67   it "should have properly formatted error" do
68     begin
69       @noninteractive_chooser.choose(@question, @list, "stubgem-nomatch", "1.0.0", ["solaris","mvs"])
70     rescue GemInstaller::GemInstallerError => e
71       @list.collect! do |item|
72         Regexp.escape(item)
73       end
74       list_regexp = @list[0..4].join(".*")
75       dependent_gem_regexp = Regexp.escape('"stubgem-nomatch 1.0.0 (solaris or mvs)"')
76       e.message.should match(/.*Unable to select gem from list.*#{dependent_gem_regexp}.*#{list_regexp}/m)
77     end
78   end
79 end
80 
81 describe "a NoninteractiveChooser instance which is passed an uninstall-formatted list of both non-binary and binary gems" do
82   before(:each) do
83     @noninteractive_chooser = GemInstaller::NoninteractiveChooser.new
84     @question = "Select RubyGem to uninstall"
85     @list = [
86       "stubgem-multiplatform 2.0.0 (ruby)",
87       "stubgem-multiplatform-1.0.1-mswin32",
88       "stubgem-multiplatform-1.0.1",
89       "stubgem-multiplatform-1.0.0-mswin32",
90       "stubgem-multiplatform-1.0.0",
91       "stubgem-1.0.0",
92       "All versions"
93       ]
94   end
95 
96   it "should properly select with a binary platform" do
97     should_choose(1, "stubgem-multiplatform", "1.0.1", ["mswin32"])
98   end
99 
100   it "should properly select with a ruby platform" do
101     should_choose(2, "stubgem-multiplatform", "1.0.1", ["ruby"])
102   end
103 
104   it "should properly select with a binary platform and nil name/version" do
105     should_choose(1, nil, nil, ["mswin32"])
106   end
107   
108   it "should properly select with a ruby platform and nil name/version" do
109     should_choose(0, nil, nil, ["ruby"])
110   end
111   
112   it "should do an exact name match (not substring)" do
113     should_choose(5, "stubgem", "1.0.0", ["ruby"])
114   end
115 
116   it "should properly select if there is no match" do
117     should_raise_error("stubgem-nomatch", "1.0.0", ["ruby"])
118     should_raise_error("stubgem-multiplatform", "1.0.1", ["nomatch"])
119     should_raise_error("stubgem-multiplatform", "9", ["mswin32"])
120   end
121 
122   it "should raise error if there is more than one platform specified to uninstall" do
123     should_raise_error("stubgem", "1.0.0", ["ruby", "mswin32"])
124   end
125 
126   it "should raise error if the question is not a recognized list prompt" do
127     @question = "invalid question prompt"
128     should_raise_error("stubgem", "1.0.0", ["ruby"])
129   end
130 
131   it "should raise error if valid_platforms is not specified as an array" do
132     should_raise_error("stubgem", "1.0.0", "ruby")
133   end
134 
135 end
136 
137 def should_choose(expected_choice, name, version, valid_platforms)
138   string, index = @noninteractive_chooser.choose(@question, @list, name, version, valid_platforms)
139   index.should==(expected_choice)
140 end
141 
142 def should_raise_error(name, version, valid_platforms)
143   lambda{ @noninteractive_chooser.choose(@question, @list, name, version, valid_platforms) }.should raise_error(GemInstaller::GemInstallerError)
144 end
145 end

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