Sha256: 2c45e9048f37c6c1ab89a13757ce51260ec4d2e955655f247fcabe9616ca51b0

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

require File.expand_path("../spec_helper", File.dirname(__FILE__))

require "bcdatabase/commands"

describe "CLI: bcdatabase" do
  before(:each) do
    ENV["BCDATABASE_PATH"] = "/tmp/bcdb_specs"
    FileUtils.mkdir_p ENV["BCDATABASE_PATH"]
  end

  after(:each) do
    FileUtils.rm_rf ENV["BCDATABASE_PATH"]
    ENV["BCDATABASE_PATH"] = nil
  end

  describe "encrypt" do
    before do
      enable_fake_cipherment
    end

    after do
      disable_fake_cipherment
    end

    def bcdatabase_encrypt(infile)
      StringIO.open("", "w") do |io|
        $stdout = io
        Bcdatabase::Commands::Encrypt.new([File.join(ENV["BCDATABASE_PATH"], infile)]).main
        $stdout = STDOUT
        YAML::load(io.string)
      end
    end

    it "replaces password: clauses with epasswords" do
      temporary_yaml "plain", {
        "single" =>  {
          "password" => 'zanzibar'
        }
      }

      bcdatabase_encrypt('plain.yaml')['single']['epassword'].should == 'rabiznaz'
      bcdatabase_encrypt('plain.yaml')['single']['password'].should be_nil
    end

    it "leaves existing epasswords alone" do
      temporary_yaml "plain", {
        "single" =>  {
          "epassword" => 'etalocohc'
        }
      }

      bcdatabase_encrypt('plain.yaml')['single']['epassword'].should == 'etalocohc'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bcdatabase-1.0.2 spec/bcdatabase/commands_spec.rb
bcdatabase-1.0.1 spec/bcdatabase/commands_spec.rb
bcdatabase-1.0.0 spec/bcdatabase/commands_spec.rb