imap-backup 1.0.1 → 1.0.2
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.
- data/lib/imap/backup/account/folder.rb +3 -0
- data/lib/imap/backup/configuration/account.rb +1 -0
- data/lib/imap/backup/configuration/folder_chooser.rb +1 -0
- data/lib/imap/backup/configuration/setup.rb +1 -0
- data/lib/imap/backup/version.rb +2 -2
- data/spec/unit/account/folder_spec.rb +16 -0
- data/spec/unit/configuration/account_spec.rb +7 -0
- data/spec/unit/configuration/folder_chooser_spec.rb +70 -45
- data/spec/unit/configuration/setup_spec.rb +7 -0
- metadata +4 -4
data/lib/imap/backup/version.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Imap::Backup::Account::Folder do
|
5
|
+
include InputOutputTestHelpers
|
6
|
+
|
5
7
|
context 'with instance' do
|
6
8
|
before :each do
|
7
9
|
@imap = stub('Net::IMAP')
|
@@ -17,6 +19,20 @@ describe Imap::Backup::Account::Folder do
|
|
17
19
|
|
18
20
|
subject.uids.should == [123, 5678]
|
19
21
|
end
|
22
|
+
|
23
|
+
it 'returns an empty array for missing mailboxes' do
|
24
|
+
data = stub('Data', :text => 'Unknown Mailbox: my_folder')
|
25
|
+
response = stub('Response', :data => data)
|
26
|
+
error = Net::IMAP::NoResponseError.new(response)
|
27
|
+
@imap.
|
28
|
+
should_receive(:examine).
|
29
|
+
with('my_folder').
|
30
|
+
and_raise(error)
|
31
|
+
|
32
|
+
capturing_output do
|
33
|
+
expect(subject.uids).to eq([])
|
34
|
+
end
|
35
|
+
end
|
20
36
|
end
|
21
37
|
|
22
38
|
context '#fetch' do
|
@@ -38,11 +38,18 @@ describe Imap::Backup::Configuration::Account do
|
|
38
38
|
@store = stub('Imap::Backup::Configuration::Store')
|
39
39
|
@store.stub!(:data => @data)
|
40
40
|
@input, @output = prepare_highline
|
41
|
+
subject.stub(:system => nil)
|
41
42
|
end
|
42
43
|
|
43
44
|
subject { Imap::Backup::Configuration::Account.new(@store, @account1) }
|
44
45
|
|
45
46
|
context 'menu' do
|
47
|
+
it 'clears the screen' do
|
48
|
+
subject.should_receive(:system).with('clear')
|
49
|
+
|
50
|
+
subject.run
|
51
|
+
end
|
52
|
+
|
46
53
|
it 'should show a menu' do
|
47
54
|
subject.run
|
48
55
|
|
@@ -7,68 +7,93 @@ describe Imap::Backup::Configuration::FolderChooser do
|
|
7
7
|
include InputOutputTestHelpers
|
8
8
|
|
9
9
|
context '#run' do
|
10
|
-
|
11
|
-
|
10
|
+
let(:connection) do
|
11
|
+
stub(
|
12
|
+
'Imap::Backup::Account::Connection'
|
13
|
+
)
|
14
|
+
end
|
15
|
+
let(:existing_account) do
|
16
|
+
{
|
17
|
+
:folders => [{:name => 'my_folder'}]
|
18
|
+
}
|
19
|
+
end
|
20
|
+
let(:empty_account) do
|
21
|
+
{
|
12
22
|
:folders => []
|
13
23
|
}
|
14
|
-
|
15
|
-
|
24
|
+
end
|
25
|
+
let(:remote_folders) do
|
26
|
+
folder1 = stub('folder', :name => 'my_folder') # this one is already backed up
|
27
|
+
folder2 = stub('folder', :name => 'another_folder')
|
28
|
+
[folder1, folder2]
|
16
29
|
end
|
17
30
|
|
18
|
-
|
19
|
-
@
|
20
|
-
connection = stub('Imap::Backup::Account::Connection')
|
21
|
-
connection.stub!(:folders).and_return(remote_folders)
|
22
|
-
Imap::Backup::Account::Connection.stub!(:new).with(account).and_return(connection)
|
23
|
-
connection
|
31
|
+
before do
|
32
|
+
@input, @output = prepare_highline
|
24
33
|
end
|
25
34
|
|
26
|
-
|
35
|
+
context 'empty account' do
|
36
|
+
let(:account) { empty_account }
|
27
37
|
|
28
|
-
|
29
|
-
Imap::Backup::Account::Connection.should_receive(:new).with(@account).and_return(@connection)
|
38
|
+
subject { Imap::Backup::Configuration::FolderChooser.new(account) }
|
30
39
|
|
31
|
-
|
32
|
-
|
40
|
+
before do
|
41
|
+
connection.stub!(:folders).and_return([])
|
42
|
+
Imap::Backup::Account::Connection.stub!(:new).with(account).and_return(connection)
|
43
|
+
subject.stub(:system).with('clear')
|
44
|
+
end
|
33
45
|
|
34
|
-
|
35
|
-
|
36
|
-
Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with('Press a key ')
|
46
|
+
it 'should connect to the account' do
|
47
|
+
Imap::Backup::Account::Connection.should_receive(:new).with(account).and_return(connection)
|
37
48
|
|
38
|
-
capturing_output do
|
39
49
|
subject.run
|
40
|
-
end
|
41
|
-
end
|
50
|
+
end
|
42
51
|
|
43
|
-
|
44
|
-
|
52
|
+
it 'should handle connection errors' do
|
53
|
+
Imap::Backup::Account::Connection.should_receive(:new).with(account).and_raise('error')
|
54
|
+
Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with('Press a key ')
|
45
55
|
|
46
|
-
|
47
|
-
|
56
|
+
capturing_output do
|
57
|
+
subject.run
|
58
|
+
end.should =~ /connection failed/i
|
59
|
+
end
|
48
60
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
@output.string.should =~ %r{Add/remove folders}
|
53
|
-
end
|
61
|
+
it 'should get a list of account folders' do
|
62
|
+
connection.should_receive(:folders).and_return([])
|
54
63
|
|
55
|
-
|
56
|
-
|
64
|
+
subject.run
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'clears the screen' do
|
68
|
+
subject.should_receive(:system).with('clear')
|
57
69
|
|
58
|
-
|
59
|
-
|
60
|
-
|
70
|
+
subject.run
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should show the menu' do
|
74
|
+
subject.run
|
75
|
+
|
76
|
+
@output.string.should =~ %r{Add/remove folders}
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should return to the account menu' do
|
80
|
+
@input.should_receive(:gets).and_return("return\n")
|
81
|
+
|
82
|
+
subject.run
|
83
|
+
|
84
|
+
@output.string.should =~ %r{return to the account menu}
|
85
|
+
end
|
61
86
|
end
|
62
87
|
|
63
88
|
context 'folder listing' do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
89
|
+
let(:account) { existing_account }
|
90
|
+
|
91
|
+
subject { Imap::Backup::Configuration::FolderChooser.new(account) }
|
92
|
+
|
93
|
+
before do
|
94
|
+
connection.stub!(:folders).and_return(remote_folders)
|
95
|
+
Imap::Backup::Account::Connection.stub!(:new).with(account).and_return(connection)
|
96
|
+
subject.stub(:system).with('clear')
|
72
97
|
end
|
73
98
|
|
74
99
|
it 'should list folders' do
|
@@ -99,7 +124,7 @@ describe Imap::Backup::Configuration::FolderChooser do
|
|
99
124
|
subject.run
|
100
125
|
|
101
126
|
@output.string.should =~ /\d+\. \+ another_folder/
|
102
|
-
|
127
|
+
account[:folders].should include( { :name => 'another_folder' } )
|
103
128
|
end
|
104
129
|
|
105
130
|
it 'should remove folders' do
|
@@ -117,7 +142,7 @@ describe Imap::Backup::Configuration::FolderChooser do
|
|
117
142
|
subject.run
|
118
143
|
|
119
144
|
@output.string.should =~ /\d+\. \- my_folder/
|
120
|
-
|
145
|
+
account[:folders].should_not include( { :name => 'my_folder' } )
|
121
146
|
end
|
122
147
|
end
|
123
148
|
end
|
@@ -16,6 +16,7 @@ describe Imap::Backup::Configuration::Setup do
|
|
16
16
|
before :each do
|
17
17
|
prepare_store
|
18
18
|
@input, @output = prepare_highline
|
19
|
+
subject.stub(:system => nil)
|
19
20
|
end
|
20
21
|
|
21
22
|
def prepare_store
|
@@ -39,6 +40,12 @@ describe Imap::Backup::Configuration::Setup do
|
|
39
40
|
@output.string.should =~ /quit/
|
40
41
|
end
|
41
42
|
|
43
|
+
it 'clears the screen' do
|
44
|
+
subject.should_receive(:system).with('clear')
|
45
|
+
|
46
|
+
subject.run
|
47
|
+
end
|
48
|
+
|
42
49
|
it 'should list accounts' do
|
43
50
|
subject.run
|
44
51
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imap-backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -187,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
187
187
|
version: '0'
|
188
188
|
segments:
|
189
189
|
- 0
|
190
|
-
hash:
|
190
|
+
hash: -2027383479193417702
|
191
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
192
|
none: false
|
193
193
|
requirements:
|
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
196
|
version: '0'
|
197
197
|
segments:
|
198
198
|
- 0
|
199
|
-
hash:
|
199
|
+
hash: -2027383479193417702
|
200
200
|
requirements: []
|
201
201
|
rubyforge_project:
|
202
202
|
rubygems_version: 1.8.23
|