<commit_before>require File.join(File.dirname(__FILE__), '..', 'lib', 'recipient_interceptor')

describe RecipientInterceptor do
  it 'overrides to/cc/bcc fields, copies original fields to custom headers' do
    Mail.register_interceptor RecipientInterceptor.new('<EMAIL>')

    response = deliver_mail

    expect(response.to).to eq ['<EMAIL>']
    expect(response.cc).to eq []
    expect(response.bcc).to eq []

    expect(response.header['X-Intercepted-To'].to_s).
      to eq "[<EMAIL>, <EMAIL>]"
    expect(response.header['X-Intercepted-Cc'].to_s).
      to eq '<EMAIL>'
    expect(response.header['X-Intercepted-Bcc'].to_s).
      to eq '<EMAIL>'
  end

  it 'accepts an array of recipients' do
    Mail.register_interceptor RecipientInterceptor.new(recipient_array)

    response = deliver_mail

    expect(response.to).to eq recipient_array
  end

  def deliver_mail
    Mail.defaults do
      delivery_method :test
    end

    mail = Mail.deliver do
      from '<EMAIL>'
      to '<EMAIL>'
      cc '<EMAIL>'
      bcc '<EMAIL>'
    end

    mail.deliver!
  end

  def recipient_array
    ['<EMAIL>', '<EMAIL>']
  end
end<commit_msg>Fix specs for Ruby 2.0<commit_after>require File.join(File.dirname(__FILE__), '..', 'lib', 'recipient_interceptor')

describe RecipientInterceptor do
  it 'overrides to/cc/bcc fields, copies original fields to custom headers' do
    Mail.register_interceptor RecipientInterceptor.new(recipient_string)

    response = deliver_mail

    expect(response.to).to eq [recipient_string]
    expect(response.cc).to eq []
    expect(response.bcc).to eq []

    expect(custom_header(response, 'X-Intercepted-To')).
      to eq ['<EMAIL>', '<EMAIL>']
    expect(custom_header(response, 'X-Intercepted-Cc')).
      to eq '<EMAIL>'
    expect(custom_header(response, 'X-Intercepted-Bcc')).
      to eq '<EMAIL>'
  end

  it 'accepts an array of recipients' do
    Mail.register_interceptor RecipientInterceptor.new(recipient_array)

    response = deliver_mail

    expect(response.to).to eq recipient_array
  end

  def deliver_mail
    Mail.defaults do
      delivery_method :test
    end

    mail = Mail.deliver do
      from '<EMAIL>'
      to '<EMAIL>'
      cc '<EMAIL>'
      bcc '<EMAIL>'
    end

    mail.deliver!
  end

  def recipient_string
    '<EMAIL>'
  end

  def recipient_array
    ['<EMAIL>', '<EMAIL>']
  end

  def custom_header(response, name)
    header = response.header[name]

    if header.respond_to?(:map)
      header.map {|header| header.value.wrapped_string }
    else
      header.to_s
    end
  end
end
{'fraction_non_alphanumeric': 0.12300506033476061, 'fraction_numerical': 0.0007785130400934215, 'mean_word_length': 3.2131147540983607, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '6796045', 'n_tokens_mistral': 877, 'n_tokens_neox': 851, 'n_words': 194}