fake_ftp 0.0.6 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fake_ftp (0.0.5)
4
+ fake_ftp (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -29,6 +29,10 @@ module FakeFtp
29
29
  @files.detect { |file| file.name == name }
30
30
  end
31
31
 
32
+ def reset
33
+ @files.clear
34
+ end
35
+
32
36
  def add_file(filename, data)
33
37
  @files << FakeFtp::File.new(::File.basename(filename.to_s), data, @mode)
34
38
  end
@@ -91,6 +95,11 @@ module FakeFtp
91
95
  end
92
96
  end
93
97
 
98
+ ## FTP commands
99
+ #
100
+ # Methods are prefixed with an underscore to avoid conflicts with internal server
101
+ # methods. Methods map 1:1 to FTP command words.
102
+ #
94
103
  def _acct(*args)
95
104
  '230 WHATEVER!'
96
105
  end
@@ -100,6 +109,34 @@ module FakeFtp
100
109
  end
101
110
  alias :_cdup :_cwd
102
111
 
112
+ def _list(*args)
113
+ respond_with('425 Ain\'t no data port!') && return if active? && @active_connection.nil?
114
+
115
+ respond_with('150 Listing status ok, about to open data connection')
116
+ data_client = active? ? @active_connection : @data_server.accept
117
+
118
+ data_client.write(@files.map do |f|
119
+ "-rw-r--r--\t1\towner\tgroup\t#{f.bytes}\t#{f.created.strftime('%b %d %H:%M')}\t#{f.name}"
120
+ end.join("\n"))
121
+ data_client.close
122
+ @active_connection = nil
123
+
124
+ '226 List information transferred'
125
+ end
126
+
127
+ def _nlst(*args)
128
+ respond_with('425 Ain\'t no data port!') && return if active? && @active_connection.nil?
129
+
130
+ respond_with('150 Listing status ok, about to open data connection')
131
+ data_client = active? ? @active_connection : @data_server.accept
132
+
133
+ data_client.write(files.join("\n"))
134
+ data_client.close
135
+ @active_connection = nil
136
+
137
+ '226 List information transferred'
138
+ end
139
+
103
140
  def _pass(*args)
104
141
  '230 logged in'
105
142
  end
@@ -137,21 +174,6 @@ module FakeFtp
137
174
  @client = nil
138
175
  end
139
176
 
140
- def _stor(filename = '')
141
- respond_with('425 Ain\'t no data port!') && return if active? && @active_connection.nil?
142
-
143
- respond_with('125 Do it!')
144
- data_client = active? ? @active_connection : @data_server.accept
145
-
146
- data = data_client.recv(1024)
147
- file = FakeFtp::File.new(::File.basename(filename.to_s), data, @mode)
148
- @files << file
149
-
150
- data_client.close
151
- @active_connection = nil
152
- '226 Did it!'
153
- end
154
-
155
177
  def _retr(filename = '')
156
178
  respond_with('501 No filename given') if filename.empty?
157
179
 
@@ -170,32 +192,19 @@ module FakeFtp
170
192
  '226 File transferred'
171
193
  end
172
194
 
173
- def _list(*args)
195
+ def _stor(filename = '')
174
196
  respond_with('425 Ain\'t no data port!') && return if active? && @active_connection.nil?
175
197
 
176
- respond_with('150 Listing status ok, about to open data connection')
198
+ respond_with('125 Do it!')
177
199
  data_client = active? ? @active_connection : @data_server.accept
178
200
 
179
- data_client.write(@files.map do |f|
180
- "-rw-r--r--\t1\towner\tgroup\t#{f.bytes}\t#{f.created.strftime('%b %d %H:%M')}\t#{f.name}"
181
- end.join("\n"))
182
- data_client.close
183
- @active_connection = nil
184
-
185
- '226 List information transferred'
186
- end
187
-
188
- def _nlst(*args)
189
- respond_with('425 Ain\'t no data port!') && return if active? && @active_connection.nil?
190
-
191
- respond_with('150 Listing status ok, about to open data connection')
192
- data_client = active? ? @active_connection : @data_server.accept
201
+ data = data_client.recv(1024)
202
+ file = FakeFtp::File.new(::File.basename(filename.to_s), data, @mode)
203
+ @files << file
193
204
 
194
- data_client.write(files.join("\n"))
195
205
  data_client.close
196
206
  @active_connection = nil
197
-
198
- '226 List information transferred'
207
+ '226 Did it!'
199
208
  end
200
209
 
201
210
  def _type(type = 'A')
@@ -1,3 +1,3 @@
1
1
  module FakeFtp
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -76,6 +76,11 @@ describe FakeFtp::Server do
76
76
  it "can be accessed with :file" do
77
77
  @server.file('filename').should == @file
78
78
  end
79
+
80
+ it "can reset files" do
81
+ @server.reset
82
+ @server.files.should == []
83
+ end
79
84
  end
80
85
 
81
86
  context 'socket' 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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Colin Shield
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-12 00:00:00 -07:00
19
+ date: 2011-10-07 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency