Sha256: 2181dc85f61e8a154b7ebadc44141611e451c40cad7f14b697e5b463643a2074

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require "aruba/rspec"

require_relative "backup_directory"

Aruba.configure do |config|
  config.home_directory = File.expand_path("./tmp/home")
  config.allow_absolute_paths = true
end

module ConfigurationHelpers
  def config_path
    File.expand_path("~/.imap-backup")
  end

  def create_config(accounts:, debug: false)
    pathname = File.join(config_path, "config.json")
    save_data = {
      version: Imap::Backup::Configuration::VERSION,
      accounts: accounts,
      debug: debug
    }
    FileUtils.mkdir_p config_path
    File.open(pathname, "w") { |f| f.write(JSON.pretty_generate(save_data)) }
    FileUtils.chmod(0o600, pathname)
  end
end

module StoreHelpers
  def store_email(
    email:, folder:,
    uid: 1,
    from: "sender@example.com",
    subject: "The Subject",
    body: "body"
  )
    account = config.accounts.find { |a| a.username == email }
    raise "Account not found" if !account
    FileUtils.mkdir_p account.local_path
    store = Imap::Backup::Serializer::MboxStore.new(account.local_path, folder)
    store.uid_validity = "42" if !store.uid_validity
    serialized = to_serialized(from: from, subject: subject, body: body)
    store.add(uid, serialized)
  end

  def to_serialized(from:, subject:, body:)
    body_and_headers = <<~BODY
      From: #{from}
      Subject: #{subject}

      #{body}
    BODY
  end

  def config
    Imap::Backup::Configuration.new(
      File.expand_path("~/.imap-backup/config.json")
    )
  end
end

RSpec.configure do |config|
  config.include ConfigurationHelpers, type: :aruba
  config.include StoreHelpers, type: :aruba
  config.include BackupDirectoryHelpers, type: :aruba

  config.before(:suite) do
    FileUtils.rm_rf "./tmp/home"
  end

  config.after do
    FileUtils.rm_rf "./tmp/home"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imap-backup-5.1.0 spec/features/support/aruba.rb