<commit_before>require 'test_helper'

class Seatbelt::AssertMailTest < Minitest::Test

  def test_assert_mail
    Mailer.test.deliver_now

    assert_mail :to => '<EMAIL>'
    assert_mail :cc => '<EMAIL>'
    assert_mail :bcc => '<EMAIL>'
    assert_mail :from => '<EMAIL>'
    assert_mail :subject => 'mail subject'
    assert_mail :subject => /subject/
    assert_mail :body => 'mail body text'
    assert_mail :body => /body text/
    assert_mail :body => ['mail body', 'body text']

    assert_mail :to => '<EMAIL>', :subject => /subject/, :body => 'body'
  end
  def test_assert_mail_crosscheck
    Mailer.test.deliver_now

    assert_assertion_fails { assert_mail :to => '<EMAIL>' }
    assert_assertion_fails { assert_mail :cc => '<EMAIL>' }
    assert_assertion_fails { assert_mail :bcc => '<EMAIL>' }
    assert_assertion_fails { assert_mail :from => '<EMAIL>' }
    assert_assertion_fails { assert_mail :subject => 'unknown' }
    assert_assertion_fails { assert_mail :body => 'unknown' }
    assert_assertion_fails { assert_mail :to => '<EMAIL>', :subject => 'unknown', :body => 'unknown' }
  end

  def test_assert_mail_with_multiple_mails
    Mailer.test.deliver_now
    Mailer.test(:to => '<EMAIL>').deliver_now

    assert_mail :to => '<EMAIL>'
    assert_mail :to => '<EMAIL>'
  end

  def test_assert_mail_with_block
    assert_mail :to => '<EMAIL>', :subject => /subject/, :body => 'body' do
      Mailer.test.deliver_now
    end
  end
  def test_assert_mail_with_block_crosscheck
    assert_assertion_fails do
      assert_mail :to => '<EMAIL>' do
        Mailer.test.deliver_now
      end
    end
  end

  def test_assert_no_mail
    assert_no_mail do
      # do something
      abc = 1 + 1
    end

    refute_mail { 3 }

    assert_no_mail :to => '<EMAIL>' do
      Mailer.test.deliver_now
    end
    assert_no_mail :subject => 'my other subject' do
      Mailer.test.deliver_now
    end
    assert_no_mail :body => 'my other body text' do
      Mailer.test.deliver_now
    end
  end

  def test_assert_no_mail_crosscheck
    assert_assertion_fails do
      assert_no_mail :to => '<EMAIL>' do
        Mailer.test.deliver_now
      end
    end
  end

end
<commit_msg>make sure tests work with Rails 3<commit_after>require 'test_helper'

class Seatbelt::AssertMailTest < Minitest::Test

  def test_assert_mail
    deliver

    assert_mail :to => '<EMAIL>'
    assert_mail :cc => '<EMAIL>'
    assert_mail :bcc => '<EMAIL>'
    assert_mail :from => '<EMAIL>'
    assert_mail :subject => 'mail subject'
    assert_mail :subject => /subject/
    assert_mail :body => 'mail body text'
    assert_mail :body => /body text/
    assert_mail :body => ['mail body', 'body text']

    assert_mail :to => '<EMAIL>', :subject => /subject/, :body => 'body'
  end
  def test_assert_mail_crosscheck
    deliver

    assert_assertion_fails { assert_mail :to => '<EMAIL>' }
    assert_assertion_fails { assert_mail :cc => '<EMAIL>' }
    assert_assertion_fails { assert_mail :bcc => '<EMAIL>' }
    assert_assertion_fails { assert_mail :from => '<EMAIL>' }
    assert_assertion_fails { assert_mail :subject => 'unknown' }
    assert_assertion_fails { assert_mail :body => 'unknown' }
    assert_assertion_fails { assert_mail :to => '<EMAIL>', :subject => 'unknown', :body => 'unknown' }
  end

  def test_assert_mail_with_multiple_mails
    deliver
    Mailer.test(:to => '<EMAIL>').deliver_now

    assert_mail :to => '<EMAIL>'
    assert_mail :to => '<EMAIL>'
  end

  def test_assert_mail_with_block
    assert_mail :to => '<EMAIL>', :subject => /subject/, :body => 'body' do
      deliver
    end
  end
  def test_assert_mail_with_block_crosscheck
    assert_assertion_fails do
      assert_mail :to => '<EMAIL>' do
        deliver
      end
    end
  end

  def test_assert_no_mail
    assert_no_mail do
      # do something
      abc = 1 + 1
    end

    refute_mail { 3 }

    assert_no_mail :to => '<EMAIL>' do
      deliver
    end
    assert_no_mail :subject => 'my other subject' do
      deliver
    end
    assert_no_mail :body => 'my other body text' do
      deliver
    end
  end

  def test_assert_no_mail_crosscheck
    assert_assertion_fails do
      assert_no_mail :to => '<EMAIL>' do
        deliver
      end
    end
  end

  private

  def deliver
    ActionMailer::VERSION::MAJOR > 3 ? Mailer.test.deliver_now : Mailer.test.deliver
  end

end

{'fraction_non_alphanumeric': 0.11553420269961108, 'fraction_numerical': 0.0018302447952413636, 'mean_word_length': 3.1323251417769375, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 102, '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': '7286869', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1492, 'n_words': 358}