<commit_before>require_relative '../spec_helper'

describe "The $SAFE variable" do
  
  ruby_version_is "2.6" do
    after :each do
      $SAFE = 0
    end
  end
  
  it "is 0 by default" do
    $SAFE.should == 0
    proc {
      $SAFE.should == 0
    }.call
  end
  
  it "can be set to 0" do
    proc {
      $SAFE = 0
      $SAFE.should == 0
    }.call
  end
  
  it "can be set to 1" do
    proc {
      $SAFE = 1
      $SAFE.should == 1
    }.call
  end
  
  [2, 3, 4].each do |n|
    it "cannot be set to #{n}" do
      lambda {
        proc {
          $SAFE = n
        }.call
      }.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
    end
  end
  
  it "cannot be set to values above 4" do
      lambda {
        proc {
          $SAFE = 100
        }.call
      }.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
  end
  
  ruby_version_is ""..."2.6" do
    it "cannot be manually lowered" do
      proc {
        $SAFE = 1
        lambda {
          $SAFE = 0
        }.should raise_error(SecurityError, /tried to downgrade safe level from 1 to 0/)<commit_msg>Spec and fix setting $SAFE to a negative value<commit_after>require_relative '../spec_helper'

describe "The $SAFE variable" do
  
  ruby_version_is "2.6" do
    after :each do
      $SAFE = 0
    end
  end
  
  it "is 0 by default" do
    $SAFE.should == 0
    proc {
      $SAFE.should == 0
    }.call
  end
  
  it "can be set to 0" do
    proc {
      $SAFE = 0
      $SAFE.should == 0
    }.call
  end
  
  it "can be set to 1" do
    proc {
      $SAFE = 1
      $SAFE.should == 1
    }.call
  end
  
  [2, 3, 4].each do |n|
    it "cannot be set to #{n}" do
      lambda {
        proc {
          $SAFE = n
        }.call
      }.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
    end
  end
  
  it "cannot be set to values below 0" do
      lambda {
        proc {
          $SAFE = -100
        }.call
      }.should raise_error(SecurityError, /tried to downgrade safe level from 0 to -100/)
  end
  
  it "cannot be set to values above 4" do
      lambda {
        proc {
          $SAFE = 100
        }.call
      }.should raise_error(ArgumentError, /\$SAFE=2 to 4 are obsolete/)
  end
  
  ruby_version_is ""..."2.6" do
    it "cannot be manually lowered" do
      proc {
        $SAFE = 1
        lambda {
          $SAFE = 0
        }.should raise_error(SecurityError, /tried to downgrade safe level from 1 to 0/)
{'fraction_non_alphanumeric': 0.10620915032679738, 'fraction_numerical': 0.02696078431372549, 'mean_word_length': 1.5915343915343916, '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': '4187857', 'n_tokens_mistral': 939, 'n_tokens_neox': 849, 'n_words': 304}