imap-backup 4.0.4 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/bin/imap-backup +5 -2
  3. data/lib/email/provider/apple_mail.rb +2 -2
  4. data/lib/email/provider/base.rb +8 -0
  5. data/lib/email/provider/fastmail.rb +2 -2
  6. data/lib/email/provider/gmail.rb +2 -2
  7. data/lib/email/provider/{default.rb → unknown.rb} +2 -3
  8. data/lib/email/provider.rb +2 -2
  9. data/lib/imap/backup/account/connection.rb +70 -58
  10. data/lib/imap/backup/account/folder.rb +23 -3
  11. data/lib/imap/backup/account.rb +102 -0
  12. data/lib/imap/backup/cli/accounts.rb +43 -0
  13. data/lib/imap/backup/cli/folders.rb +3 -1
  14. data/lib/imap/backup/cli/helpers.rb +8 -9
  15. data/lib/imap/backup/cli/local.rb +4 -2
  16. data/lib/imap/backup/cli/setup.rb +1 -1
  17. data/lib/imap/backup/cli/utils.rb +3 -2
  18. data/lib/imap/backup/{configuration/store.rb → configuration.rb} +49 -14
  19. data/lib/imap/backup/downloader.rb +26 -12
  20. data/lib/imap/backup/logger.rb +42 -0
  21. data/lib/imap/backup/sanitizer.rb +42 -0
  22. data/lib/imap/backup/serializer/mbox_store.rb +2 -2
  23. data/lib/imap/backup/setup/account.rb +177 -0
  24. data/lib/imap/backup/{configuration → setup}/asker.rb +5 -5
  25. data/lib/imap/backup/setup/connection_tester.rb +26 -0
  26. data/lib/imap/backup/{configuration → setup}/folder_chooser.rb +25 -17
  27. data/lib/imap/backup/setup/helpers.rb +15 -0
  28. data/lib/imap/backup/{configuration/setup.rb → setup.rb} +33 -25
  29. data/lib/imap/backup/uploader.rb +2 -2
  30. data/lib/imap/backup/version.rb +2 -2
  31. data/lib/imap/backup.rb +7 -33
  32. data/lib/retry_on_error.rb +1 -1
  33. data/spec/features/backup_spec.rb +1 -0
  34. data/spec/features/support/email_server.rb +5 -2
  35. data/spec/features/support/shared/connection_context.rb +7 -5
  36. data/spec/support/higline_test_helpers.rb +1 -1
  37. data/spec/support/silence_logging.rb +1 -1
  38. data/spec/unit/email/provider/{default_spec.rb → base_spec.rb} +1 -7
  39. data/spec/unit/email/provider_spec.rb +2 -2
  40. data/spec/unit/imap/backup/account/connection_spec.rb +22 -26
  41. data/spec/unit/imap/backup/cli/accounts_spec.rb +47 -0
  42. data/spec/unit/imap/backup/cli/local_spec.rb +15 -4
  43. data/spec/unit/imap/backup/cli/utils_spec.rb +54 -42
  44. data/spec/unit/imap/backup/{configuration/store_spec.rb → configuration_spec.rb} +23 -24
  45. data/spec/unit/imap/backup/downloader_spec.rb +1 -1
  46. data/spec/unit/imap/backup/logger_spec.rb +48 -0
  47. data/spec/unit/imap/backup/{configuration → setup}/account_spec.rb +78 -70
  48. data/spec/unit/imap/backup/{configuration → setup}/asker_spec.rb +2 -2
  49. data/spec/unit/imap/backup/{configuration → setup}/connection_tester_spec.rb +10 -10
  50. data/spec/unit/imap/backup/{configuration → setup}/folder_chooser_spec.rb +25 -26
  51. data/spec/unit/imap/backup/{configuration/setup_spec.rb → setup_spec.rb} +81 -52
  52. metadata +54 -51
  53. data/lib/imap/backup/configuration/account.rb +0 -159
  54. data/lib/imap/backup/configuration/connection_tester.rb +0 -14
  55. data/lib/imap/backup/configuration/list.rb +0 -53
  56. data/spec/support/shared_examples/account_flagging.rb +0 -23
  57. data/spec/unit/imap/backup/configuration/list_spec.rb +0 -89
  58. data/spec/unit/imap/backup_spec.rb +0 -28
@@ -1,16 +1,16 @@
1
1
  require "highline"
2
2
 
3
- module Imap::Backup
4
- module Configuration; end
3
+ require "imap/backup/account"
4
+ require "imap/backup/setup/helpers"
5
5
 
6
- class Configuration::Setup
6
+ module Imap::Backup
7
+ class Setup
7
8
  class << self
8
9
  attr_accessor :highline
9
10
  end
10
11
  self.highline = HighLine.new
11
12
 
12
13
  def run
13
- Imap::Backup.setup_logging config
14
14
  catch :done do
15
15
  loop do
16
16
  Kernel.system("clear")
@@ -23,35 +23,41 @@ module Imap::Backup
23
23
 
24
24
  def show_menu
25
25
  self.class.highline.choose do |menu|
26
- menu.header = "Choose an action"
26
+ menu.header = <<~MENU.chomp
27
+ #{helpers.title_prefix} Main Menu
28
+
29
+ Choose an action
30
+ MENU
27
31
  account_items menu
28
32
  add_account_item menu
29
33
  toggle_logging_item menu
30
- menu.choice("save and exit") do
31
- config.save
32
- throw :done
33
- end
34
- menu.choice("exit without saving changes") do
35
- throw :done
34
+ if config.modified?
35
+ menu.choice("save and exit") do
36
+ config.save
37
+ throw :done
38
+ end
39
+ menu.choice("exit without saving changes") { throw :done }
40
+ else
41
+ menu.choice("quit") { throw :done }
36
42
  end
37
43
  end
38
44
  end
39
45
 
40
46
  def account_items(menu)
41
47
  config.accounts.each do |account|
42
- next if account[:delete]
48
+ next if account.marked_for_deletion?
43
49
 
44
- item = account[:username].clone
45
- item << " *" if account[:modified]
50
+ item = account.username.clone
51
+ item << " *" if account.modified?
46
52
  menu.choice(item) do
47
- edit_account account[:username]
53
+ edit_account account.username
48
54
  end
49
55
  end
50
56
  end
51
57
 
52
58
  def add_account_item(menu)
53
59
  menu.choice("add account") do
54
- username = Configuration::Asker.email
60
+ username = Asker.email
55
61
  edit_account username
56
62
  end
57
63
  end
@@ -61,35 +67,37 @@ module Imap::Backup
61
67
  new_setting = !config.debug?
62
68
  menu.choice(menu_item) do
63
69
  config.debug = new_setting
64
- Imap::Backup.setup_logging config
70
+ Imap::Backup::Logger.setup_logging(config)
65
71
  end
66
72
  end
67
73
 
68
74
  def config
69
- @config ||= Configuration::Store.new
75
+ @config ||= Configuration.new
70
76
  end
71
77
 
72
78
  def default_account_config(username)
73
- {
79
+ ::Imap::Backup::Account.new(
74
80
  username: username,
75
81
  password: "",
76
82
  local_path: File.join(config.path, username.tr("@", "_")),
77
83
  folders: []
78
- }.tap do |c|
84
+ ).tap do |a|
79
85
  server = Email::Provider.for_address(username)
80
- c[:server] = server.host if server.host
86
+ a.server = server.host if server.host
81
87
  end
82
88
  end
83
89
 
84
90
  def edit_account(username)
85
- account = config.accounts.find { |a| a[:username] == username }
91
+ account = config.accounts.find { |a| a.username == username }
86
92
  if account.nil?
87
93
  account = default_account_config(username)
88
94
  config.accounts << account
89
95
  end
90
- Configuration::Account.new(
91
- config, account, Configuration::Setup.highline
92
- ).run
96
+ Account.new(config, account, Setup.highline).run
97
+ end
98
+
99
+ def helpers
100
+ Helpers.new
93
101
  end
94
102
  end
95
103
  end
@@ -12,12 +12,12 @@ module Imap::Backup
12
12
  count = missing_uids.count
13
13
  return if count.zero?
14
14
 
15
- Imap::Backup.logger.debug "[#{folder.name}] #{count} to restore"
15
+ Imap::Backup::Logger.logger.debug "[#{folder.name}] #{count} to restore"
16
16
  serializer.each_message(missing_uids).with_index do |(uid, message), i|
17
17
  next if message.nil?
18
18
 
19
19
  log_prefix = "[#{folder.name}] uid: #{uid} (#{i + 1}/#{count}) -"
20
- Imap::Backup.logger.debug(
20
+ Imap::Backup::Logger.logger.debug(
21
21
  "#{log_prefix} #{message.supplied_body.size} bytes"
22
22
  )
23
23
 
@@ -2,8 +2,8 @@ module Imap; end
2
2
 
3
3
  module Imap::Backup
4
4
  MAJOR = 4
5
- MINOR = 0
6
- REVISION = 4
5
+ MINOR = 1
6
+ REVISION = 1
7
7
  PRE = nil
8
8
  VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".")
9
9
  end
data/lib/imap/backup.rb CHANGED
@@ -3,46 +3,20 @@ module Imap; end
3
3
  require "imap/backup/utils"
4
4
  require "imap/backup/account/connection"
5
5
  require "imap/backup/account/folder"
6
- require "imap/backup/configuration/account"
7
- require "imap/backup/configuration/asker"
8
- require "imap/backup/configuration/connection_tester"
9
- require "imap/backup/configuration/folder_chooser"
10
- require "imap/backup/configuration/list"
11
- require "imap/backup/configuration/setup"
12
- require "imap/backup/configuration/store"
6
+ require "imap/backup/configuration"
13
7
  require "imap/backup/downloader"
8
+ require "imap/backup/logger"
14
9
  require "imap/backup/uploader"
15
10
  require "imap/backup/serializer"
16
11
  require "imap/backup/serializer/mbox"
12
+ require "imap/backup/setup"
13
+ require "imap/backup/setup/account"
14
+ require "imap/backup/setup/asker"
15
+ require "imap/backup/setup/connection_tester"
16
+ require "imap/backup/setup/folder_chooser"
17
17
  require "imap/backup/version"
18
18
  require "email/provider"
19
19
 
20
- require "logger"
21
-
22
20
  module Imap::Backup
23
21
  class ConfigurationNotFound < StandardError; end
24
-
25
- class Logger
26
- include Singleton
27
-
28
- attr_reader :logger
29
-
30
- def initialize
31
- @logger = ::Logger.new($stdout)
32
- $stdout.sync = true
33
- end
34
- end
35
-
36
- def self.logger
37
- Logger.instance.logger
38
- end
39
-
40
- def self.setup_logging(config)
41
- logger.level =
42
- if config.debug?
43
- ::Logger::Severity::DEBUG
44
- else
45
- ::Logger::Severity::ERROR
46
- end
47
- end
48
22
  end
@@ -5,7 +5,7 @@ module RetryOnError
5
5
  rescue *errors => e
6
6
  if tries < limit
7
7
  message = "#{e}, attempt #{tries} of #{limit}"
8
- Imap::Backup.logger.debug message
8
+ Imap::Backup::Logger.logger.debug message
9
9
  tries += 1
10
10
  retry
11
11
  end
@@ -58,6 +58,7 @@ RSpec.describe "backup", type: :feature, docker: true do
58
58
  email3
59
59
  original_folder_uid_validity
60
60
  connection.run_backup
61
+ connection.disconnect
61
62
  server_rename_folder folder, new_name
62
63
  end
63
64
  let(:renamed_folder) { "#{folder}.#{original_folder_uid_validity}" }
@@ -63,11 +63,14 @@ module EmailServerHelpers
63
63
  end
64
64
 
65
65
  def server_folders
66
- root_info = imap.list("", "")[0]
67
- root = root_info.name
68
66
  imap.list(root, "*")
69
67
  end
70
68
 
69
+ def root
70
+ root_info = imap.list("", "")[0]
71
+ root_info.name
72
+ end
73
+
71
74
  def server_create_folder(folder)
72
75
  imap.create(folder)
73
76
  imap.disconnect
@@ -2,11 +2,13 @@ shared_context "imap-backup connection" do
2
2
  let(:local_backup_path) { Dir.mktmpdir(nil, "tmp") }
3
3
  let(:default_connection) { fixture("connection") }
4
4
  let(:backup_folders) { nil }
5
- let(:connection_options) do
6
- default_connection.merge(
7
- local_path: local_backup_path,
8
- folders: backup_folders
5
+ let(:account) do
6
+ Imap::Backup::Account.new(
7
+ default_connection.merge(
8
+ local_path: local_backup_path,
9
+ folders: backup_folders
10
+ )
9
11
  )
10
12
  end
11
- let(:connection) { Imap::Backup::Account::Connection.new(connection_options) }
13
+ let(:connection) { Imap::Backup::Account::Connection.new(account) }
12
14
  end
@@ -2,7 +2,7 @@ module HighLineTestHelpers
2
2
  def prepare_highline
3
3
  @input = instance_double(IO, eof?: false, gets: "q\n")
4
4
  @output = StringIO.new
5
- Imap::Backup::Configuration::Setup.highline = HighLine.new(@input, @output)
5
+ Imap::Backup::Setup.highline = HighLine.new(@input, @output)
6
6
  [@input, @output]
7
7
  end
8
8
  end
@@ -1,7 +1,7 @@
1
1
  def silence_logging
2
2
  RSpec.configure do |config|
3
3
  config.before(:suite) do
4
- Imap::Backup.logger.level = Logger::UNKNOWN
4
+ Imap::Backup::Logger.logger.level = Logger::UNKNOWN
5
5
  end
6
6
  end
7
7
  end
@@ -1,10 +1,4 @@
1
- describe Email::Provider::Default do
2
- describe "#host" do
3
- it "is unset" do
4
- expect(subject.host).to be_nil
5
- end
6
- end
7
-
1
+ describe Email::Provider::Base do
8
2
  describe "#options" do
9
3
  it "returns options" do
10
4
  expect(subject.options).to be_a(Hash)
@@ -17,10 +17,10 @@ describe Email::Provider do
17
17
  end
18
18
 
19
19
  context "with unknown providers" do
20
- it "returns a default provider" do
20
+ it "returns the Unknown provider" do
21
21
  result = described_class.for_address("foo@unknown.com")
22
22
 
23
- expect(result).to be_a(Email::Provider::Default)
23
+ expect(result).to be_a(Email::Provider::Unknown)
24
24
  end
25
25
  end
26
26
  end
@@ -5,6 +5,7 @@ describe Imap::Backup::Account::Connection do
5
5
  FOLDER_CONFIG = {name: BACKUP_FOLDER}.freeze
6
6
  FOLDER_NAME = "my_folder".freeze
7
7
  GMAIL_IMAP_SERVER = "imap.gmail.com".freeze
8
+ IMAP_FOLDER = "imap_folder".freeze
8
9
  LOCAL_PATH = "local_path".freeze
9
10
  LOCAL_UID = "local_uid".freeze
10
11
  PASSWORD = "secret".freeze
@@ -12,7 +13,7 @@ describe Imap::Backup::Account::Connection do
12
13
  SERVER = "imap.example.com".freeze
13
14
  USERNAME = "username@example.com".freeze
14
15
 
15
- subject { described_class.new(options) }
16
+ subject { described_class.new(account) }
16
17
 
17
18
  let(:client) do
18
19
  instance_double(
@@ -20,14 +21,16 @@ describe Imap::Backup::Account::Connection do
20
21
  )
21
22
  end
22
23
  let(:imap_folders) { [] }
23
- let(:options) do
24
- {
24
+ let(:account) do
25
+ instance_double(
26
+ Imap::Backup::Account,
25
27
  username: USERNAME,
26
28
  password: PASSWORD,
27
29
  local_path: LOCAL_PATH,
28
30
  folders: config_folders,
29
- server: server
30
- }
31
+ server: server,
32
+ connection_options: nil
33
+ )
31
34
  end
32
35
  let(:config_folders) { [FOLDER_CONFIG] }
33
36
  let(:root_info) do
@@ -59,21 +62,10 @@ describe Imap::Backup::Account::Connection do
59
62
  end
60
63
 
61
64
  describe "#initialize" do
62
- [
63
- [:username, USERNAME],
64
- [:password, PASSWORD],
65
- [:local_path, LOCAL_PATH],
66
- [:server, SERVER]
67
- ].each do |attr, expected|
68
- it "expects #{attr}" do
69
- expect(subject.public_send(attr)).to eq(expected)
70
- end
71
- end
72
-
73
65
  it "creates the path" do
74
66
  expect(Imap::Backup::Utils).to receive(:make_folder)
75
67
 
76
- subject.username
68
+ subject
77
69
  end
78
70
  end
79
71
 
@@ -110,19 +102,23 @@ describe Imap::Backup::Account::Connection do
110
102
  end
111
103
  end
112
104
 
113
- describe "#folders" do
105
+ describe "#folder_names" do
114
106
  let(:imap_folders) do
115
- [BACKUP_FOLDER]
107
+ [IMAP_FOLDER]
116
108
  end
117
109
 
118
110
  it "returns the list of folders" do
119
- expect(subject.folders).to eq([BACKUP_FOLDER])
111
+ expect(subject.folder_names).to eq([IMAP_FOLDER])
120
112
  end
121
113
  end
122
114
 
123
115
  describe "#status" do
124
116
  let(:folder) do
125
- instance_double(Imap::Backup::Account::Folder, uids: [remote_uid])
117
+ instance_double(
118
+ Imap::Backup::Account::Folder,
119
+ uids: [remote_uid],
120
+ name: IMAP_FOLDER
121
+ )
126
122
  end
127
123
  let(:remote_uid) { "remote_uid" }
128
124
 
@@ -132,7 +128,7 @@ describe Imap::Backup::Account::Connection do
132
128
  end
133
129
 
134
130
  it "returns the names of folders" do
135
- expect(subject.status[0][:name]).to eq(BACKUP_FOLDER)
131
+ expect(subject.status[0][:name]).to eq(IMAP_FOLDER)
136
132
  end
137
133
 
138
134
  it "returns local message uids" do
@@ -148,7 +144,7 @@ describe Imap::Backup::Account::Connection do
148
144
  let(:folder) do
149
145
  instance_double(
150
146
  Imap::Backup::Account::Folder,
151
- name: "folder",
147
+ name: IMAP_FOLDER,
152
148
  exist?: exists,
153
149
  uid_validity: uid_validity
154
150
  )
@@ -159,11 +155,11 @@ describe Imap::Backup::Account::Connection do
159
155
 
160
156
  before do
161
157
  allow(Imap::Backup::Downloader).
162
- to receive(:new).with(folder, serializer) { downloader }
158
+ to receive(:new).with(folder, serializer, anything) { downloader }
163
159
  allow(Imap::Backup::Account::Folder).to receive(:new).
164
160
  with(subject, BACKUP_FOLDER) { folder }
165
161
  allow(Imap::Backup::Serializer::Mbox).to receive(:new).
166
- with(LOCAL_PATH, BACKUP_FOLDER) { serializer }
162
+ with(LOCAL_PATH, IMAP_FOLDER) { serializer }
167
163
  end
168
164
 
169
165
  context "with supplied config_folders" do
@@ -257,7 +253,7 @@ describe Imap::Backup::Account::Connection do
257
253
  Imap::Backup::Account::Folder,
258
254
  create: nil,
259
255
  uids: uids,
260
- name: FOLDER_NAME,
256
+ name: IMAP_FOLDER,
261
257
  uid_validity: uid_validity
262
258
  )
263
259
  end
@@ -0,0 +1,47 @@
1
+ require "imap/backup/cli/accounts"
2
+
3
+ describe Imap::Backup::CLI::Accounts do
4
+ subject { described_class.new }
5
+
6
+ let(:accounts) { [account1, account2] }
7
+ let(:account1) do
8
+ instance_double(
9
+ Imap::Backup::Account,
10
+ username: "a1@example.com"
11
+ )
12
+ end
13
+ let(:account2) do
14
+ instance_double(
15
+ Imap::Backup::Account,
16
+ username: "a2@example.com"
17
+ )
18
+ end
19
+ let(:store) do
20
+ instance_double(Imap::Backup::Configuration, accounts: accounts)
21
+ end
22
+ let(:exists) { true }
23
+
24
+ before do
25
+ allow(Imap::Backup::Configuration).to receive(:new) { store }
26
+ allow(Imap::Backup::Configuration).
27
+ to receive(:exist?) { exists }
28
+ end
29
+
30
+ describe "#each" do
31
+ specify "calls the block with each account" do
32
+ result = subject.map { |a| a }
33
+
34
+ expect(result).to eq(accounts)
35
+ end
36
+
37
+ context "when the configuration file is missing" do
38
+ let(:exists) { false }
39
+
40
+ it "fails" do
41
+ expect do
42
+ subject.each {}
43
+ end.to raise_error(Imap::Backup::ConfigurationNotFound, /not found/)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,8 +1,18 @@
1
1
  describe Imap::Backup::CLI::Local do
2
- let(:list) do
3
- instance_double(Imap::Backup::Configuration::List, accounts: accounts)
2
+ let(:accounts) do
3
+ instance_double(
4
+ Imap::Backup::CLI::Accounts,
5
+ find: ->(&block) { [account].find { |a| block.call(a) } }
6
+ )
7
+ end
8
+ let(:account) do
9
+ instance_double(
10
+ Imap::Backup::Account,
11
+ username: email,
12
+ marked_for_deletion?: false,
13
+ modified?: false
14
+ )
4
15
  end
5
- let(:accounts) { [{username: email}] }
6
16
  let(:connection) do
7
17
  instance_double(
8
18
  Imap::Backup::Account::Connection,
@@ -31,9 +41,10 @@ describe Imap::Backup::CLI::Local do
31
41
 
32
42
  before do
33
43
  allow(Kernel).to receive(:puts)
34
- allow(Imap::Backup::Configuration::List).to receive(:new) { list }
44
+ allow(Imap::Backup::CLI::Accounts).to receive(:new) { accounts }
35
45
  allow(Imap::Backup::Account::Connection).to receive(:new) { connection }
36
46
  allow(Mail).to receive(:new) { mail }
47
+ allow(accounts).to receive(:each).and_yield(account)
37
48
  end
38
49
 
39
50
  describe "accounts" do
@@ -1,50 +1,62 @@
1
- describe Imap::Backup::CLI::Utils do
2
- let(:list) do
3
- instance_double(Imap::Backup::Configuration::List, accounts: accounts)
4
- end
5
- let(:accounts) { [{username: email}] }
6
- let(:connection) do
7
- instance_double(
8
- Imap::Backup::Account::Connection,
9
- local_folders: local_folders
10
- )
11
- end
12
- let(:local_folders) { [[serializer, folder]] }
13
- let(:folder) do
14
- instance_double(
15
- Imap::Backup::Account::Folder,
16
- exist?: true,
17
- name: "name",
18
- uid_validity: "uid_validity",
19
- uids: %w(123 456)
20
- )
21
- end
22
- let(:serializer) do
23
- instance_double(
24
- Imap::Backup::Serializer::Mbox,
25
- uids: %w(123 789),
26
- apply_uid_validity: nil,
27
- save: nil
28
- )
29
- end
30
- let(:email) { "foo@example.com" }
1
+ module Imap::Backup
2
+ describe CLI::Utils do
3
+ let(:accounts) do
4
+ instance_double(
5
+ CLI::Accounts,
6
+ find: ->(&block) { [account].find { |a| block.call(a) } }
7
+ )
8
+ end
9
+ let(:account) { instance_double(Account, username: email) }
10
+ let(:connection) do
11
+ instance_double(
12
+ Account::Connection,
13
+ account: account,
14
+ backup_folders: [folder]
15
+ )
16
+ end
17
+ let(:account) do
18
+ instance_double(
19
+ Account,
20
+ local_path: "path"
21
+ )
22
+ end
23
+ let(:folder) do
24
+ instance_double(
25
+ Account::Folder,
26
+ exist?: true,
27
+ name: "name",
28
+ uid_validity: "uid_validity",
29
+ uids: %w(123 456)
30
+ )
31
+ end
32
+ let(:serializer) do
33
+ instance_double(
34
+ Serializer::Mbox,
35
+ uids: %w(123 789),
36
+ apply_uid_validity: nil,
37
+ save: nil
38
+ )
39
+ end
40
+ let(:email) { "foo@example.com" }
31
41
 
32
- before do
33
- allow(Imap::Backup::Configuration::List).to receive(:new) { list }
34
- allow(Imap::Backup::Account::Connection).to receive(:new) { connection }
35
- end
42
+ before do
43
+ allow(CLI::Accounts).to receive(:new) { accounts }
44
+ allow(Account::Connection).to receive(:new) { connection }
45
+ allow(Serializer::Mbox).to receive(:new) { serializer }
46
+ end
36
47
 
37
- describe "ignore_history" do
38
- it "ensures the local UID validity matches the server" do
39
- subject.ignore_history(email)
48
+ describe "ignore_history" do
49
+ it "ensures the local UID validity matches the server" do
50
+ subject.ignore_history(email)
40
51
 
41
- expect(serializer).to have_received(:apply_uid_validity).with("uid_validity")
42
- end
52
+ expect(serializer).to have_received(:apply_uid_validity).with("uid_validity")
53
+ end
43
54
 
44
- it "fills the local folder with fake emails" do
45
- subject.ignore_history(email)
55
+ it "fills the local folder with fake emails" do
56
+ subject.ignore_history(email)
46
57
 
47
- expect(serializer).to have_received(:save).with("456", /From: fake@email.com/)
58
+ expect(serializer).to have_received(:save).with("456", /From: fake@email.com/)
59
+ end
48
60
  end
49
61
  end
50
62
  end