testftpd 0.1.4 → 0.1.5

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/testftpd.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative 'testftpd/file_system_provider'
2
2
  require_relative 'testftpd/server'
3
+ require_relative 'testftpd/server_builder'
3
4
 
4
5
  module TestFtpd
5
6
 
@@ -0,0 +1,32 @@
1
+ require_relative 'server'
2
+
3
+ module TestFtpd
4
+
5
+ class ServerBuilder
6
+
7
+ DEFAULT_PORT_RANGE = (21212..21232).to_a
8
+
9
+ def self.build(config, ports)
10
+ new.build(config, ports)
11
+ end
12
+
13
+ def build(config, ports = DEFAULT_PORT_RANGE)
14
+ @server = nil
15
+ ports.each do |port|
16
+ attempt_to_build config.merge(port: port)
17
+ break if @server
18
+ end
19
+ @server
20
+ end
21
+
22
+ private
23
+
24
+ def attempt_to_build(options)
25
+ @server = Server.new(options)
26
+ rescue Errno::EADDRINUSE
27
+ nil
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -1,3 +1,3 @@
1
1
  module TestFtpd
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -17,7 +17,6 @@ describe TestFtpd do
17
17
 
18
18
  before do
19
19
  subject.start
20
- copy_ftproot(ftp_root)
21
20
  end
22
21
 
23
22
  after do
@@ -27,6 +26,7 @@ describe TestFtpd do
27
26
 
28
27
  context 'before authenticating' do
29
28
  before :each do
29
+ copy_ftproot(ftp_root)
30
30
  @ftp = Net::FTP.new
31
31
  @ftp.connect('127.0.0.1', ftp_port)
32
32
  end
@@ -42,6 +42,7 @@ describe TestFtpd do
42
42
 
43
43
  context 'after authenticating' do
44
44
  before :each do
45
+ copy_ftproot(ftp_root)
45
46
  @ftp = Net::FTP.new
46
47
  @ftp.connect('127.0.0.1', ftp_port)
47
48
  @ftp.login('username', 'password')
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ require 'testftpd'
4
+
5
+ describe TestFtpd::ServerBuilder do
6
+
7
+ let(:ftp_ports) { (21212..21232).to_a }
8
+ let(:ftp_options) { { root_dir: APP_PATH } }
9
+
10
+ subject { TestFtpd::ServerBuilder }
11
+
12
+ describe '#build' do
13
+ context 'when a port is in use' do
14
+ before(:each) do
15
+ @dummy_server = TCPServer.new('', ftp_ports.first)
16
+ end
17
+ after(:each) do
18
+ @dummy_server.close
19
+ @server.shutdown
20
+ end
21
+
22
+ it 'builds a server on the next available port' do
23
+ @server = subject.build(ftp_options, ftp_ports)
24
+ expect( @server ).to be_an_instance_of TestFtpd::Server
25
+ expect( @server.config[:port] ).to eq ftp_ports[1]
26
+ end
27
+ end
28
+ end
29
+
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testftpd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
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-03-15 00:00:00.000000000 Z
12
+ date: 2013-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -86,6 +86,7 @@ extra_rdoc_files: []
86
86
  files:
87
87
  - lib/testftpd/file_system_provider.rb
88
88
  - lib/testftpd/server.rb
89
+ - lib/testftpd/server_builder.rb
89
90
  - lib/testftpd/version.rb
90
91
  - lib/testftpd.rb
91
92
  - vendor/dyn-ftp-serv/CHANGELOG
@@ -101,6 +102,7 @@ files:
101
102
  - spec/fixtures/test_file_to_upload
102
103
  - spec/integration/test_ftp_spec.rb
103
104
  - spec/spec_helper.rb
105
+ - spec/unit/testftpd/server_builder_spec.rb
104
106
  - spec/unit/testftpd/server_spec.rb
105
107
  homepage: https://github.com/christian-schulze/testftpd
106
108
  licenses: []
@@ -135,4 +137,5 @@ test_files:
135
137
  - spec/fixtures/test_file_to_upload
136
138
  - spec/integration/test_ftp_spec.rb
137
139
  - spec/spec_helper.rb
140
+ - spec/unit/testftpd/server_builder_spec.rb
138
141
  - spec/unit/testftpd/server_spec.rb