describe 'PuppetShow' do
  describe 'Log' do
    describe 'Logger' do
      subject(:logger) {
        Class.new do
          include PuppetShow::Log::Logger
        end.new
      }

      describe '#log_output' do
        it 'logs a new output into a buffer' do
          logger.log_output("Hello World!")
          logger.log_output("This is an output!")
        end
      end

      describe '#log_error' do
        it 'logs a new error into a buffer' do
          logger.log_output("Hello World!")
          logger.log_output("This is an error!")
        end
      end

      describe '#outputs?' do
        context 'when there is no output logged' do
          it 'returns false' do
            expect(logger.outputs?).to be(false)
          end
        end

        context 'when there is at least one output logged' do
          let(:output1) { "Hello World!" }
          let(:output2) { "This has to be logged!" }
          let(:output3) { "It is important" }

          it 'returns true' do
            logger.log_output(output1)
            logger.log_output(output2)
            logger.log_output(output3)

            expect(logger.outputs?).to be(true)
          end
        end
      end

      describe '#errors?' do
        context 'when there is no error logged' do
          it 'returns false' do
            expect(logger.errors?).to be(false)
          end
        end


        context 'when there is at least one output logged' do
          let(:error1) { "Hello World!" }
          let(:error2) { "This has to be logged!" }
          let(:error3) { "It is important" }

          it 'returns true' do
            logger.log_error(error1)
            logger.log_error(error2)
            logger.log_error(error3)

            expect(logger.errors?).to be(true)
          end
        end
      end

      describe '#outputs' do
        context 'when there is no output logged' do
          it 'returns the empty string' do
            expect(logger.outputs).to eq('')
          end
        end

        context 'when there is at least one output logged' do
          let(:output1) { "Hello World!" }
          let(:output2) { "This has to be logged!" }
          let(:output3) { "It is important" }
          let(:output) { output1 + "\n" + output2 + "\n" + output3 }

          it 'returns a string which is the concatenation of all outputs' do
            logger.log_output(output1)
            logger.log_output(output2)
            logger.log_output(output3)

            expect(logger.outputs).to eq(output)
          end
        end
      end

      describe '#errors' do
        context 'when there is no error logged' do
          it 'returns the empty string' do
            expect(logger.outputs).to eq('')
          end
        end

        context 'when there is at least one error logged' do
          let(:error1) { "Hello World!" }
          let(:error2) { "This has to be logged!" }
          let(:error3) { "It is important" }
          let(:error) { error1 + "\n" + error2 + "\n" + error3 }

          it 'returns a string which is the concatenation of all errors' do
            logger.log_error(error1)
            logger.log_error(error2)
            logger.log_error(error3)

            expect(logger.errors).to eq(error)
          end
        end
      end
    end
  end
end
