# frozen_string_literal: true

RSpec.describe Helium::Console do
  it 'has a version number' do
    expect(Helium::Console::VERSION).not_to be nil
  end

  describe '#format' do
    subject(:console) { described_class.new(instance_registry: instance_registry, class_registry: class_registry) }

    let(:test_class) { Class.new }
    let(:object) { test_class.new }
    let(:instance_registry) { instance_double Helium::Console::Registry }
    let(:class_registry) { instance_double Helium::Console::Registry }

    let(:style) { [nil, :compact, :inline, :partial, :full].sample }
    let(:options) { Array.new(3) { FFaker::Lorem.words(2) }.to_h.transform_keys(&:to_sym) }

    describe 'formatting instance' do
      let(:object) { test_class.new }

      let(:result) { FFaker::Lorem.sentence }
      let(:formatter_class) { class_double Helium::Console::Formatter }
      let(:formatter) { instance_double Helium::Console::Formatter, call: result }

      before do
        allow(formatter_class).to receive(:new).with(object, style, console, instance_of(Hash)).and_return(formatter)
        allow(instance_registry).to receive(:handler_for).with(test_class).and_return(formatter_class)
      end

      it 'returns the result of formatting handler' do
        expect(console.format(object, style, **options)).to eq result
      end
    end
  end
end
