<commit_before>require 'rexml/document'

REPORTS_DIR = File.dirname(__FILE__) + '/reports'

describe "MiniTest::Unit acceptance" do
  it "should generate two XML files" do
    File.exist?(File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestOne.xml')).should == true
    File.exist?(File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestTwo.xml')).should == true
  end

  it "should have one error and one failure for MiniTestExampleTestOne" do
    doc = File.open(File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestOne.xml')) do |f|
      REXML::Document.new(f)
    end
    doc.root.attributes["errors"].should == "1"
    doc.root.attributes["failures"].should == "1"
    doc.root.attributes["assertions"].should == "1"
    doc.root.attributes["tests"].should == "1"
    doc.root.elements.to_a("/testsuite/testcase").size.should == 1
    doc.root.elements.to_a("/testsuite/testcase/error").size.should == 1
    doc.root.elements.to_a("/testsuite/testcase/failure").size.should == 1
    doc.root.elements.to_a("/testsuite/system-out").first.texts.inject("") do |c,e|
      c << e.value; c
    end.strip.should == "Some <![CDATA[on stdout]]>"
  end

  it "should have no errors or failures for MiniTestExampleTestTwo" do
    doc = File.open(File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestTwo.xml')) do |f|
      REXML::Document.new(f)
    end
    doc.root.attributes["errors"].should == "0"
    doc.root.attributes["failures"].should == "0"
    doc.root.attributes["assertions"].should == "1"
    doc.root.attributes["tests"].should == "1"
    doc.root.elements.to_a("/testsuite/testcase").size.should == 1
    doc.root.elements.to_a("/testsuite/testcase/failure").size.should == 0<commit_msg>Split big acceptance tests into multiple tests<commit_after>require 'rexml/document'

REPORTS_DIR = File.dirname(__FILE__) + '/reports'

describe "MiniTest::Unit acceptance" do
  let(:report_path_1) {File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestOne.xml')}
  let(:report_path_2) {File.join(REPORTS_DIR, 'TEST-MiniTestExampleTestTwo.xml')}

  context "generated files" do
    it "generates two XML files" do
      pending "A rogue file is created"
      expect(Dir["#{REPORTS_DIR}/*.xml"].count).to eql 2
    end

    it "generates XML for the first test" do
      expect(File.exist?(report_path_1)).to be true
    end

    it "generates XML for the second test" do
      expect(File.exist?(report_path_2)).to be true
    end
  end

  context "a test with a failure and an error" do
    let (:root) { load_xml_result(report_path_1).root }

    it "has one error" do
      expect(root.attributes["errors"]).to eql "1"
    end

    it "has one failure" do
      expect(root.attributes["failures"]).to eql "1"
    end

    it "has one assertion" do
      expect(root.attributes["assertions"]).to eql "1"
    end

    it "has one test" do
      expect(root.attributes["tests"]).to eql "1"
    end

    it "has one testcase" do
      expect(root.elements.to_a("/testsuite/testcase").size).to eql 1
    end

    context "the testcase" do
      it "has an error" do
        expect(root.elements.to_a("/testsuite/testcase/error").size).to eql 1
      end

      it "has a failure" do
        expect(root.elements.to_a("/testsuite/testcase/failure").size).to eql 1
      end
    end

    it "captures the STDOUT" do
      content = root.elements.to_a("/testsuite/system-out").first.texts.inject("") do |c,e|
        c << e.value; c
      end.strip

      expect(content).to eql "Some <![CDATA[on stdout]]>"
    end
  end

  context "a test without failures" do
    let(:root) { load_xml_result(report_path_2).root }

    it "has zero errors" do
      expect(root.attributes["errors"]).to eql "0"
    end

    it "has zero failures" do
      expect(root.attributes["failures"]).to eql "0"
    end

    it "has one assertion" do
      expect(root.attributes["assertions"]).to eql "1"
    end

    it "has one test" do
      expect(root.attributes["tests"]).to eql "1"
    end

    it "has one testcase" do
      expect(root.elements.to_a("/testsuite/testcase").size).to eql 1
    end

    context "the testcase" do
      it "has no failures" do
        expect(root.elements.to_a("/testsuite/testcase/failure").size).to eql 0
      end
    end
  end

  def load_xml_result(path)
    File.open(path) do |f|
      REXML::Document.new(f)
    end
{'fraction_non_alphanumeric': 0.1417633410672854, 'fraction_numerical': 0.00765661252900232, 'mean_word_length': 3.226470588235294, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '1054779', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1452, 'n_words': 336}