<commit_before>require 'spec_helper'

RSpec.describe Pdfinfo do
  let(:pdf_path) { fixture_path('pdfs/test.pdf') }
  let(:pdfinfo) { described_class.new(pdf_path) }
  let(:encrypted_response) { File.read(fixture_path('shell_responses/encrypted.txt')).chomp }
  let(:unencrypted_response) { File.read(fixture_path('shell_responses/test.txt')).chomp }
  let(:mock_response) { unencrypted_response }

  def modified_response(response, key, new_value = '')
    response.sub(/(?<=#{key}:)(.+)$/, new_value)
  end

  def response_without_key(response, key)
    response.sub(%r{#{key}.*\n}, '')
  end

  before(:each) do |ex|
    unless ex.metadata[:skip_mock_response]
      allow(Open3).to receive(:capture2).and_return([mock_response, nil])
    end
  end

  specify 'mock responses match', :skip_mock_response, :pending => "issues with inconsistent fixture generation" do
    unless ENV['CI']
      expect(`pdfinfo -upw foo #{fixture_path('pdfs/encrypted.pdf')}`.chomp).to eq(encrypted_response)
      expect(`pdfinfo #{fixture_path('pdfs/test.pdf')}`.chomp).to eq(unencrypted_response)
    end
  end

  describe '.pdfinfo_command' do
    it 'falls back to pdfinfo' do<commit_msg>skip instead of pend test<commit_after>require 'spec_helper'

RSpec.describe Pdfinfo do
  let(:pdf_path) { fixture_path('pdfs/test.pdf') }
  let(:pdfinfo) { described_class.new(pdf_path) }
  let(:encrypted_response) { File.read(fixture_path('shell_responses/encrypted.txt')).chomp }
  let(:unencrypted_response) { File.read(fixture_path('shell_responses/test.txt')).chomp }
  let(:mock_response) { unencrypted_response }

  def modified_response(response, key, new_value = '')
    response.sub(/(?<=#{key}:)(.+)$/, new_value)
  end

  def response_without_key(response, key)
    response.sub(%r{#{key}.*\n}, '')
  end

  before(:each) do |ex|
    unless ex.metadata[:skip_mock_response]
      allow(Open3).to receive(:capture2).and_return([mock_response, nil])
    end
  end

  specify 'mock responses match', :skip_mock_response, :skip do
    unless ENV['CI']
      expect(`pdfinfo -upw foo #{fixture_path('pdfs/encrypted.pdf')}`.chomp).to eq(encrypted_response)
      expect(`pdfinfo #{fixture_path('pdfs/test.pdf')}`.chomp).to eq(unencrypted_response)
    end
  end

  describe '.pdfinfo_command' do
    it 'falls back to pdfinfo' do
{'fraction_non_alphanumeric': 0.15397923875432526, 'fraction_numerical': 0.0017301038062283738, 'mean_word_length': 4.946015424164524, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '3058642', 'n_tokens_mistral': 805, 'n_tokens_neox': 800, 'n_words': 138}