Geminstaller C0 Coverage Information - RCov

spec/unit/application_spec.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/unit/application_spec.rb 217 181
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 application instance invoked with no args" do
5   before(:each) do
6     application_spec_setup_common
7     @mock_arg_parser.should_receive(:parse).with(nil)
8     @mock_arg_parser.should_receive(:output).and_return(nil)
9   end
10   
11   it "should install a gem which is specified in the config and print startup message" do
12     @mock_config_builder.should_receive(:build_config).and_return {@stub_config_local}
13     
14     gems = [@stub_gem]
15     @stub_config.should_receive(:gems).and_return(gems)
16     @mock_install_processor.should_receive(:process).once.with(gems)
17     @mock_output_filter.should_receive(:geminstaller_output).once().with(:debug,/^GemInstaller is verifying gem installation: gemname 1.0/)
18     @application.install
19   end
20 
21   it "should install multiple gems which are specified in the config and print startup message" do
22     @mock_config_builder.should_receive(:build_config).and_return {@stub_config_local}
23     
24     @stub_gem2 = GemInstaller::RubyGem.new("gemname2")
25     gems = [@stub_gem, @stub_gem2]
26     @stub_config.should_receive(:gems).and_return(gems)
27     @mock_install_processor.should_receive(:process).once.with(gems)
28     @mock_output_filter.should_receive(:geminstaller_output).once().with(:debug,/^GemInstaller is verifying gem installation: gemname 1.0, gemname2 > 0.0.0/)
29     @application.install
30   end
31 
32   it "should not install a gem which is already installed" do
33     @mock_config_builder.should_receive(:build_config).and_return {@stub_config_local}
34     
35     @stub_gem.check_for_upgrade = false
36     gems = [@stub_gem]
37     @stub_config.should_receive(:gems).and_return(gems)
38     @mock_install_processor.should_receive(:process).once.with(gems)
39     @mock_output_filter.should_receive(:geminstaller_output).once().with(:debug,/^GemInstaller is verifying gem installation/)
40     @application.install
41   end
42 
43   it "should verify and specify gem if check_for_upgrade is specified" do
44     @mock_config_builder.should_receive(:build_config).and_return {@stub_config_local}
45     
46     @stub_gem.check_for_upgrade = true
47     gems = [@stub_gem]
48     @stub_config.should_receive(:gems).and_return(gems)
49     @mock_install_processor.should_receive(:process).once.with(gems)
50     @mock_output_filter.should_receive(:geminstaller_output).once().with(:debug,/^GemInstaller is verifying gem installation/)
51     @application.install
52   end
53 
54   it "should print any exception message to debug then exit gracefully" do
55     @mock_output_filter.should_receive(:geminstaller_output).once().with(:error,/^GemInstaller::GemInstallerError/)
56     @mock_output_filter.should_receive(:geminstaller_output).once().with(:debug,anything())
57     @mock_config_builder.should_receive(:build_config).and_raise(GemInstaller::GemInstallerError)
58     return_code = @application.install
59     return_code.should ==(1)
60   end
61 
62   it "should print any exception message AND stacktrace" do
63     @mock_output_filter.should_receive(:geminstaller_output).once().with(:error,/^GemInstaller::GemInstallerError/)
64     @mock_output_filter.should_receive(:geminstaller_output).once() # TODO: how to specify Error/stacktrace exception?
65     @mock_config_builder.should_receive(:build_config).and_raise(GemInstaller::GemInstallerError)
66     return_code = @application.install
67     return_code.should==(1)
68   end
69 
70   it ", with --exceptions option, should raise any exception" do
71     @options[:exceptions] = true
72     @mock_output_filter.should_receive(:geminstaller_output).once().with(:error,/^GemInstaller::GemInstallerError/)
73     @mock_output_filter.should_receive(:geminstaller_output).once() # TODO: how to specify Error/stacktrace exception?
74     @mock_config_builder.should_receive(:build_config).and_raise(GemInstaller::GemInstallerError)
75     lambda { @application.install }.should raise_error(GemInstaller::GemInstallerError)
76   end
77 end
78 
79 describe "an application instance invoked with invalid args or help option" do
80   before(:each) do
81     application_spec_setup_common
82   end
83 
84   it "should print any arg parser error output then exit gracefully" do
85     arg_parser_output = "arg parser output"
86     @mock_output_filter.should_receive(:geminstaller_output).with(:error,/^arg parser output/)
87     @mock_arg_parser.should_receive(:parse).with(nil).and_return(1)
88     @mock_arg_parser.should_receive(:output).and_return(arg_parser_output)
89     return_code = @application.install
90     return_code.should==(1)
91   end
92 
93   it "should print any arg parser non-error output then exit gracefully" do
94     arg_parser_output = "arg parser output"
95     @mock_output_filter.should_receive(:geminstaller_output).with(:info,/^arg parser output/)
96     @mock_arg_parser.should_receive(:parse).with(nil).and_return(0)
97     @mock_arg_parser.should_receive(:output).and_return(arg_parser_output)
98     return_code = @application.install
99     return_code.should==(0)
100   end
101 end
102 
103 describe "an application instance invoked with missing config file(s)" do
104   before(:each) do
105     application_spec_setup_common
106   end
107 
108   it "should print message and exit gracefully" do
109     @mock_output_filter.should_receive(:geminstaller_output).with(:error,/^Error: A GemInstaller config file is missing/m)
110     @mock_output_filter.should_receive(:geminstaller_output).once().with(:debug,anything())
111     @mock_arg_parser.should_receive(:parse).with(nil).and_return(0)
112     @mock_arg_parser.should_receive(:output).and_return('')
113     @mock_config_builder.should_receive(:build_config).and_raise(GemInstaller::MissingFileError)
114     return_code = @application.install
115     return_code.should==(1)
116   end
117   
118   it "should still run print-rogue-gems option if it is specified and there is only a single config file" do
119     @options[:print_rogue_gems] = true
120     @mock_arg_parser.should_receive(:parse).with(nil).and_return(0)
121     @mock_arg_parser.should_receive(:output).and_return('')
122     @mock_config_builder.should_receive(:build_config).and_raise(GemInstaller::MissingFileError)
123     single_config = ['single_config_file.yml']
124     @mock_config_builder.should_receive(:config_file_paths_array).twice.and_return(single_config)
125     @mock_rogue_gem_finder.should_receive(:print_rogue_gems).once().with([], single_config)
126     return_code = @application.install
127     return_code.should==(0)
128   end
129 
130   it "should not run print-rogue-gems option if there is more than one missing config file" do
131   end
132 end
133 
134 describe "an application instance invoked with alternate config file location" do
135   before(:each) do
136     application_spec_setup_common
137     @mock_output_filter.should_receive(:geminstaller_output).with(:debug,anything())
138   end
139 
140   it "should use the alternate config file location" do
141     config_paths = 'config_paths'
142     @mock_arg_parser.should_receive(:parse).with(nil)
143     @options[:config_paths] = config_paths
144     @mock_arg_parser.should_receive(:output)
145     @mock_config_builder.should_receive(:config_file_paths=).with(config_paths).and_return {@stub_config_local}
146     @mock_config_builder.should_receive(:build_config).and_return {@stub_config_local}
147     
148     gems = [@stub_gem]
149     @stub_config.should_receive(:gems).and_return(gems)
150     @mock_install_processor.should_receive(:process).once.with(gems)
151     @application.install
152   end
153 end
154 
155 describe "an application instance invoked with print-rogue-gems arg" do
156   before(:each) do
157     application_spec_setup_common
158     @mock_arg_parser.should_receive(:parse).with(nil)
159     @mock_arg_parser.should_receive(:output).and_return(nil)
160     @options[:print_rogue_gems] = true
161   end
162 
163   it "should invoke rogue_gem_finder" do
164     
165     @mock_config_builder.should_receive(:build_config).and_return {@stub_config_local}
166     
167     gems = [@stub_gem]
168     @stub_config.should_receive(:gems).and_return(gems)
169     
170     paths = []
171     @mock_config_builder.should_receive(:config_file_paths_array).once.and_return(paths)
172     @mock_rogue_gem_finder.should_receive(:print_rogue_gems).once().with(gems, paths)
173     
174     @application.install
175   end
176 end
177 
178 describe "an application instance invoked with bundler-export arg" do
179   before(:each) do
180     application_spec_setup_common
181     @mock_arg_parser.should_receive(:parse).with(nil)
182     @mock_arg_parser.should_receive(:output).and_return(nil)
183     @options[:bundler_export] = true
184   end
185 
186   it "should invoke bundler_export" do    
187     @mock_config_builder.should_receive(:build_config).and_return {@stub_config_local}
188     @mock_bundler_exporter.should_receive(:output).once().with(@stub_config_local)
189     @application.install
190   end
191 end
192 
193 
194 def application_spec_setup_common
195   @mock_arg_parser = mock("Mock Arg Parser")
196   @mock_config_builder = mock("Mock Config Builder")
197   @stub_config = mock("Mock Config")
198   @mock_install_processor = mock("Mock InstallProcessor")
199   @mock_output_filter = mock("Mock Output Filter")
200   @stub_gem = GemInstaller::RubyGem.new("gemname", :version => "1.0")
201   @mock_rogue_gem_finder = mock("Mock RogueGemFinder")
202   @mock_bundler_exporter = mock("Mock BundlerExporter")
203   @options = {}
204 
205   @stub_config_local = @stub_config
206 
207   @application = GemInstaller::Application.new
208   @application.options = @options
209   @application.arg_parser = @mock_arg_parser
210   @application.config_builder = @mock_config_builder
211   @application.install_processor = @mock_install_processor
212   @application.output_filter = @mock_output_filter
213   @application.rogue_gem_finder = @mock_rogue_gem_finder
214   @application.bundler_exporter = @mock_bundler_exporter
215 end
216 
217 

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