<commit_before>require "spec_helper"

describe "Setup" do
  before {
    @old_config = Invoker::Power::Config::CONFIG_LOCATION
    Invoker::Power::Config.const_set(:CONFIG_LOCATION, "/tmp/.invoker")

    File.exists?(Invoker::Power::Config::CONFIG_LOCATION) &&
      File.delete(Invoker::Power::Config::CONFIG_LOCATION)

    @old_resolver = Invoker::Power::Setup::RESOLVER_FILE
    Invoker::Power::Setup.const_set(:RESOLVER_FILE, "/tmp/invoker-dev")

    File.exists?(Invoker::Power::Setup::RESOLVER_FILE) &&
      File.delete(Invoker::Power::Setup::RESOLVER_FILE)
  }

  after {
    File.exists?(Invoker::Power::Config::CONFIG_LOCATION) &&
      File.delete(Invoker::Power::Config::CONFIG_LOCATION)

    Invoker::Power::Config.const_set(:CONFIG_LOCATION, @old_config)

    File.exists?(Invoker::Power::Setup::RESOLVER_FILE) &&
      File.delete(Invoker::Power::Setup::RESOLVER_FILE)
    Invoker::Power::Setup.const_set(:RESOLVER_FILE, @old_resolver)
  }

  describe "When no setup exists" do
    it "should create a config file with port etc" do
      setup = Invoker::Power::Setup.new()
      setup.expects(:install_resolver).returns(true)
      setup.expects(:flush_dns_rules).returns(true)
      setup.expects(:drop_to_normal_user).returns(true)
      setup.expects(:install_firewall).once()

      setup.setup_invoker
<commit_msg>Fix constant warnings in test suite<commit_after>require "spec_helper"

describe "Setup" do
  before {
    @original_verbosity = $VERBOSE
    $VERBOSE = nil
    @old_config = Invoker::Power::Config::CONFIG_LOCATION
    Invoker::Power::Config.const_set(:CONFIG_LOCATION, "/tmp/.invoker")

    File.exists?(Invoker::Power::Config::CONFIG_LOCATION) &&
      File.delete(Invoker::Power::Config::CONFIG_LOCATION)

    @old_resolver = Invoker::Power::Setup::RESOLVER_FILE
    Invoker::Power::Setup.const_set(:RESOLVER_FILE, "/tmp/invoker-dev")

    File.exists?(Invoker::Power::Setup::RESOLVER_FILE) &&
      File.delete(Invoker::Power::Setup::RESOLVER_FILE)
  }

  after {
    File.exists?(Invoker::Power::Config::CONFIG_LOCATION) &&
      File.delete(Invoker::Power::Config::CONFIG_LOCATION)

    Invoker::Power::Config.const_set(:CONFIG_LOCATION, @old_config)

    File.exists?(Invoker::Power::Setup::RESOLVER_FILE) &&
      File.delete(Invoker::Power::Setup::RESOLVER_FILE)
    Invoker::Power::Setup.const_set(:RESOLVER_FILE, @old_resolver)
    $VERBOSE = @original_verbosity
  }

  describe "When no setup exists" do
    it "should create a config file with port etc" do
      setup = Invoker::Power::Setup.new()
      setup.expects(:install_resolver).returns(true)
      setup.expects(:flush_dns_rules).returns(true)
      setup.expects(:drop_to_normal_user).returns(true)
      setup.expects(:install_firewall).once()

      setup.setup_invoker

{'fraction_non_alphanumeric': 0.14670981661272922, 'fraction_numerical': 0.0, 'mean_word_length': 5.168514412416852, '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': '1534899', 'n_tokens_mistral': 930, 'n_tokens_neox': 919, 'n_words': 111}