<commit_before>require 'spec_helper'
require 'stringio'
require 'timecop'

describe ProgressBar::Base do
  before do
    @output = StringIO.new('', 'w+')
    @progressbar = ProgressBar::Base.new(:output => @output, :length => 80)
  end

  context 'when a new bar is created' do
    context 'and no options are passed' do
      before { @progressbar = ProgressBar::Base.new }

      describe '#title' do
        it 'returns the default title' do
          @progressbar.send(:title).to_s.should eql ProgressBar::Base::DEFAULT_TITLE
        end
      end

      describe '#output' do
        it 'returns the default output stream' do
          @progressbar.send(:output).should eql ProgressBar::Base::DEFAULT_OUTPUT_STREAM
        end
      end

      describe '#length' do
        it 'returns the width of the terminal if it is a Unix environment' do
          @progressbar.stub(:terminal_width).and_return(99)
          @progressbar.send(:reset_length) # This should be changed to use #any_instance
          @progressbar.send(:length).should eql 99
        end
      end

      describe '#length' do
        it 'returns 80 if it is not a Unix environment' do
          @progressbar.stub(:unix?).and_return(false)
          @progressbar.send(:reset_length) # This should be changed to use #any_instance
          @progressbar.send(:length).should eql 80
        end
      end
    end

    context 'and the RUBY_PROGRESS_BAR_LENGTH environment variable exists' do
      before { ENV['RUBY_PROGRESS_BAR_LENGTH'] = '44' ; @progressbar = ProgressBar::Base.new }
      after { ENV['RUBY_PROGRESS_BAR_LENGTH'] = nil }

      describe '#length' do
        it 'returns the length of the environment variable as an integer' do
          @progressbar.send(:length).should == 44<commit_msg>Rework #length specs now that we have a more complex set of specifications<commit_after>require 'spec_helper'
require 'stringio'
require 'timecop'

describe ProgressBar::Base do
  before do
    @output = StringIO.new('', 'w+')
    @progressbar = ProgressBar::Base.new(:output => @output, :length => 80)
  end

  context 'when a new bar is created' do
    context 'and no options are passed' do
      before { @progressbar = ProgressBar::Base.new }

      describe '#title' do
        it 'returns the default title' do
          @progressbar.send(:title).to_s.should eql ProgressBar::Base::DEFAULT_TITLE
        end
      end

      describe '#output' do
        it 'returns the default output stream' do
          @progressbar.send(:output).should eql ProgressBar::Base::DEFAULT_OUTPUT_STREAM
        end
      end

      describe '#length' do
        context 'when the RUBY_PROGRESS_BAR_LENGTH environment variable exists' do
          before  { ENV['RUBY_PROGRESS_BAR_LENGTH'] = '44' }
          after   { ENV['RUBY_PROGRESS_BAR_LENGTH'] = nil }

          it 'returns the length of the environment variable as an integer' do
            @progressbar = ProgressBar::Base.new
            @progressbar.send(:length).should eql 44
          end
        end

        context 'when the RUBY_PROGRESS_BAR_LENGTH environment variable does not exist' do
          before  { ENV['RUBY_PROGRESS_BAR_LENGTH'] = nil }

          context 'but the length option was passed in' do
            it 'returns the length specified in the option' do
              @progressbar = ProgressBar::Base.new(:length => 88)
              @progressbar.send(:length).should eql 88
            end
          end

          context 'and no length option was passed in' do
            it 'returns the width of the terminal if it is a Unix environment' do
              @progressbar.stub(:terminal_width).and_return(99)
              @progressbar.send(:reset_length)
              @progressbar.send(:length).should eql 99
            end

            it 'returns 80 if it is not a Unix environment' do
              @progressbar.stub(:unix?).and_return(false)
              @progressbar.send(:reset_length)
              @progressbar.send(:length).should eql 80
            end
          end
{'fraction_non_alphanumeric': 0.08845391476709613, 'fraction_numerical': 0.007928642220019821, 'mean_word_length': 2.5043402777777777, 'pattern_counts': {'":': 0, '<': 3, '<?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': '753054', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1097, 'n_words': 360}