Geminstaller C0 Coverage Information - RCov

spec/functional/gem_runner_proxy_spec.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/functional/gem_runner_proxy_spec.rb 135 111
93.33%
93.69%

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 GemRunnerProxy instance" do
5   before(:each) do
6     GemInstaller::TestGemHome.use
7     @registry = GemInstaller::create_registry
8     @gem_runner_proxy = @registry.gem_runner_proxy
9     @gem_interaction_handler = @registry.gem_interaction_handler if GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4') 
10   end
11 
12   it "should return output of gem command" do
13     gem_runner_args = ["list", "#{sample_multiplatform_gem_name}", "--remote"]
14     gem_runner_args += ['--all'] if GemInstaller::RubyGemsVersionChecker.matches?('>=1.1.1')
15     gem_runner_args += install_options_for_testing
16 
17     output = @gem_runner_proxy.run(gem_runner_args)
18     
19     if GemInstaller::RubyGemsVersionChecker.matches?('=0.9.5')
20       # bug in 0.9.5 that double-lists versions
21       expected_versions = "#{sample_multiplatform_gem_version}, #{sample_multiplatform_gem_version}, #{sample_multiplatform_gem_version_low}"
22     elsif GemInstaller::RubyGemsVersionChecker.matches?('<=1.3.6')
23       # no platforms in output prior to 1.3.7
24       expected_versions = "#{sample_multiplatform_gem_version}, #{sample_multiplatform_gem_version_low}"
25     else
26       expected_versions = "#{sample_multiplatform_gem_version} ruby mswin32, #{sample_multiplatform_gem_version_low}"
27     end
28     
29     expected_output = /#{sample_multiplatform_gem_name} \(#{expected_versions}\)/m
30     output.join("\n").should match(expected_output)
31   end
32 
33   it "should return multi-line output as an array" do
34     gem_runner_args = ["search", "--remote"]
35     gem_runner_args += install_options_for_testing
36     
37     output = @gem_runner_proxy.run(gem_runner_args)
38     
39     output.size.should be > 1
40   end
41 
42   it "should not throw an error if there is an normal rubygems exit via terminate_interaction" do
43     gem_runner_args = ["--help"]
44   
45     output = @gem_runner_proxy.run(gem_runner_args)
46     expected_output = /Usage:/m
47     output.join("\n").should match(expected_output)
48   end
49 
50   it "should return error output if there is an abnormal exit" do
51     gem_runner_args = ["bogus_command"]
52 
53     begin
54       @gem_runner_proxy.run(gem_runner_args)
55     rescue GemInstaller::GemInstallerError => error
56       expected_error_message = /Gem command was:.*gem bogus_command.*Gem command output was:.*Unknown command bogus_command/m
57       error.message.should match(expected_error_message)
58     end
59   end
60 
61   it "should return descriptive message if there was an unexpected prompt due to unmet dependency" do
62     use_mocks
63     @mock_gem_runner.should_receive(:run).and_raise(GemInstaller::UnauthorizedDependencyPromptError.new("unexpected dependency error message"))
64     dependency_prompt = 'Install required dependency somegem? [Yn]'
65     @mock_output_listener.should_receive(:read!).and_return([dependency_prompt])
66     begin
67       @gem_runner_proxy.run(['install'])
68     rescue GemInstaller::GemInstallerError => error
69       expected_error_message = /unexpected dependency error message.*Gem command was:.*install.*Gem command output was:.*Install required dependency/m
70       error.message.should match(expected_error_message)
71     end
72   end
73 
74   it "should return generic error output if there was an unexpected prompt due to something other than an unmet dependency" do
75     use_mocks
76     @mock_gem_runner.should_receive(:run).and_raise(GemInstaller::UnexpectedPromptError.new("unexpected prompt"))
77     unexpected_prompt = 'some unexpected prompt?'
78     @mock_output_listener.should_receive(:read!).and_return([unexpected_prompt])
79     begin
80       @gem_runner_proxy.run(['install'])
81     rescue GemInstaller::GemInstallerError => error
82       expected_error_message = /Gem command was:.*install.*Gem command output was:.*#{unexpected_prompt}/m
83       error.message.should match(expected_error_message)
84     end
85   end
86 
87   it "returns custom error output if there was an access error" do
88     use_mocks
89     error_message = "error message"
90     @mock_gem_runner.should_receive(:run).and_raise(GemInstaller::GemInstallerError.new(error_message))
91     access_error = 'Errno::EACCES'
92     @mock_output_listener.should_receive(:read!).and_return([access_error])
93     begin
94       @gem_runner_proxy.run(['install'])
95     rescue GemInstaller::GemInstallerAccessError => error
96       expected_error_message = /don't have permission.*Gem command was:.*install.*Gem command output was:.*#{access_error}/m
97       error.message.should match(expected_error_message)
98     end
99   end
100 
101   it "should choose from list" do
102     gem_runner_args = ["install", "#{sample_multiplatform_gem_name}", "--remote"]
103     gem_runner_args += install_options_for_testing
104 
105     @gem_interaction_handler.dependent_gem = sample_multiplatform_gem if GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4') 
106     output = @gem_runner_proxy.run(gem_runner_args)
107     output.join("\n").should match(/Successfully installed #{sample_multiplatform_gem_name}-#{sample_multiplatform_gem_version}/m)
108   end
109   
110   after(:each) do
111     GemInstaller::TestGemHome.uninstall_all_test_gems
112   end
113 
114   def use_mocks
115     @mock_gem_runner = mock("Mock Gem Runner")
116     @mock_output_listener = mock("Mock Output Listener")
117     @gem_runner_proxy.instance_eval do
118       def gem_runner=(runner)
119         @gem_runner = runner
120       end
121       
122       def output_listener=(listener)
123        @output_listener = listener
124      end
125      
126       def create_gem_runner
127         return @gem_runner
128       end
129     end
130     @gem_runner_proxy.gem_runner = @mock_gem_runner
131     @gem_runner_proxy.output_listener = @mock_output_listener
132     
133     @mock_gem_runner.should_receive(:do_configuration)
134   end
135 end

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