<commit_before>require 'grit'
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/fakefs_helper')
require 'hastie/report_publisher'

describe Hastie::ReportPublisher do

  def read_file file
    if File.exists? file
      File.open(file, 'r').read
    else
      ""
    end
  end

  before :each do
    @config_file = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "hastie_config"))
    @org_server_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "server"))
    @org_report_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "report"))

    @sandbox = File.expand_path(File.join(File.dirname(__FILE__), "sandbox"))

    @server_dir = File.join(@sandbox, "server")
    @report_dir = File.join(@sandbox, "report")

    FileUtils.mkdir_p @sandbox

    FileUtils.cp_r @org_server_dir, @server_dir
    FileUtils.cp_r @org_report_dir, @report_dir

    @report_name = File.basename(Dir.glob(File.join(@report_dir, "*.textile"))[0])

    Grit::Repo.init(@server_dir)

    @input = [@report_dir, "--config_file", @config_file, "--server_root", @server_dir]
  end

  after :each do
    FileUtils.rm_r @sandbox if File.exists?(@sandbox)
  end

  it "should copy new report into reports_dir" do
    content = capture(:stdout) do
      lambda { Hastie::ReportPublisher.start @input }.should_not raise_error SystemExit
    end

    File.exists?(File.join(@server_dir, "_posts", @report_name)).should == true
    File.exists?(File.join(@server_dir, "data", "report")).should == true
  end

  it "should add report to _reports.yml" do
  end
<commit_msg>spec for adding to _reports.yml<commit_after>require 'grit'
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/fakefs_helper')
require 'hastie/report_publisher'

describe Hastie::ReportPublisher do

  def read_file file
    if File.exists? file
      File.open(file, 'r').read
    else
      ""
    end
  end

  before :each do
    @config_file = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "hastie_config"))
    @org_server_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "server"))
    @org_report_dir = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "report"))

    @sandbox = File.expand_path(File.join(File.dirname(__FILE__), "sandbox"))

    @server_dir = File.join(@sandbox, "server")
    @report_dir = File.join(@sandbox, "report")

    FileUtils.mkdir_p @sandbox

    FileUtils.cp_r @org_server_dir, @server_dir
    FileUtils.cp_r @org_report_dir, @report_dir

    @report_name = File.basename(Dir.glob(File.join(@report_dir, "*.textile"))[0])

    Grit::Repo.init(@server_dir)

    @input = [@report_dir, "--config_file", @config_file, "--server_root", @server_dir]
  end

  after :each do
    FileUtils.rm_r @sandbox if File.exists?(@sandbox)
  end

  it "should copy new report into reports_dir" do
    content = capture(:stdout) do
      lambda { Hastie::ReportPublisher.start @input }.should_not raise_error SystemExit
    end

    File.exists?(File.join(@server_dir, "_posts", @report_name)).should == true
    File.exists?(File.join(@server_dir, "data", "report")).should == true
  end

  it "should add report to _reports.yml" do
    content = capture(:stdout) do
      lambda { Hastie::ReportPublisher.start @input }.should_not raise_error SystemExit
    end
    reports_content = read_file(File.join(@server_dir, "_reports.yml"))
    reports_content.should match /#{File.basename(@report_dir)}/
  end

{'fraction_non_alphanumeric': 0.14023882254929187, 'fraction_numerical': 0.0005554012774229381, 'mean_word_length': 4.432880844645551, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1051993', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1211, 'n_words': 240}