require 'db_obfuscation/environment'
require 'db_dump'

module DbObfuscation
  module Cli
    describe DbDump do

      it 'dump a db into a dump file' do
        filename = 'db.yml'
        db_config = {
          'username' => 'fake_username',
          'password' => 'fake_password',
          'database' => 'fake_database',
          'host' => 'fake_host'
        }

        allow(YAML).to receive(:load_file).with(filename).
          and_return(db_config)

        dump_name = 'dumped_database'

        dump_cmd = <<-dump_cmd.gsub(/\s{2,}/,' ').strip
      PGPASSWORD=fake_password pg_dump -h fake_host -U fake_username -w
      -Fc -f dumped_database fake_database
        dump_cmd

        expect(Kernel).to receive(:system).with(dump_cmd)
        described_class.dump(filename, dump_name)
      end
    end

  end
end
