Geminstaller C0 Coverage Information - RCov

spec/unit/arg_parser_spec.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/unit/arg_parser_spec.rb 233 194
100.00%
100.00%

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 "an ArgParser instance with no args" do
5   before(:each) do
6     common_setup
7   end
8 
9   it "should properly set defaults" do
10     @arg_parser.parse(@args)
11     @options[:silent].should==(false)
12     @options[:sudo].should==(false)
13     @options[:geminstaller_output].should==(@geminstaller_output_default)
14     @options[:rubygems_output].should==(@rubygems_output_default)
15   end
16 
17 end
18 
19 describe "an ArgParser instance with bad args" do
20   before(:each) do
21     common_setup
22     @args.push("--badarg")
23   end
24 
25   it "should provide usage in output but no stacktrace" do
26     verify_usage_output
27   end
28 end
29 
30 describe "an ArgParser instance with args which are not nil and are not passed as an array" do
31   before(:each) do
32     common_setup
33     @args = 'not an array'
34   end
35 
36   it "should raise exception" do
37     lambda { @arg_parser.parse(@args) }.should raise_error(GemInstaller::GemInstallerError)
38   end
39 end
40 
41 describe "an ArgParser instance with help flag" do
42   before(:each) do
43     common_setup
44     @args.push("-h")
45   end
46 
47   it "should provide usage in output" do
48     verify_usage_output
49   end
50 end
51 
52 describe "an ArgParser instance with configs option" do
53   before(:each) do
54     common_setup
55     @config_paths = "c:\geminstaller.yml"
56     @args.push("--config=#{@config_paths}")
57   end
58 
59   it "should correctly parse config path from options" do
60     @arg_parser.parse(@args)
61     config_paths = @options[:config_paths]
62     config_paths.should==(@config_paths)
63   end
64 end
65 
66 describe "an ArgParser instance with geminstaller-output option" do
67   before(:each) do
68     common_setup
69   end
70 
71   it "should correctly parse geminstaller output level from options" do
72     @args.push("--geminstaller-output","error,install,info,commandecho,debug")
73     @arg_parser.parse(@args)
74     [:error,:install,:info,:commandecho,:debug].each do |option|
75       @options[:geminstaller_output].should include(option)
76     end
77   end
78 
79   it "should correctly parse geminstaller output level from options" do
80     @args.push("-g","all")
81     @arg_parser.parse(@args)
82     @options[:geminstaller_output].should ==([:all])
83   end
84 
85   it "should raise error and not assign options if invalid geminstaller-output option is given" do
86     invalid = "invalid"
87     @args.push("-g",invalid)
88     @arg_parser.parse(@args)
89     @arg_parser.output.should match(/Invalid geminstaller-output flag: #{invalid}/)
90     @options[:geminstaller_output].should == @geminstaller_output_default
91   end
92 end
93 
94 describe "an ArgParser instance with rubygems-output option" do
95   before(:each) do
96     common_setup
97   end
98 
99   it "should correctly parse rubygems output level from options" do
100     @args.push("--rubygems-output","stderr,STDOUT,stderr")
101     @arg_parser.parse(@args)
102     @options[:rubygems_output].should ==([:stderr,:stdout])
103   end
104 
105   it "should correctly parse rubygems output level from options" do
106     @args.push("-r","all")
107     @arg_parser.parse(@args)
108     @options[:rubygems_output].should ==([:all])
109   end
110 
111   it "should raise error and not assign options if invalid rubygems-output option is given" do
112     invalid = "invalid"
113     @args.push("-r",invalid)
114     @arg_parser.parse(@args)
115     @arg_parser.output.should match(/Invalid rubygems-output flag: #{invalid}/)
116     @options[:rubygems_output].should == @rubygems_output_default
117   end
118 end
119 
120 describe "an ArgParser instance with rubygems-output option and silent option set to true" do
121   before(:each) do
122     common_setup
123   end
124 
125   it "should return error message" do
126     @args.push("--silent")
127     @args.push("--rubygems-output","stderr,stdout")
128     @arg_parser.parse(@args)
129     @arg_parser.output.should match(/The rubygems-output or geminstaller-output option cannot be specified if the silent option is true/)
130   end
131 end
132 
133 describe "an ArgParser instance with silent option" do
134   before(:each) do
135     common_setup
136     @args.push("--silent")
137   end
138 
139   it "should return silent flag as true in options hash" do
140     @arg_parser.parse(@args)
141     @options[:silent].should==(true)
142   end
143 end
144 
145 describe "an ArgParser instance with exceptions option" do
146   before(:each) do
147     common_setup
148     @args.push("--exceptions")
149   end
150 
151   it "should return exceptions flag as true in options hash" do
152     @arg_parser.parse(@args)
153     @options[:exceptions].should==(true)
154   end
155 end
156 
157 describe "an ArgParser instance with redirect-stderr-to-stdout option" do
158   before(:each) do
159     common_setup
160     @args.push("--redirect-stderr-to-stdout")
161   end
162 
163   it "should return redirect_stderr_to_stdout flag as true in options hash" do
164     @arg_parser.parse(@args)
165     @options[:redirect_stderr_to_stdout].should==(true)
166   end
167 end
168 
169 describe "an ArgParser instance with rogue-gems option" do
170   before(:each) do
171     common_setup
172   end
173 
174   it "specified by --print-rogue-gems should return rogue_gems flag as true in options hash" do
175     @args.push("--print-rogue-gems")
176     @arg_parser.parse(@args)
177     @options[:print_rogue_gems].should==(true)
178   end
179 
180   it "specified by --bundler-export should return bundler_export flag as true in options hash" do
181     @args.push("--bundler-export")
182     @arg_parser.parse(@args)
183     @options[:bundler_export].should==(true)
184   end
185 
186   it "specified by -p should return rogue_gems flag as true in options hash" do
187     @args.push("-p")
188     @arg_parser.parse(@args)
189     @options[:print_rogue_gems].should==(true)
190   end
191 end
192 
193 describe "an ArgParser instance with version option" do
194   before(:each) do
195     common_setup
196     @args.push("--version")
197   end
198 
199   it "should return version" do
200     @arg_parser.parse(@args)
201     output = @arg_parser.output
202     output.should match(/#{GemInstaller.version}/)
203   end
204 end
205 
206 describe "an ArgParser instance with sudo option" do
207   before(:each) do
208     common_setup
209     @args.push("--sudo")
210   end
211 
212   it "should return error message (sudo is not yet supported when GemInstaller is invoked programatically)" do
213     @arg_parser.parse(@args)
214     @arg_parser.output.should match(/The sudo option is not .* supported.*/)
215   end
216 end
217 
218 def common_setup
219   @arg_parser = GemInstaller::ArgParser.new
220   @args = []
221   @options = {}
222   @geminstaller_output_default = [:error,:install,:info]
223   @rubygems_output_default = [:stderr]
224   @arg_parser.options = @options
225 end
226 
227 def verify_usage_output
228   @arg_parser.parse(@args)
229   output = @arg_parser.output
230   output.should match(/Usage: geminstaller.*/)
231 end
232 
233 

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