<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2011 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'pry'

shared_context "deploying with move" do
  before do
    Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
    Chef::Config[:file_atomic_update] = true
  end
end

shared_context "deploying with copy" do
  before do
    Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
    Chef::Config[:file_atomic_update] = false
  end
end

shared_context "deploying via tmpdir" do
  before do
    Chef::Config[:file_staging_uses_destdir] = false
    Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
  end
end

shared_context "deploying via destdir" do
  before do
    Chef::Config[:file_staging_uses_destdir] = true
    Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
  end
end


shared_examples_for "a file with the wrong content" do
  before do
    # Assert starting state is as expected
    File.should exist(path)
    # Kinda weird, in this case @expected_checksum is the cksum of the file
    # with incorrect content.
    sha256_checksum(path).should == @expected_checksum
  end

  describe "when diff is disabled" do

    include_context "diff disabled"

    context "when running action :create" do
      context "with backups enabled" do
        before do
          resource.run_action(:create)
        end

        it "overwrites the file with the updated content when the :create action is run" do
          File.stat(path).mtime.should > @expected_mtime
          sha256_checksum(path).should_not == @expected_checksum
        end

        it "backs up the existing file" do
          Dir.glob(backup_glob).size.should equal(1)
        end

        it "is marked as updated by last action" do
          resource.should be_updated_by_last_action
        end

        it "should restore the security contexts on selinux", :selinux_only do
          selinux_security_context_restored?(path).should be_true
        end
      end

      context "with backups disabled" do
        before do
          resource.backup(0)
          resource.run_action(:create)
        end

        it "should not attempt to backup the existing file if :backup == 0" do
          Dir.glob(backup_glob).size.should equal(0)
        end

        it "should restore the security contexts on selinux", :selinux_only do
          selinux_security_context_restored?(path).should be_true
        end
      end
    end

    describe "when running action :create_if_missing" do
      before do
        resource.run_action(:create_if_missing)
      end

      it "doesn't overwrite the file when the :create_if_missing action is run" do
        File.stat(path).mtime.should == @expected_mtime
        sha256_checksum(path).should == @expected_checksum
      end

      it "is not marked as updated" do
        resource.should_not be_updated_by_last_action
      end

      it "should restore the security contexts on selinux", :selinux_only do
        selinux_security_context_restored?(path).should be_true
      end
    end

    describe "when running action :delete" do
      before do
        resource.run_action(:delete)
      end

      it "deletes the file" do
        File.should_not exist(path)
      end

      it "is marked as updated by last action" do
        resource.should be_updated_by_last_action
      end
    end

  end

  context "`.diff`'s enabled" do
    describe '.sensitive' do
      context "`.sensitive`'s insensitive by default" do
        it { expect(resource.sensitive).to(be_false) }
      end

      context "`.sensitive`'s sensitive" do
        before { resource.sensitive(true) }

        it { expect(resource.sensitive).to(be_true) }

        context '`.sensitive` suppresses a sensitive resource' do
          subject(:provider) { resource.provider_for_action(:create) }

          before { provider.run_action }

          it { expect(resource.diff).to(include('suppressed sensitive resource')) }

          it { expect(provider.instance_variable_get("@converge_actions")
                              .actions[0][0]).to(eq(['suppressed sensitive resource'])) }
        end
      end
    end
  end
end

shared_examples_for "a file with the correct content" do
  before do
    # Assert starting state is as expected
    File.should exist(path)
    sha256_checksum(path).should == @expected_checksum
  end

  include_context "diff disabled"

  describe "when running action :create" do
    before do
      resource.run_action(:create)
    end
    it "does not overwrite the original when the :create action is run" do
      sha256_checksum(path).should == @expected_checksum
    end
<commit_msg>fixed 1.8.7 incompatability issue; removed `pry` import<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2011 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

shared_context "deploying with move" do
  before do
    Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
    Chef::Config[:file_atomic_update] = true
  end
end

shared_context "deploying with copy" do
  before do
    Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
    Chef::Config[:file_atomic_update] = false
  end
end

shared_context "deploying via tmpdir" do
  before do
    Chef::Config[:file_staging_uses_destdir] = false
    Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
  end
end

shared_context "deploying via destdir" do
  before do
    Chef::Config[:file_staging_uses_destdir] = true
    Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
  end
end


shared_examples_for "a file with the wrong content" do
  before do
    # Assert starting state is as expected
    File.should exist(path)
    # Kinda weird, in this case @expected_checksum is the cksum of the file
    # with incorrect content.
    sha256_checksum(path).should == @expected_checksum
  end

  describe "when diff is disabled" do

    include_context "diff disabled"

    context "when running action :create" do
      context "with backups enabled" do
        before do
          resource.run_action(:create)
        end

        it "overwrites the file with the updated content when the :create action is run" do
          File.stat(path).mtime.should > @expected_mtime
          sha256_checksum(path).should_not == @expected_checksum
        end

        it "backs up the existing file" do
          Dir.glob(backup_glob).size.should equal(1)
        end

        it "is marked as updated by last action" do
          resource.should be_updated_by_last_action
        end

        it "should restore the security contexts on selinux", :selinux_only do
          selinux_security_context_restored?(path).should be_true
        end
      end

      context "with backups disabled" do
        before do
          resource.backup(0)
          resource.run_action(:create)
        end

        it "should not attempt to backup the existing file if :backup == 0" do
          Dir.glob(backup_glob).size.should equal(0)
        end

        it "should restore the security contexts on selinux", :selinux_only do
          selinux_security_context_restored?(path).should be_true
        end
      end
    end

    describe "when running action :create_if_missing" do
      before do
        resource.run_action(:create_if_missing)
      end

      it "doesn't overwrite the file when the :create_if_missing action is run" do
        File.stat(path).mtime.should == @expected_mtime
        sha256_checksum(path).should == @expected_checksum
      end

      it "is not marked as updated" do
        resource.should_not be_updated_by_last_action
      end

      it "should restore the security contexts on selinux", :selinux_only do
        selinux_security_context_restored?(path).should be_true
      end
    end

    describe "when running action :delete" do
      before do
        resource.run_action(:delete)
      end

      it "deletes the file" do
        File.should_not exist(path)
      end

      it "is marked as updated by last action" do
        resource.should be_updated_by_last_action
      end
    end

  end

  context "`.diff`'s enabled" do
    describe '.sensitive' do
      context "`.sensitive`'s insensitive by default" do
        it { expect(resource.sensitive).to(be_false) }
      end

      context "`.sensitive`'s sensitive" do
        before { resource.sensitive(true) }

        it { expect(resource.sensitive).to(be_true) }

        context '`.sensitive` suppresses a sensitive resource' do
          subject(:provider) { resource.provider_for_action(:create) }

          before { provider.run_action }

          it { expect(resource.diff).to(include('suppressed sensitive resource')) }

          it { expect(provider.instance_variable_get("@converge_actions").actions[0][0]).to(eq(['suppressed sensitive resource'])) }
        end
      end
    end
  end
end

shared_examples_for "a file with the correct content" do
  before do
    # Assert starting state is as expected
    File.should exist(path)
    sha256_checksum(path).should == @expected_checksum
  end

  include_context "diff disabled"

  describe "when running action :create" do
    before do
      resource.run_action(:create)
    end
    it "does not overwrite the original when the :create action is run" do
      sha256_checksum(path).should == @expected_checksum
    end

{'fraction_non_alphanumeric': 0.07564717162032598, 'fraction_numerical': 0.006232023010546501, 'mean_word_length': 2.9377123442808606, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1683643', 'n_tokens_mistral': 3107, 'n_tokens_neox': 2941, 'n_words': 975}