<commit_before>require "spec_helper"

describe LetterOpener::DeliveryMethod do
  before(:each) do
    Launchy.stub(:open)
    location = File.expand_path('../../../tmp/letter_opener', __FILE__)
    FileUtils.rm_rf(location)
    Mail.defaults do
      delivery_method LetterOpener::DeliveryMethod, :location => location
    end
    @location = location
  end

  it "saves text into html document" do
    Launchy.should_receive(:open)
    mail = Mail.deliver do
      from     'Foo <EMAIL>'
      reply_to 'No Reply <EMAIL>'
      to       '<EMAIL>'
      subject  'Hello'
      body     'World!'
    end
    text = File.read(Dir["#{@location}/*/plain.html"].first)
    text.should include("Foo <EMAIL>")
    text.should include("No Reply <EMAIL>")
    text.should include("<EMAIL>")
    text.should include("Hello")
    text.should include("World!")
  end

  it "saves multipart email into html document" do
    mail = Mail.deliver do
      from    '<EMAIL>'
      to      '<EMAIL>'
      subject 'Many parts'
      text_part do
        body 'This is <plain> text'
      end
      html_part do
        content_type 'text/html; charset=UTF-8'
        body '<h1>This is HTML</h1>'
      end
    end
    text = File.read(Dir["#{@location}/*/plain.html"].first)
    text.should include("View HTML version")
    text.should include("This is &lt;plain&gt; text")
    html = File.read(Dir["#{@location}/*/rich.html"].first)
    html.should include("View plain text version")
    html.should include("<h1>This is HTML</h1>")
  end


  it "saves text into html document when deliver! is called" do
    Launchy.should_receive(:open)
    mail = Mail.new do
      from    '<EMAIL>'
      to      '<EMAIL>'
      subject 'Hello'
      body    'World!'
    end

    mail.deliver!

    text = File.read(Dir["#{@location}/*/plain.html"].first)
    text.should include("<EMAIL>")
    text.should include("<EMAIL>")
    text.should include("Hello")
    text.should include("World!")
  end
end
<commit_msg>don't use instance variable in specs<commit_after>require "spec_helper"

describe LetterOpener::DeliveryMethod do
  let(:location) { File.expand_path('../../../tmp/letter_opener', __FILE__) }

  before do
    Launchy.stub(:open)
    FileUtils.rm_rf(location)
    context = self

    Mail.defaults do
      delivery_method LetterOpener::DeliveryMethod, :location => context.location
    end
  end

  it "saves text into html document" do
    Launchy.should_receive(:open)
    mail = Mail.deliver do
      from     'Foo <EMAIL>'
      reply_to 'No Reply <EMAIL>'
      to       '<EMAIL>'
      subject  'Hello'
      body     'World!'
    end
    text = File.read(Dir["#{location}/*/plain.html"].first)
    text.should include("Foo <EMAIL>")
    text.should include("No Reply <EMAIL>")
    text.should include("<EMAIL>")
    text.should include("Hello")
    text.should include("World!")
  end

  it "saves multipart email into html document" do
    mail = Mail.deliver do
      from    '<EMAIL>'
      to      '<EMAIL>'
      subject 'Many parts'
      text_part do
        body 'This is <plain> text'
      end
      html_part do
        content_type 'text/html; charset=UTF-8'
        body '<h1>This is HTML</h1>'
      end
    end
    text = File.read(Dir["#{location}/*/plain.html"].first)
    text.should include("View HTML version")
    text.should include("This is &lt;plain&gt; text")
    html = File.read(Dir["#{location}/*/rich.html"].first)
    html.should include("View plain text version")
    html.should include("<h1>This is HTML</h1>")
  end


  it "saves text into html document when deliver! is called" do
    Launchy.should_receive(:open)
    mail = Mail.new do
      from    '<EMAIL>'
      to      '<EMAIL>'
      subject 'Hello'
      body    'World!'
    end

    mail.deliver!

    text = File.read(Dir["#{location}/*/plain.html"].first)
    text.should include("<EMAIL>")
    text.should include("<EMAIL>")
    text.should include("Hello")
    text.should include("World!")
  end
end

{'fraction_non_alphanumeric': 0.13820731096644967, 'fraction_numerical': 0.0025037556334501754, 'mean_word_length': 2.6854243542435423, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, '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': '358275', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1282, 'n_words': 325}