euromail 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 681fed0406570f2d0611fbc0cec27e340f8fdbf4
4
- data.tar.gz: 889b36e9dff7dc703072f7e74fe1c59f8219d328
3
+ metadata.gz: 7310e9a1f83998fbb895d06f34dd0ec9292fdd7a
4
+ data.tar.gz: 462798a9e3ac58a3d2d56f8a74317e78e5ae0762
5
5
  SHA512:
6
- metadata.gz: 7aa8eed727a2ba83c434bd27cfe2c1c966e1643ab16669c9326eed539a367fdb38031af1a2c95443d024e60d8b57a6e7ee67118b056f016b531308efbf40840e
7
- data.tar.gz: 3e5442d4d27aaf9c91d2dde95686bb521a052c6171b1c181554b6366996845001547f05424247accae4d3d32e8dd02e6c13aa71735848ec2693a200006bea615
6
+ metadata.gz: 5feb196cfd433982b982c30e2ea38b87b083f917265f19b1f836e1a7e8dffd67f0da531ac27b2c4d2e62a8f5512be65ab0c0ee9203f1130228caa79992bb93f1
7
+ data.tar.gz: b3b8d8591ae0699fb0b24a45b9bb6f598712d7c1967c71b311c3f1e6f57dd25761775ba822bc3a4ec4fa2918fdb551de5f42152b96374aca7761c094b72509d6
@@ -5,12 +5,13 @@ module Euromail
5
5
 
6
6
  attr_reader :application, :customer, :host, :username, :password, :current_mode
7
7
 
8
- def initialize application, customer, host, username, password
8
+ def initialize application, customer, host, username, password, net_ssh_options={}
9
9
  @application = application
10
10
  @customer = customer
11
11
  @host = host
12
12
  @username = username
13
13
  @password = password
14
+ @net_ssh_options = net_ssh_options
14
15
  @current_mode = :production
15
16
  end
16
17
 
@@ -37,7 +38,7 @@ module Euromail
37
38
  end
38
39
  end
39
40
 
40
- # Attempt to remove the file for the given identifier.
41
+ # Attempt to remove the file for the given identifier.
41
42
  def remove! identifier
42
43
  connect do |connection|
43
44
  connection.remove( identifier )
@@ -51,7 +52,8 @@ module Euromail
51
52
  # connection.remove('3')
52
53
  # end
53
54
  def connect &block
54
- Net::SFTP.start(host, username, :password => password) do |sftp|
55
+ options = {password: password }.merge(@net_ssh_options)
56
+ Net::SFTP.start(host, username, options) do |sftp|
55
57
  connection = Euromail::SFTPConnection.new(self, sftp)
56
58
  block.call(connection)
57
59
  end
@@ -65,4 +67,4 @@ module Euromail
65
67
  end
66
68
 
67
69
  end
68
- end
70
+ end
@@ -13,7 +13,7 @@ describe Euromail::SFTPConnection do
13
13
 
14
14
  describe "#upload" do
15
15
  it "use the generated filename" do
16
- @net_sftp_session.should receive(:upload!).with( @string_io, euromail.filename('1') )
16
+ expect(@net_sftp_session).to receive(:upload!).with( @string_io, euromail.filename('1') )
17
17
  euromail.connect do |connection|
18
18
  connection.upload('some-client-code', '1')
19
19
  end
@@ -29,8 +29,8 @@ describe Euromail::SFTPConnection do
29
29
 
30
30
  it "can upload several pdf files within the same connection" do
31
31
  expect(@net_sftp_session).to receive(:upload!).exactly(2).times
32
- StringIO.should receive(:new).with('some-client-code-1')
33
- StringIO.should receive(:new).with('some-client-code-2')
32
+ expect(StringIO).to receive(:new).with('some-client-code-1')
33
+ expect(StringIO).to receive(:new).with('some-client-code-2')
34
34
 
35
35
  euromail.connect do |connection|
36
36
  connection.upload("some-client-code-1", '1')
@@ -41,7 +41,7 @@ describe Euromail::SFTPConnection do
41
41
 
42
42
  describe "#remove" do
43
43
  it "removes the file with the generated filename" do
44
- @net_sftp_session.should receive(:remove!).with( euromail.filename('1') )
44
+ expect(@net_sftp_session).to receive(:remove!).with( euromail.filename('1') )
45
45
  euromail.connect do |connection|
46
46
  connection.remove('1')
47
47
  end
@@ -17,19 +17,23 @@ describe Euromail::SFTPService do
17
17
  end
18
18
 
19
19
  it "the current mode is development" do
20
- euromail.current_mode.should eql :development
20
+ expect(euromail.current_mode).to eql :development
21
21
  end
22
22
 
23
23
  describe "#upload" do
24
24
  it "does not upload anything" do
25
- @file_hander.should_not receive(:write)
25
+ expect(@file_hander).not_to receive(:write)
26
+ allow($stdout).to receive(:puts)
27
+ euromail.connect do |connection|
28
+ connection.upload('come-client-code', '3')
29
+ end
26
30
  end
27
31
 
28
32
  it "logs uploads" do
29
- Net::SFTP.should_not receive(:start)
30
- $stdout.should receive(:puts).with("Connecting to some-cheapass-domain.com")
31
- $stdout.should receive(:puts).with("Uploaded ./moves_nedap_3.pdf")
32
- $stdout.should receive(:puts).with("Connection to some-cheapass-domain.com closed")
33
+ expect(Net::SFTP).not_to receive(:start)
34
+ expect($stdout).to receive(:puts).with("Connecting to some-cheapass-domain.com")
35
+ expect($stdout).to receive(:puts).with("Uploaded ./moves_nedap_3.pdf")
36
+ expect($stdout).to receive(:puts).with("Connection to some-cheapass-domain.com closed")
33
37
  euromail.connect do |connection|
34
38
  connection.upload('come-client-code', '3')
35
39
  end
@@ -38,14 +42,18 @@ describe Euromail::SFTPService do
38
42
 
39
43
  describe "#remove" do
40
44
  it "does not remove anything" do
41
- @net_sftp_session.should_not receive(:remove!)
45
+ expect(@net_sftp_session).not_to receive(:remove!)
46
+ allow($stdout).to receive(:puts)
47
+ euromail.connect do |connection|
48
+ connection.remove('3')
49
+ end
42
50
  end
43
51
 
44
52
  it "logs deletes" do
45
- Net::SFTP.should_not receive(:start)
46
- $stdout.should receive(:puts).with("Connecting to some-cheapass-domain.com")
47
- $stdout.should receive(:puts).with("Removed ./moves_nedap_3.pdf")
48
- $stdout.should receive(:puts).with("Connection to some-cheapass-domain.com closed")
53
+ expect(Net::SFTP).not_to receive(:start)
54
+ expect($stdout).to receive(:puts).with("Connecting to some-cheapass-domain.com")
55
+ expect($stdout).to receive(:puts).with("Removed ./moves_nedap_3.pdf")
56
+ expect($stdout).to receive(:puts).with("Connection to some-cheapass-domain.com closed")
49
57
  euromail.connect do |connection|
50
58
  connection.remove('3')
51
59
  end
@@ -54,9 +62,9 @@ describe Euromail::SFTPService do
54
62
 
55
63
  describe "#connect" do
56
64
  it "logs the connection" do
57
- Net::SFTP.should_not receive(:start)
58
- $stdout.should receive(:puts).with("Connecting to some-cheapass-domain.com")
59
- $stdout.should receive(:puts).with("Connection to some-cheapass-domain.com closed")
65
+ expect(Net::SFTP).not_to receive(:start)
66
+ expect($stdout).to receive(:puts).with("Connecting to some-cheapass-domain.com")
67
+ expect($stdout).to receive(:puts).with("Connection to some-cheapass-domain.com closed")
60
68
  euromail.connect {}
61
69
  end
62
70
  end
@@ -11,71 +11,82 @@ describe Euromail::SFTPService do
11
11
  Euromail::SFTPService.new('moves', 'nedap', 'some-cheapass-domain.com', "stefan", "super_secret")
12
12
  end
13
13
 
14
+ let(:euromail_with_option) do
15
+ Euromail::SFTPService.new('moves', 'nedap', 'some-cheapass-domain.com', "stefan", "super_secret", {
16
+ some_option: "test option"
17
+ })
18
+ end
19
+
14
20
  context "when creating" do
15
21
  it "has an application, customer, host, username and password" do
16
- euromail.application.should eql('moves')
17
- euromail.customer.should eql('nedap')
18
- euromail.host.should eql('some-cheapass-domain.com')
19
- euromail.username.should eql('stefan')
20
- euromail.password.should eql('super_secret')
22
+ expect(euromail.application).to eql('moves')
23
+ expect(euromail.customer).to eql('nedap')
24
+ expect(euromail.host).to eql('some-cheapass-domain.com')
25
+ expect(euromail.username).to eql('stefan')
26
+ expect(euromail.password).to eql('super_secret')
21
27
  end
22
28
 
23
29
  it "the current mode is production" do
24
- euromail.current_mode.should eql :production
30
+ expect(euromail.current_mode).to eql :production
25
31
  end
26
32
  end
27
33
 
28
34
  describe "#connect" do
29
35
  it "connects to euromail using the given username and pass" do
30
- Net::SFTP.should receive(:start).with('some-cheapass-domain.com', 'stefan', :password => 'super_secret')
36
+ expect(Net::SFTP).to receive(:start).with('some-cheapass-domain.com', 'stefan', :password => 'super_secret')
31
37
  euromail.connect {}
32
38
  end
39
+
40
+ it "connects using additional net_ssh options passed from the user" do
41
+ expect(Net::SFTP).to receive(:start).with('some-cheapass-domain.com', 'stefan', :password => 'super_secret', :some_option => "test option")
42
+ euromail_with_option.connect {}
43
+ end
33
44
  end
34
45
 
35
46
  describe "#upload!" do
36
47
  it "uploads pdf data" do
37
- StringIO.should receive(:new).with('some-client-code')
38
- @net_sftp_session.should receive(:upload!).with(@string_io, euromail.filename('1'))
48
+ expect(StringIO).to receive(:new).with('some-client-code')
49
+ expect(@net_sftp_session).to receive(:upload!).with(@string_io, euromail.filename('1'))
39
50
  euromail.upload!('some-client-code', '1')
40
51
  end
41
52
 
42
53
  it "does not remove the remote file after an upload succeeds" do
43
- euromail.should_not receive(:remove!).with('1')
54
+ expect(euromail).not_to receive(:remove!).with('1')
44
55
  euromail.upload!('some-client-code', '1')
45
56
  end
46
57
 
47
58
  it "tries to remove the remote file after an upload fails" do
48
- @net_sftp_session.stub(:upload!).and_raise("Connection dropped")
49
- euromail.should receive(:remove!).with('1')
50
- expect{ euromail.upload!('some-client-code', '1') }.to raise_error
59
+ expect(@net_sftp_session).to receive(:upload!).and_raise("Connection dropped")
60
+ expect(euromail).to receive(:remove!).with('1')
61
+ expect{ euromail.upload!('some-client-code', '1') }.to raise_error("Connection dropped")
51
62
  end
52
63
 
53
64
  it "raises if some error occurs" do
54
- @net_sftp_session.stub(:upload!).and_raise("Some error")
55
- expect{ euromail.upload!('some-client-code', '2') }.to raise_error
65
+ expect(@net_sftp_session).to receive(:upload!).and_raise("Some error")
66
+ expect{ euromail.upload!('some-client-code', '2') }.to raise_error("Some error")
56
67
  end
57
68
  end
58
69
 
59
70
  describe "#remove!" do
60
71
  it "removes the file from the sftp server" do
61
- @net_sftp_session.should receive(:remove!).with( euromail.filename('2') )
72
+ expect(@net_sftp_session).to receive(:remove!).with( euromail.filename('2') )
62
73
  euromail.remove!('2')
63
74
  end
64
75
 
65
76
  it "raises if some error occurs" do
66
- @net_sftp_session.stub(:remove!).and_raise("Some error")
67
- expect{ euromail.remove!('2') }.to raise_error
77
+ expect(@net_sftp_session).to receive(:remove!).and_raise("Some error")
78
+ expect{ euromail.remove!('2') }.to raise_error("Some error")
68
79
  end
69
80
  end
70
81
 
71
82
  describe "#filename" do
72
83
  it "generates a string with application, customer and the given identifier" do
73
- euromail.filename('123').should eql('./moves_nedap_123.pdf')
84
+ expect(euromail.filename('123')).to eql('./moves_nedap_123.pdf')
74
85
  end
75
86
 
76
87
  it "requires a non empty identifier" do
77
- expect{ euromail.filename('') }.to raise_error
78
- expect{ euromail.filename(nil) }.to raise_error
88
+ expect{ euromail.filename('') }.to raise_error("An identifier is required")
89
+ expect{ euromail.filename(nil) }.to raise_error("An identifier is required")
79
90
  end
80
91
  end
81
92
 
@@ -17,37 +17,39 @@ describe Euromail::SFTPService do
17
17
  end
18
18
 
19
19
  it "the current mode is test" do
20
- euromail.current_mode.should eql :test
20
+ expect(euromail.current_mode).to eql :test
21
21
  end
22
22
 
23
23
  describe "#upload" do
24
24
  it "does not upload anything" do
25
- @file_hander.should_not receive(:write)
25
+ expect(@file_hander).not_to receive(:write)
26
+ euromail.upload!('some-client-code', '1')
26
27
  end
27
28
 
28
29
  it "stores uploaded filenames" do
29
- euromail.uploaded_files.should == []
30
+ expect(euromail.uploaded_files).to eql([])
30
31
  euromail.upload!('some-client-code', '1')
31
- euromail.uploaded_files.should == [euromail.filename('1')]
32
+ expect(euromail.uploaded_files).to eql([euromail.filename('1')])
32
33
  end
33
34
  end
34
35
 
35
36
  describe "#remove" do
36
37
  it "does not remove anything" do
37
- @net_sftp_session.should_not receive(:remove!)
38
+ expect(@net_sftp_session).not_to receive(:remove!)
39
+ euromail.remove!('2')
38
40
  end
39
41
 
40
42
  it "stores deleted filenames" do
41
- euromail.removed_files.should == []
43
+ expect(euromail.removed_files).to eql([])
42
44
  euromail.remove!('2')
43
- euromail.removed_files.should == [euromail.filename('2')]
45
+ expect(euromail.removed_files).to eql([euromail.filename('2')])
44
46
  end
45
47
  end
46
48
 
47
49
  describe "#connect" do
48
50
  it "only calls the block" do
49
- Net::SFTP.should_not receive(:start)
50
- $stdout.should_not receive(:puts)
51
+ expect(Net::SFTP).not_to receive(:start)
52
+ expect($stdout).not_to receive(:puts)
51
53
  euromail.connect {}
52
54
  end
53
55
  end
@@ -3,18 +3,13 @@ module SFTPMock
3
3
  @net_sftp_session = double("Net::SFTP::Session")
4
4
  @string_io = double("StringIO")
5
5
 
6
- @file_hander.stub(:write) do |data|
7
- end
8
-
9
- @net_sftp_session.stub(:remove!) do |filename|
10
- end
11
-
12
- @net_sftp_session.stub(:upload!) do |filename|
13
- end
14
-
15
- StringIO.stub(:new).and_return(@string_io)
6
+ RSpec::Mocks.configuration.allow_message_expectations_on_nil
7
+ allow(@file_hander).to receive(:write)
8
+ allow(@net_sftp_session).to receive(:remove!)
9
+ allow(@net_sftp_session).to receive(:upload!)
10
+ allow(StringIO).to receive(:new).and_return(@string_io)
16
11
 
17
- Net::SFTP.stub(:start) do |host, username, password_hash, &block|
12
+ allow(Net::SFTP).to receive(:start) do |host, username, password_hash, &block|
18
13
  block.call(@net_sftp_session) if block
19
14
  end
20
15
  end
@@ -10,3 +10,5 @@ if ENV["COVERAGE"]
10
10
  add_filter "/spec/"
11
11
  end
12
12
  end
13
+
14
+ RSpec::Mocks.configuration.allow_message_expectations_on_nil = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: euromail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Teijgeler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-29 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-sftp
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  requirements: []
63
63
  rubyforge_project:
64
- rubygems_version: 2.2.2
64
+ rubygems_version: 2.6.14
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Gem to upload pdf data to an SFTP server