<commit_before>require File.expand_path('../../../spec_helper', __FILE__)

module Bcdatabase::Commands
  describe Encrypt do
    let(:pprod_path) { File.join(ENV['BCDATABASE_PATH'], 'pprod.yaml') }

    before do
      enable_fake_cipherment
      ENV['BCDATABASE_PATH'] = (tmpdir + 'base').tap { |d| d.mkpath }.to_s

      temporary_yaml 'pprod', {
        'wh' => {
          'password' => '<PASSWORD>'
        },
        'app' => {
          'epassword' => '<PASSWORD>'
        }
      }
    end

    after do
      ENV['BCDATABASE_PATH'] = nil
      disable_fake_cipherment
    end

    def run_with(inputfile, outputfile=nil)
      capture_std do
        Encrypt.new(inputfile, outputfile).run
      end
    end

    def run_with_input(*lines)
      replace_stdin(*lines) do
        capture_std do
          Encrypt.new.run
        end
      end
    end

    shared_examples 'general behavior' do
      let(:yaml_output) { YAML.load(output) }

      it 'reads from the appropriate input' do
        output.should =~ /wh:/
      end

      it 'encrypts the password' do
        yaml_output['wh']['epassword'].should == '<PASSWORD>'
      end

      it 'removes the unencrypted password' do
        yaml_output['wh'].should_not have_key('password')
      end

      it 'leaves any existing epasswords alone' do
        yaml_output['app']['epassword'].should == '<PASSWORD>'
      end
    end

    describe 'with zero arguments' do
      subject { run_with_input('wh:', '  password: <PASSWORD>', 'app:', '  epassword: <PASSWORD>') }

      let(:output) { subject[:out] }

      include_examples 'general behavior'
    end

    describe 'with one argument' do
      subject { run_with(pprod_path) }

      let(:output) { subject[:out] }

      include_examples 'general behavior'
    end

    describe 'with two arguments' do
      subject { run_with(pprod_path, out_path) }

      let(:out_path) { tmpdir + 'encrypted.yml' }
      let(:output) { subject; File.read(out_path) }

      include_examples 'general behavior'
    end
  end
end<commit_msg>Add spec for untested but documented behavior -- both input and output the same -- in bcdatabase encrypt.<commit_after>require File.expand_path('../../../spec_helper', __FILE__)

module Bcdatabase::Commands
  describe Encrypt do
    let(:pprod_path) { File.join(ENV['BCDATABASE_PATH'], 'pprod.yaml') }

    before do
      enable_fake_cipherment
      ENV['BCDATABASE_PATH'] = (tmpdir + 'base').tap { |d| d.mkpath }.to_s

      temporary_yaml 'pprod', {
        'wh' => {
          'password' => '<PASSWORD>'
        },
        'app' => {
          'epassword' => '<PASSWORD>'
        }
      }
    end

    after do
      ENV['BCDATABASE_PATH'] = nil
      disable_fake_cipherment
    end

    def run_with(inputfile, outputfile=nil)
      capture_std do
        Encrypt.new(inputfile, outputfile).run
      end
    end

    def run_with_input(*lines)
      replace_stdin(*lines) do
        capture_std do
          Encrypt.new.run
        end
      end
    end

    shared_examples 'general behavior' do
      let(:yaml_output) { YAML.load(output) }

      it 'reads from the appropriate input' do
        output.should =~ /wh:/
      end

      it 'encrypts the password' do
        yaml_output['wh']['epassword'].should == '<PASSWORD>'
      end

      it 'removes the unencrypted password' do
        yaml_output['wh'].should_not have_key('password')
      end

      it 'leaves any existing epasswords alone' do
        yaml_output['app']['epassword'].should == '<PASSWORD>'
      end
    end

    describe 'with zero arguments' do
      subject { run_with_input('wh:', '  password: <PASSWORD>', 'app:', '  epassword: <PASSWORD>') }

      let(:output) { subject[:out] }

      include_examples 'general behavior'
    end

    describe 'with one argument' do
      subject { run_with(pprod_path) }

      let(:output) { subject[:out] }

      include_examples 'general behavior'
    end

    describe 'with two arguments' do
      subject { run_with(pprod_path, out_path) }

      let(:out_path) { tmpdir + 'encrypted.yml' }
      let(:output) { subject; File.read(out_path) }

      include_examples 'general behavior'

      context 'that are both the same file' do
        let(:out_path) { pprod_path }

        include_examples 'general behavior'
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11856978085351788, 'fraction_numerical': 0.0, 'mean_word_length': 2.416863672182821, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '7646673', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1345, 'n_words': 326}