imap-backup 1.0.5 → 1.0.6

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +1 -1
  4. data/Gemfile +0 -1
  5. data/README.md +0 -1
  6. data/Rakefile +4 -9
  7. data/bin/imap-backup +0 -1
  8. data/imap-backup.gemspec +0 -1
  9. data/lib/email/mboxrd/message.rb +31 -32
  10. data/lib/imap/backup.rb +17 -4
  11. data/lib/imap/backup/account/connection.rb +70 -64
  12. data/lib/imap/backup/account/folder.rb +21 -26
  13. data/lib/imap/backup/configuration/account.rb +127 -73
  14. data/lib/imap/backup/configuration/asker.rb +38 -31
  15. data/lib/imap/backup/configuration/connection_tester.rb +9 -14
  16. data/lib/imap/backup/configuration/folder_chooser.rb +43 -48
  17. data/lib/imap/backup/configuration/list.rb +19 -24
  18. data/lib/imap/backup/configuration/setup.rb +56 -51
  19. data/lib/imap/backup/configuration/store.rb +47 -52
  20. data/lib/imap/backup/downloader.rb +11 -14
  21. data/lib/imap/backup/serializer/base.rb +8 -11
  22. data/lib/imap/backup/serializer/directory.rb +36 -41
  23. data/lib/imap/backup/serializer/mbox.rb +83 -88
  24. data/lib/imap/backup/utils.rb +0 -3
  25. data/lib/imap/backup/version.rb +1 -2
  26. data/spec/gather_rspec_coverage.rb +0 -1
  27. data/spec/spec_helper.rb +2 -7
  28. data/spec/unit/account/connection_spec.rb +0 -1
  29. data/spec/unit/account/folder_spec.rb +0 -1
  30. data/spec/unit/configuration/account_spec.rb +207 -136
  31. data/spec/unit/configuration/asker_spec.rb +59 -85
  32. data/spec/unit/configuration/connection_tester_spec.rb +36 -26
  33. data/spec/unit/configuration/folder_chooser_spec.rb +3 -6
  34. data/spec/unit/configuration/list_spec.rb +0 -1
  35. data/spec/unit/configuration/setup_spec.rb +8 -9
  36. data/spec/unit/configuration/store_spec.rb +1 -4
  37. data/spec/unit/downloader_spec.rb +0 -1
  38. data/spec/unit/email/mboxrd/message_spec.rb +0 -1
  39. data/spec/unit/serializer/base_spec.rb +0 -1
  40. data/spec/unit/serializer/directory_spec.rb +0 -1
  41. data/spec/unit/serializer/mbox_spec.rb +0 -1
  42. data/spec/unit/utils_spec.rb +0 -1
  43. metadata +2 -2
@@ -1,114 +1,88 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe Imap::Backup::Configuration::Asker do
5
- context '.email' do
6
- it 'should ask for an email' do
7
- Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with(/email/)
4
+ module Imap::Backup::Configuration
5
+ describe Asker do
6
+ let(:highline) { double }
8
7
 
9
- Imap::Backup::Configuration::Asker.email
8
+ subject { Asker.new(highline) }
9
+
10
+ context '#initialize' do
11
+ its(:highline) { should eq(highline) }
10
12
  end
11
13
 
12
- it 'should validate the address' do
13
- Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with(/email/) do |&block|
14
- q = stub('HighLine::Question', :default= => nil,
15
- :readline= => nil,
16
- :responses => {})
17
- q.should_receive(:validate=).with(instance_of(Regexp))
14
+ context '#email' do
15
+ let(:email) { 'email@example.com' }
18
16
 
19
- block.call q
17
+ before do
18
+ allow(highline).to receive(:ask).and_return(email)
19
+ @result = subject.email
20
20
  end
21
21
 
22
- Imap::Backup::Configuration::Asker.email
23
- end
24
-
25
- it 'should return the address' do
26
- Imap::Backup::Configuration::Setup.highline.stub!(:ask).with(/email/).and_return('new@example.com')
27
-
28
- Imap::Backup::Configuration::Asker.email.should == 'new@example.com'
29
- end
30
- end
22
+ it 'asks for an email' do
23
+ expect(highline).to have_received(:ask).with(/email/)
24
+ end
31
25
 
32
- context '.password' do
33
- before :each do
34
- Imap::Backup::Configuration::Setup.highline.stub!(:ask).with(/^password/).and_return('secret')
35
- Imap::Backup::Configuration::Setup.highline.stub!(:ask).with(/^repeat password/).and_return('secret')
26
+ it 'returns the address' do
27
+ expect(@result).to eq(email)
28
+ end
36
29
  end
37
30
 
38
- it 'should ask for a password and confirmation' do
39
- Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with(/^password/).and_return('secret')
40
- Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with(/^repeat password/).and_return('secret')
31
+ context '#password' do
32
+ let(:password1) { 'password' }
33
+ let(:password2) { 'password' }
34
+ let(:answers) { [answer1, answer2] }
35
+ let(:answer1) { true }
36
+ let(:answer2) { false }
37
+
38
+ before do
39
+ @i = 0
40
+ allow(highline).to receive(:ask).with('password: ').and_return(password1)
41
+ allow(highline).to receive(:ask).with('repeat password: ').and_return(password2)
42
+ allow(highline).to receive(:agree) do
43
+ answer = answers[@i]
44
+ @i += 1
45
+ answer
46
+ end
47
+ @result = subject.password
48
+ end
41
49
 
42
- Imap::Backup::Configuration::Asker.password
43
- end
50
+ it 'asks for a password' do
51
+ expect(highline).to have_received(:ask).with('password: ')
52
+ end
44
53
 
45
- it 'should return the password' do
46
- Imap::Backup::Configuration::Asker.password.should == 'secret'
47
- end
54
+ it 'asks for confirmation' do
55
+ expect(highline).to have_received(:ask).with('repeat password: ')
56
+ end
48
57
 
49
- it "should ask again if the passwords don't match" do
50
- state = :password1
51
- Imap::Backup::Configuration::Setup.highline.stub!(:ask) do
52
- case state
53
- when :password1
54
- state = :confirmation1
55
- 'secret'
56
- when :confirmation1
57
- state = :retry?
58
- 'wrong!!!'
59
- when :retry?
60
- state = :password2
61
- 'y'
62
- when :password2
63
- state = :confirmation2
64
- 'secret'
65
- when :confirmation2
66
- 'secret'
67
- end
58
+ it 'returns the password' do
59
+ expect(@result).to eq(password1)
68
60
  end
69
61
 
70
- Imap::Backup::Configuration::Asker.password
71
- end
62
+ context 'different answers' do
63
+ let(:password2) { 'secret' }
72
64
 
73
- it 'should return nil if the user cancels' do
74
- state = :password1
75
- Imap::Backup::Configuration::Setup.highline.stub!(:ask) do
76
- case state
77
- when :password1
78
- state = :confirmation1
79
- 'secret'
80
- when :confirmation1
81
- state = :retry?
82
- 'wrong!!!'
83
- when :retry?
84
- state = :password2
85
- 'n'
65
+ it 'asks to continue' do
66
+ expect(highline).to have_received(:agree).at_least(1).times.with(/Continue\?/)
86
67
  end
87
68
  end
88
-
89
- Imap::Backup::Configuration::Asker.password.should be_nil
90
69
  end
91
- end
92
70
 
93
- context '.backup_path' do
94
- it 'should ask for a directory' do
95
- validator = /validator/
96
- Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with(/directory/) do |&block|
97
- q = stub('HighLine::Question', :responses => {}, :readline= => nil)
98
- q.should_receive(:default=).with('default path')
99
- q.should_receive(:validate=).with(validator)
71
+ context '#backup_path' do
72
+ let(:path) { '/path' }
100
73
 
101
- block.call q
74
+ before do
75
+ allow(highline).to receive(:ask).and_return(path)
76
+ @result = subject.backup_path('', //)
102
77
  end
103
78
 
104
- Imap::Backup::Configuration::Asker.backup_path('default path', validator)
105
- end
106
-
107
- it 'should return the choice' do
108
- Imap::Backup::Configuration::Setup.highline.should_receive(:ask).with(/directory/).and_return('/path')
79
+ it 'asks for a directory' do
80
+ expect(highline).to have_received(:ask).with(/directory/)
81
+ end
109
82
 
110
- Imap::Backup::Configuration::Asker.backup_path('default path', //).should == '/path'
83
+ it 'returns the path' do
84
+ expect(@result).to eq(path)
85
+ end
111
86
  end
112
87
  end
113
88
  end
114
-
@@ -3,41 +3,51 @@ require 'spec_helper'
3
3
 
4
4
  describe Imap::Backup::Configuration::ConnectionTester do
5
5
  context '.test' do
6
- it 'should try to connect' do
7
- Imap::Backup::Account::Connection.should_receive(:new).with('foo')
6
+ let(:connection) { double('Imap::Backup::Account::Connection', :imap => nil) }
8
7
 
9
- Imap::Backup::Configuration::ConnectionTester.test('foo')
8
+ before do
9
+ allow(Imap::Backup::Account::Connection).to receive(:new).and_return(connection)
10
10
  end
11
11
 
12
- it 'should return success if the connection works' do
13
- Imap::Backup::Account::Connection.stub!(:new).
14
- with('foo')
12
+ context 'call' do
13
+ before { @result = subject.test('foo') }
15
14
 
16
- result = Imap::Backup::Configuration::ConnectionTester.test('foo')
17
-
18
- result.should =~ /successful/
15
+ it 'tries to connect' do
16
+ expect(connection).to have_received(:imap)
17
+ end
19
18
  end
20
19
 
21
- it 'should handle no response' do
22
- e = Net::IMAP::NoResponseError.new(stub('o', :data => stub('foo', :text => 'bar')))
23
- Imap::Backup::Account::Connection.stub!(:new).
24
- with('foo').
25
- and_raise(e)
26
-
27
- result = Imap::Backup::Configuration::ConnectionTester.test('foo')
20
+ context 'success' do
21
+ before { @result = subject.test('foo') }
28
22
 
29
- result.should =~ /no response/i
23
+ it 'returns success' do
24
+ expect(@result).to match(/successful/)
25
+ end
30
26
  end
31
27
 
32
- it 'should handle other errors' do
33
- Imap::Backup::Account::Connection.stub!(:new).
34
- with('foo').
35
- and_raise('error')
36
-
37
- result = Imap::Backup::Configuration::ConnectionTester.test('foo')
38
-
39
- result.should =~ /unexpected error/i
28
+ context 'failure' do
29
+ before do
30
+ allow(connection).to receive(:imap).and_raise(error)
31
+ @result = subject.test('foo')
32
+ end
33
+
34
+ context 'no connection' do
35
+ let(:error) do
36
+ data = double('foo', :text => 'bar')
37
+ Net::IMAP::NoResponseError.new(double('o', :data => data))
38
+ end
39
+
40
+ it 'returns success' do
41
+ expect(@result).to match(/no response/i)
42
+ end
43
+ end
44
+
45
+ context 'other' do
46
+ let(:error) { 'Error' }
47
+ it 'returns success' do
48
+ expect(@result).to match(/unexpected error/i)
49
+ end
50
+ end
40
51
  end
41
52
  end
42
53
  end
43
-
@@ -8,9 +8,7 @@ describe Imap::Backup::Configuration::FolderChooser do
8
8
 
9
9
  context '#run' do
10
10
  let(:connection) do
11
- stub(
12
- 'Imap::Backup::Account::Connection'
13
- )
11
+ stub('Imap::Backup::Account::Connection')
14
12
  end
15
13
  let(:existing_account) do
16
14
  {
@@ -124,7 +122,7 @@ describe Imap::Backup::Configuration::FolderChooser do
124
122
  subject.run
125
123
 
126
124
  @output.string.should =~ /\d+\. \+ another_folder/
127
- account[:folders].should include( { :name => 'another_folder' } )
125
+ account[:folders].should include({:name => 'another_folder'})
128
126
  end
129
127
 
130
128
  it 'should remove folders' do
@@ -142,9 +140,8 @@ describe Imap::Backup::Configuration::FolderChooser do
142
140
  subject.run
143
141
 
144
142
  @output.string.should =~ /\d+\. \- my_folder/
145
- account[:folders].should_not include( { :name => 'my_folder' } )
143
+ account[:folders].should_not include({:name => 'my_folder'})
146
144
  end
147
145
  end
148
146
  end
149
147
  end
150
-
@@ -74,4 +74,3 @@ describe Imap::Backup::Configuration::List do
74
74
  end
75
75
  end
76
76
  end
77
-
@@ -5,10 +5,10 @@ describe Imap::Backup::Configuration::Setup do
5
5
  include HighLineTestHelpers
6
6
 
7
7
  context '#initialize' do
8
- it 'should not require the config file to exist' do
9
- Imap::Backup::Configuration::Store.should_receive(:new)
10
-
11
- Imap::Backup::Configuration::Setup.new
8
+ context 'without a config file' do
9
+ it 'works' do
10
+ Imap::Backup::Configuration::Setup.new
11
+ end
12
12
  end
13
13
  end
14
14
 
@@ -20,8 +20,8 @@ describe Imap::Backup::Configuration::Setup do
20
20
  end
21
21
 
22
22
  def prepare_store
23
- @account1 = { :username => 'account@example.com' }
24
- @data = { :accounts => [ @account1 ] }
23
+ @account1 = {:username => 'account@example.com'}
24
+ @data = {:accounts => [@account1]}
25
25
  @store = stub('Imap::Backup::Configuration::Store', :data => @data, :path => '/base/path')
26
26
  Imap::Backup::Configuration::Store.stub!(:new).and_return(@store)
27
27
  end
@@ -65,7 +65,7 @@ describe Imap::Backup::Configuration::Setup do
65
65
  end
66
66
 
67
67
  @account = stub('Imap::Backup::Configuration::Account')
68
- Imap::Backup::Configuration::Account.should_receive(:new).with(@store, @account1).and_return(@account)
68
+ allow(Imap::Backup::Configuration::Account).to receive(:new).with(@store, @account1, anything).and_return(@account)
69
69
  @account.should_receive(:run).with()
70
70
 
71
71
  subject.run
@@ -86,7 +86,7 @@ describe Imap::Backup::Configuration::Setup do
86
86
  blank_account = {:username=>"new@example.com", :password=>"", :local_path=>"/base/path/new_example.com", :folders=>[]}
87
87
  Imap::Backup::Configuration::Asker.should_receive(:email).with().and_return('new@example.com')
88
88
  @account = stub('Imap::Backup::Configuration::Account')
89
- Imap::Backup::Configuration::Account.should_receive(:new).with(@store, blank_account).and_return(@account)
89
+ allow(Imap::Backup::Configuration::Account).to receive(:new).with(@store, blank_account, anything).and_return(@account)
90
90
  @account.should_receive(:run).once
91
91
 
92
92
  subject.run
@@ -114,4 +114,3 @@ describe Imap::Backup::Configuration::Setup do
114
114
  end
115
115
  end
116
116
  end
117
-
@@ -146,9 +146,7 @@ describe Imap::Backup::Configuration::Store do
146
146
  end
147
147
 
148
148
  it 'should create a path for folders with slashes' do
149
- folders = [
150
- { :name => 'folder/path' },
151
- ]
149
+ folders = [{:name => 'folder/path'}]
152
150
  JSON.stub!(:parse).with('xxx', :symbolize_names => true).and_return(configuration(folders))
153
151
 
154
152
  File.should_receive(:directory?).with('/my/backup/path/folder').and_return(true)
@@ -161,4 +159,3 @@ describe Imap::Backup::Configuration::Store do
161
159
  end
162
160
  end
163
161
  end
164
-
@@ -84,4 +84,3 @@ describe Imap::Backup::Downloader do
84
84
  end
85
85
  end
86
86
  end
87
-
@@ -48,4 +48,3 @@ describe Email::Mboxrd::Message do
48
48
  end
49
49
  end
50
50
  end
51
-
@@ -16,4 +16,3 @@ describe Imap::Backup::Serializer::Base do
16
16
  end
17
17
  end
18
18
  end
19
-
@@ -76,4 +76,3 @@ describe Imap::Backup::Serializer::Directory do
76
76
  end
77
77
  end
78
78
  end
79
-
@@ -110,4 +110,3 @@ describe Imap::Backup::Serializer::Mbox do
110
110
  end
111
111
  end
112
112
  end
113
-
@@ -66,4 +66,3 @@ describe Imap::Backup::Utils do
66
66
  end
67
67
  end
68
68
  end
69
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-12 00:00:00.000000000 Z
11
+ date: 2013-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake