Geminstaller C0 Coverage Information - RCov

spec/unit/enhanced_stream_ui_spec.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/unit/enhanced_stream_ui_spec.rb 110 84
77.27%
78.57%

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 EnhancedStreamUI instance with an OutputProxy injected for outs and errs" do
5   
6   before(:each) do
7     # Can't use an rspec mock here, because you can't mock the 'puts' method
8     stub_in_stream = StringIO.new("1")
9     stub_out_stream = StringIO.new("","w")
10     @enhanced_stream_ui = GemInstaller::EnhancedStreamUI.new
11     @outs_output_observer = GemInstaller::OutputObserver.new
12     @errs_output_observer = GemInstaller::OutputObserver.new
13     @enhanced_stream_ui.outs = @outs_output_observer
14     @outs_output_observer.stream = :stdout
15     @enhanced_stream_ui.errs = @errs_output_observer
16     @errs_output_observer.stream = :stderr
17 
18     @mock_outs_listener = mock('mock_outs_listener')
19     @outs_output_observer.register(@mock_outs_listener)
20 
21     @mock_errs_listener = mock('mock_errs_listener')
22     @errs_output_observer.register(@mock_errs_listener)
23   end
24 
25   it "will throw unexpected prompt error for ask" do
26     question = 'question'
27     lambda{ @enhanced_stream_ui.ask(question) }.should raise_error(GemInstaller::UnexpectedPromptError)
28   end
29 
30   it "will throw unexpected prompt error for ask_yes_no if question is not a dependency prompt" do
31     mock_gem_interaction_handler = mock("Mock GemInteractionHandler")
32     if GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4')
33       # special handling for dependency prompts in ask_yes_no is not used for RubyGems >= 0.9.5,
34       # all prompts are considered unexpected
35       mock_gem_interaction_handler.should_receive(:handle_ask_yes_no)
36       @enhanced_stream_ui.gem_interaction_handler = mock_gem_interaction_handler
37     end
38     question = 'question'
39     lambda{ @enhanced_stream_ui.ask_yes_no(question) }.should raise_error(GemInstaller::UnexpectedPromptError)
40   end
41 
42   it "will force throw of GemInstaller::UnauthorizedDependencyPromptError or RubyGemsExit if intercepted by alert_error" do
43     begin
44       raise GemInstaller::UnauthorizedDependencyPromptError.new
45     rescue StandardError => error
46       lambda{ @enhanced_stream_ui.alert_error('statement') }.should raise_error(GemInstaller::UnauthorizedDependencyPromptError)
47     end
48 
49     begin
50       raise GemInstaller::RubyGemsExit.new
51     rescue StandardError => error
52       lambda{ @enhanced_stream_ui.alert_error('statement') }.should raise_error(GemInstaller::RubyGemsExit)
53     end
54   end
55 
56   it "can listen to error stream" do
57     statement = 'statement'
58     @mock_errs_listener.should_receive(:notify).once.with('ERROR:  ' + statement + "\n", :stderr)
59     @enhanced_stream_ui.alert_error(statement)
60   end
61   
62   it "will stop listening to streams if listeners are unregistered" do
63     statement = 'statement'
64     @mock_errs_listener.should_receive(:notify).once.with('ERROR:  ' + statement + "\n", :stderr)
65     @mock_outs_listener.should_receive(:notify).once.with(statement + "\n", :stdout)
66     # listeners should receive messages when they are registered
67     @enhanced_stream_ui.alert_error(statement)
68     @enhanced_stream_ui.say(statement)
69 
70     # listeners should no longer receive messages when they are unregistered
71     @outs_output_observer.unregister(@mock_outs_listener)
72     @errs_output_observer.unregister(@mock_errs_listener)
73     @enhanced_stream_ui.alert_error(statement)
74     @enhanced_stream_ui.say(statement)
75     
76   end
77   
78   if GemInstaller::RubyGemsVersionChecker.matches?('<=1.0.1')
79   # no more special handling of terminate_interaction required after 1.0.1
80   it "will raise exception on terminate_interaction! (instead of exiting)" do
81     lambda{ @enhanced_stream_ui.terminate_interaction!(0) }.should raise_error(GemInstaller::GemInstallerError)
82   end
83 
84   it "will raise RubyGemsExit on terminate_interaction and status == 0 (instead of exiting)" do
85     lambda{ @enhanced_stream_ui.terminate_interaction(0) }.should raise_error(GemInstaller::RubyGemsExit)
86   end
87 
88   it "will raise exception on terminate_interaction and status != 0 (instead of exiting)" do
89     lambda{ @enhanced_stream_ui.terminate_interaction(1) }.should raise_error(GemInstaller::GemInstallerError)
90   end
91   end
92   
93   it "will call gem_interaction_handler when ask_yes_no is called" do
94     mock_gem_interaction_handler = mock("mock_gem_interaction_handler")
95     if GemInstaller::RubyGemsVersionChecker.matches?('<=0.9.4')
96       @enhanced_stream_ui.gem_interaction_handler = mock_gem_interaction_handler
97       # special handling for dependency prompts in ask_yes_no is not used for RubyGems >= 0.9.5,
98       # all prompts are considered unexpected
99       question = 'question'
100       @mock_outs_listener.should_receive(:notify).once.with(question, :stdout)
101       error = GemInstaller::UnauthorizedDependencyPromptError
102       mock_gem_interaction_handler.should_receive(:handle_ask_yes_no).with(question).and_raise(error)
103     else
104       error = GemInstaller::UnexpectedPromptError
105     end
106     lambda{ @enhanced_stream_ui.ask_yes_no(question) }.should raise_error(error)
107   end
108 
109 
110 end

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