<commit_before>dir = File.dirname(__FILE__)
require File.expand_path("#{dir}/../helper/spec_helper")

context "An EnhancedStreamUI instance with an OutputProxy injected for outs and errs" do
  
  setup do
    # Can't use an rspec mock here, because you can't mock the 'puts' method
    stub_in_stream = StringIO.new("1")
    stub_out_stream = StringIO.new("","w")
    @enhanced_stream_ui = GemInstaller::EnhancedStreamUI.new
    @outs_output_observer = GemInstaller::OutputObserver.new
    @errs_output_observer = GemInstaller::OutputObserver.new
    @enhanced_stream_ui.outs = @outs_output_observer
    @outs_output_observer.stream = :stdout
    @enhanced_stream_ui.errs = @errs_output_observer
    @errs_output_observer.stream = :stderr

    @mock_outs_listener = mock('mock_outs_listener')
    @outs_output_observer.register(@mock_outs_listener)

    @mock_errs_listener = mock('mock_errs_listener')
    @errs_output_observer.register(@mock_errs_listener)
  end

  specify "will throw unexpected prompt error if there is no queued input" do
    question = 'question'
    lambda{ @enhanced_stream_ui.ask(question) }.should_raise(GemInstaller::UnexpectedPromptError)
  end

  specify "will force throw of GemInstaller::UnauthorizedDependencyPromptError or RubyGemsExit if intercepted by alert_error" do
    begin
      raise GemInstaller::UnauthorizedDependencyPromptError.new
    rescue StandardError => error
      lambda{ @enhanced_stream_ui.alert_error('statement') }.should_raise(GemInstaller::UnauthorizedDependencyPromptError)
    end

    begin
      raise GemInstaller::RubyGemsExit.new
    rescue StandardError => error
      lambda{ @enhanced_stream_ui.alert_error('statement') }.should_raise(GemInstaller::RubyGemsExit)
    end
  end

  specify "can listen to error stream" do<commit_msg> r<EMAIL>:  woolley | 2007-04-08 01:21:49 -0700  refactoring and code coverage for enhanced_stream_ui<commit_after>dir = File.dirname(__FILE__)
require File.expand_path("#{dir}/../helper/spec_helper")

context "An EnhancedStreamUI instance with an OutputProxy injected for outs and errs" do
  
  setup do
    # Can't use an rspec mock here, because you can't mock the 'puts' method
    stub_in_stream = StringIO.new("1")
    stub_out_stream = StringIO.new("","w")
    @enhanced_stream_ui = GemInstaller::EnhancedStreamUI.new
    @outs_output_observer = GemInstaller::OutputObserver.new
    @errs_output_observer = GemInstaller::OutputObserver.new
    @enhanced_stream_ui.outs = @outs_output_observer
    @outs_output_observer.stream = :stdout
    @enhanced_stream_ui.errs = @errs_output_observer
    @errs_output_observer.stream = :stderr

    @mock_outs_listener = mock('mock_outs_listener')
    @outs_output_observer.register(@mock_outs_listener)

    @mock_errs_listener = mock('mock_errs_listener')
    @errs_output_observer.register(@mock_errs_listener)
  end

  specify "will throw unexpected prompt error for ask" do
    question = 'question'
    lambda{ @enhanced_stream_ui.ask(question) }.should_raise(GemInstaller::UnexpectedPromptError)
  end

  specify "will throw unexpected prompt error for ask_yes_no if question is not a dependency prompt" do
    mock_gem_interaction_handler = mock("Mock GemInteractionHandler")
    mock_gem_interaction_handler.should_receive(:handle_ask_yes_no)
    @enhanced_stream_ui.gem_interaction_handler = mock_gem_interaction_handler
    question = 'question'
    lambda{ @enhanced_stream_ui.ask_yes_no(question) }.should_raise(GemInstaller::UnexpectedPromptError)
  end

  specify "will force throw of GemInstaller::UnauthorizedDependencyPromptError or RubyGemsExit if intercepted by alert_error" do
    begin
      raise GemInstaller::UnauthorizedDependencyPromptError.new
    rescue StandardError => error
      lambda{ @enhanced_stream_ui.alert_error('statement') }.should_raise(GemInstaller::UnauthorizedDependencyPromptError)
    end

    begin
      raise GemInstaller::RubyGemsExit.new
    rescue StandardError => error
      lambda{ @enhanced_stream_ui.alert_error('statement') }.should_raise(GemInstaller::RubyGemsExit)
    end
  end

  specify "can listen to error stream" do
{'fraction_non_alphanumeric': 0.0835553402760959, 'fraction_numerical': 0.004843787842092516, 'mean_word_length': 5.238670694864048, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1064808', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1250, 'n_words': 268}