Sha256: 3af489bfc3b4e2d98af18e1b565dccddac36838eb3eee8d35f0418db286ebc04

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe RspecProgressBar::Formatter do
  let(:io) { double }
  let(:formatter) { described_class.new(io) }

  it 'inherits from RSpec::Core::Formatters::BaseTextFormatter' do
    expect(formatter).to be_a(RSpec::Core::Formatters::BaseTextFormatter)
  end

  describe '#initialize' do
    it 'assigns @output' do
      expect(formatter.instance_variable_get(:@output)).to eq(io)
    end
  end

  describe '#start' do
    let(:notification) { double(count: 100) }

    it 'initializes progress bar' do
      expect { formatter.start(notification) }
        .to change { formatter.progress_bar }
          .from(nil)
          .to(ProgressBar)

      expect(formatter.progress_bar.max).to eq(100)
      expect(formatter.progress_bar.count).to eq(0)
    end
  end

  describe '#example_started' do
    let(:notification) { double(count: 100) }

    before do
      formatter.start(notification)
      allow(io).to receive(:<<)
      allow(io).to receive(:flush)
      allow(formatter.progress_bar)
        .to receive(:to_s)
        .and_return('PROGRESS')
    end

    it 'increments progress bar count' do
      expect { formatter.example_started(notification) }
        .to change { formatter.progress_bar.count }
          .from(0)
          .to(1)
    end

    it 'prints progress' do
      formatter.example_started(notification)

      expect(io)
        .to have_received(:<<)
        .with("\rPROGRESS")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-progress-bar-0.1.2 spec/lib/rspec_progress_bar/formatter_spec.rb