<commit_before>require 'spec_helper'
require 'pathname'

module Seahorse
  module  Client
    module Logging
      describe Formatter do

        let(:response) { Response.new }

        def format(pattern, options = {})
          Logging::Formatter.new(pattern, options).format(response)
        end

        describe '#format' do

          it 'provides a :client_class replacement' do
            response.context.client = String.new
            expect(format(':client_class')).to eq('String')
          end

          it 'provides a :operation replacement' do
            response.context.operation_name = 'operation-name'
            expect(format(':operation')).to eq('operation-name')
          end

          it 'provides a :request_params replacement' do
            response.context.params = {
              foo: 'bar',
              attributes: {
                'color' => 'red',
                'size' => 'large'
              },
              config: {
                nested: true,
                values: [1,2,3],
                file: File.open('Rakefile'),
                path: Pathname.new('Rakefile'),
                complex: double('obj', inspect: '"inspected"')
              },
              huge: '-' * 1000
            }
            formatted = format('{:request_params}', max_string_size: 20)
            size = File.size('Rakefile')
            expect(formatted).to eq(<<-FORMATTED.strip)
{foo:"bar",attributes:{"color"=>"red","size"=>"large"},config:{nested:true,values:[1,2,3],file:#<File:Rakefile (#{size} bytes)>,path:#<File:Rakefile (#{size} bytes)>,complex:"inspected"},huge:#<String "--------------------" ... (1000 bytes)>}
            FORMATTED
          end

          it 'provides a :time replacement' do
            now = Time.now
            response.context[:logging_started_at] = now - 1.54321
            response.context[:logging_completed_at] = now
            expect(format(':time')).to eq('1.54321')
          end<commit_msg>Resolved an issue causing spec to be fragile.<commit_after>require 'spec_helper'
require 'pathname'

module Seahorse
  module  Client
    module Logging
      describe Formatter do

        let(:response) { Response.new }

        def format(pattern, options = {})
          Logging::Formatter.new(pattern, options).format(response)
        end

        describe '#format' do

          it 'provides a :client_class replacement' do
            response.context.client = String.new
            expect(format(':client_class')).to eq('String')
          end

          it 'provides a :operation replacement' do
            response.context.operation_name = 'operation-name'
            expect(format(':operation')).to eq('operation-name')
          end

          it 'provides a :request_params replacement' do
            response.context.params = {
              foo: 'bar',
              attributes: {
                'color' => 'red',
                'size' => 'large'
              },
              config: {
                nested: true,
                values: [1,2,3],
                file: File.open(__FILE__),
                path: Pathname.new(__FILE__),
                complex: double('obj', inspect: '"inspected"')
              },
              huge: '-' * 1000
            }
            formatted = format('{:request_params}', max_string_size: 20)
            size = File.size(__FILE__)
            expect(formatted).to eq(<<-FORMATTED.strip)
{foo:"bar",attributes:{"color"=>"red","size"=>"large"},config:{nested:true,values:[1,2,3],file:#<File:#{__FILE__} (#{size} bytes)>,path:#<File:#{__FILE__} (#{size} bytes)>,complex:"inspected"},huge:#<String "--------------------" ... (1000 bytes)>}
            FORMATTED
          end

          it 'provides a :time replacement' do
            now = Time.now
            response.context[:logging_started_at] = now - 1.54321
            response.context[:logging_completed_at] = now
            expect(format(':time')).to eq('1.54321')
          end
{'fraction_non_alphanumeric': 0.14547738693467338, 'fraction_numerical': 0.01407035175879397, 'mean_word_length': 1.8660907127429807, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '6343663', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1070, 'n_words': 222}