fake_ftp 0.0.3 → 0.0.4
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/Gemfile.lock +1 -1
- data/README.markdown +24 -3
- data/lib/fake_ftp/file.rb +11 -1
- data/lib/fake_ftp/server.rb +1 -1
- data/lib/fake_ftp/version.rb +1 -1
- data/spec/models/fake_ftp/file_spec.rb +54 -0
- data/spec/models/fake_ftp/server_spec.rb +4 -0
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -18,6 +18,8 @@ their intended destination rather than testing how our code does so.
|
|
18
18
|
Usage
|
19
19
|
-----
|
20
20
|
|
21
|
+
To test passive upload:
|
22
|
+
|
21
23
|
require 'fake_ftp'
|
22
24
|
require 'net/ftp'
|
23
25
|
|
@@ -35,13 +37,32 @@ Usage
|
|
35
37
|
|
36
38
|
server.files.should include('some_file.txt')
|
37
39
|
server.file('some_file.txt').bytes.should == 25
|
40
|
+
server.file('some_file.txt').should be_passive
|
41
|
+
server.file('some_file.txt').should_not be_active
|
38
42
|
|
39
43
|
server.stop
|
40
44
|
|
41
|
-
|
42
|
-
|
45
|
+
To test active upload:
|
46
|
+
|
47
|
+
server = FakeFtp::Server.new(21212)
|
48
|
+
## 21212 is the control port, which is used by FTP for the primary connection
|
49
|
+
## 21213 is the data port, used in FTP passive mode to send file contents
|
50
|
+
server.start
|
51
|
+
|
52
|
+
ftp = Net::FTP.new
|
53
|
+
ftp.connect('127.0.0.1', 21212)
|
54
|
+
ftp.login('user', 'password')
|
55
|
+
ftp.passive = false
|
56
|
+
ftp.put('some_file.txt')
|
57
|
+
ftp.close
|
58
|
+
|
59
|
+
server.files.should include('some_file.txt')
|
60
|
+
server.file('some_file.txt').bytes.should == 25
|
61
|
+
server.file('some_file.txt').should be_active
|
62
|
+
server.file('some_file.txt').should_not be_passive
|
63
|
+
|
64
|
+
server.stop
|
43
65
|
|
44
|
-
* files should track if uploaded via active or passive
|
45
66
|
|
46
67
|
References
|
47
68
|
----------
|
data/lib/fake_ftp/file.rb
CHANGED
@@ -1,10 +1,20 @@
|
|
1
1
|
module FakeFtp
|
2
2
|
class File
|
3
3
|
attr_accessor :bytes, :name
|
4
|
+
attr_writer :type
|
4
5
|
|
5
|
-
def initialize(name = nil, bytes = nil)
|
6
|
+
def initialize(name = nil, bytes = nil, type = nil)
|
6
7
|
self.name = name
|
7
8
|
self.bytes = bytes
|
9
|
+
self.type = type
|
10
|
+
end
|
11
|
+
|
12
|
+
def passive?
|
13
|
+
@type == :passive
|
14
|
+
end
|
15
|
+
|
16
|
+
def active?
|
17
|
+
@type == :active
|
8
18
|
end
|
9
19
|
end
|
10
20
|
end
|
data/lib/fake_ftp/server.rb
CHANGED
@@ -145,7 +145,7 @@ module FakeFtp
|
|
145
145
|
end
|
146
146
|
|
147
147
|
data = data_client.recv(1024)
|
148
|
-
file = FakeFtp::File.new(::File.basename(filename.to_s), data.length)
|
148
|
+
file = FakeFtp::File.new(::File.basename(filename.to_s), data.length, @mode)
|
149
149
|
@files << file
|
150
150
|
|
151
151
|
data_client.close
|
data/lib/fake_ftp/version.rb
CHANGED
@@ -18,10 +18,64 @@ describe FakeFtp::File do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'setup' do
|
21
|
+
it "can be initialized without attributes" do
|
22
|
+
file = FakeFtp::File.new
|
23
|
+
file.name.should be_nil
|
24
|
+
file.bytes.should be_nil
|
25
|
+
file.instance_variable_get(:@type).should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can be initialized with name" do
|
29
|
+
file = FakeFtp::File.new('filename')
|
30
|
+
file.name.should == 'filename'
|
31
|
+
file.bytes.should be_nil
|
32
|
+
file.instance_variable_get(:@type).should be_nil
|
33
|
+
end
|
34
|
+
|
21
35
|
it "can be initialized with name and bytes" do
|
22
36
|
file = FakeFtp::File.new('filename', 104)
|
23
37
|
file.name.should == 'filename'
|
24
38
|
file.bytes.should == 104
|
39
|
+
file.instance_variable_get(:@type).should be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can be initialized with name and bytes and type" do
|
43
|
+
file = FakeFtp::File.new('filename', 104, :passive)
|
44
|
+
file.name.should == 'filename'
|
45
|
+
file.bytes.should == 104
|
46
|
+
file.instance_variable_get(:@type).should == :passive
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#passive?' do
|
51
|
+
before :each do
|
52
|
+
@file = FakeFtp::File.new
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be true if type is :passive" do
|
56
|
+
@file.type = :passive
|
57
|
+
@file.passive?.should be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be false if type is :active" do
|
61
|
+
@file.type = :active
|
62
|
+
@file.passive?.should be_false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#active?' do
|
67
|
+
before :each do
|
68
|
+
@file = FakeFtp::File.new
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should be true if type is :active" do
|
72
|
+
@file.type = :active
|
73
|
+
@file.active?.should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be false if type is :passive" do
|
77
|
+
@file.type = :passive
|
78
|
+
@file.active?.should be_false
|
25
79
|
end
|
26
80
|
end
|
27
81
|
end
|
@@ -389,6 +389,8 @@ describe FakeFtp::Server do
|
|
389
389
|
|
390
390
|
@server.files.should include('text_file.txt')
|
391
391
|
@server.file('text_file.txt').bytes.should == 20
|
392
|
+
@server.file('text_file.txt').should be_passive
|
393
|
+
@server.file('text_file.txt').should_not be_active
|
392
394
|
end
|
393
395
|
|
394
396
|
it "should put files using active" do
|
@@ -400,6 +402,8 @@ describe FakeFtp::Server do
|
|
400
402
|
|
401
403
|
@server.files.should include('text_file.txt')
|
402
404
|
@server.file('text_file.txt').bytes.should == 20
|
405
|
+
@server.file('text_file.txt').should_not be_passive
|
406
|
+
@server.file('text_file.txt').should be_active
|
403
407
|
end
|
404
408
|
|
405
409
|
xit "should disconnect clients on close" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_ftp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Colin Shield
|