fake_ftp 0.1.1 → 0.2.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: 50a4678ec926f8b3ac68aa2db5670987c7c19558
4
- data.tar.gz: caf6eef42de1e306f19860b56265b8e64ced3040
3
+ metadata.gz: 16d22a49aeec88b087647080ff78af2cba62258f
4
+ data.tar.gz: 1fc101ff74542713e759abd3f7e96a223c7ed4ec
5
5
  SHA512:
6
- metadata.gz: 70a2926c93a0aff84dc95d52ea0312809bac104dd5d885eeac968932c5b82336d98115d0770ff20db0ad58efce8df62c55bc55376c2991bd9db12ff7680b4018
7
- data.tar.gz: d7b0cd6eb3d31c651aab69cca842bbb6f6da82e7487184e2dea56d75c4aa80e5cb641e31146776873ad0d1b574e0c0960ed84750755dcd8e68f172439aea623d
6
+ metadata.gz: a00eb184ceb029f516e92d8d0b01438156565f5ec9fd09ee3746b4755440f25d64d2dbe47533f00a88d2fec3f6b870d4cb67c3703a2a6111e2b030df98646d84
7
+ data.tar.gz: a27f8e3aa33522b31b04fc6cd1cf2cba529f5fba9f8b516e8c916741a7b82e71993f658b4d994feb6db8707d0883a8635a5903d02cf357fcae3d6aa0404b8fe7
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ pkg/*
5
5
  .DS_Store
6
6
  .rbenv-version
7
7
  .rbenv-gemsets
8
+ /Gemfile.lock
@@ -1,5 +1,8 @@
1
1
  language: ruby
2
+ sudo: false
3
+ dist: trusty
4
+ cache: bundler
2
5
  rvm:
3
- - 2.0.0
4
- - 1.9.3
5
- - 1.8.7
6
+ - 2.4.1
7
+ - 2.3.4
8
+ - 2.2.7
@@ -17,3 +17,5 @@ Contributors
17
17
  * Puneet Goyal
18
18
  * Steve Thompson
19
19
  * Thomas Sonntag
20
+ * runongirlrunon
21
+ * Dan Buch
data/Gemfile CHANGED
@@ -4,9 +4,9 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem "rspec", '>2'
8
- gem "rake", '>=0.8.7'
7
+ gem "rspec", '~> 2.14.0'
8
+ gem "rake", '~> 0.9.2.2'
9
9
 
10
- gem "guard-rspec"
11
- gem 'pry-nav'
10
+ gem "guard-rspec", '~> 0.6.0'
11
+ gem 'pry-nav', '~> 0.2.3'
12
12
  end
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  FakeFtp
2
2
  =======
3
3
 
4
- [![Build status](https://secure.travis-ci.org/livinginthepast/fake_ftp.png)](http://travis-ci.org/livinginthepast/fake_ftp)
4
+ [![Build status](https://secure.travis-ci.org/livinginthepast/fake_ftp.svg)](http://travis-ci.org/livinginthepast/fake_ftp)
5
5
 
6
6
  This is a gem that allows you to test FTP implementations in ruby. It is
7
7
  a minimal single-client FTP server that can be bound to any arbitrary
@@ -22,6 +22,7 @@ module FakeFtp
22
22
  port
23
23
  pwd
24
24
  quit
25
+ size
25
26
  stor
26
27
  retr
27
28
  rnfr
@@ -146,23 +147,14 @@ module FakeFtp
146
147
  end
147
148
 
148
149
  def _list(*args)
149
- wildcards = []
150
- args.each do |arg|
151
- next unless arg.include? '*'
152
- wildcards << arg.gsub('*', '.*')
153
- end
154
-
155
150
  respond_with('425 Ain\'t no data port!') && return if active? && @active_connection.nil?
156
151
 
157
152
  respond_with('150 Listing status ok, about to open data connection')
158
153
  data_client = active? ? @active_connection : @data_server.accept
159
154
 
160
- files = @files
161
- if not wildcards.empty?
162
- files = files.select do |f|
163
- wildcards.any? { |wildcard| f.name =~ /#{wildcard}/ }
164
- end
165
- end
155
+ wildcards = build_wildcards(args)
156
+ files = matching_files(@files, wildcards)
157
+
166
158
  files = files.map do |f|
167
159
  "-rw-r--r--\t1\towner\tgroup\t#{f.bytes}\t#{f.created.strftime('%b %d %H:%M')}\t#{f.name}\n"
168
160
  end
@@ -187,7 +179,14 @@ module FakeFtp
187
179
  respond_with('150 Listing status ok, about to open data connection')
188
180
  data_client = active? ? @active_connection : @data_server.accept
189
181
 
190
- data_client.write(files.join("\n"))
182
+ wildcards = build_wildcards(args)
183
+ files = matching_files(@files, wildcards)
184
+
185
+ files = files.map do |file|
186
+ "#{file.name}\n"
187
+ end
188
+
189
+ data_client.write(files.join)
191
190
  data_client.close
192
191
  @active_connection = nil
193
192
 
@@ -271,6 +270,11 @@ module FakeFtp
271
270
  end
272
271
  end
273
272
 
273
+ def _size(filename)
274
+ file_size = file(filename).bytes
275
+ respond_with("213 #{file_size}")
276
+ end
277
+
274
278
  def _stor(filename = '')
275
279
  respond_with('425 Ain\'t no data port!') && return if active? && @active_connection.nil?
276
280
 
@@ -336,5 +340,24 @@ module FakeFtp
336
340
 
337
341
  return false
338
342
  end
343
+
344
+ def build_wildcards(args)
345
+ wildcards = []
346
+ args.each do |arg|
347
+ next unless arg.include? '*'
348
+ wildcards << arg.gsub('*', '.*')
349
+ end
350
+ wildcards
351
+ end
352
+
353
+ def matching_files(files, wildcards)
354
+ if not wildcards.empty?
355
+ files.select do |f|
356
+ wildcards.any? { |wildcard| f.name =~ /#{wildcard}/ }
357
+ end
358
+ else
359
+ files
360
+ end
361
+ end
339
362
  end
340
363
  end
@@ -1,3 +1,3 @@
1
1
  module FakeFtp
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -317,7 +317,23 @@ describe FakeFtp::Server, 'commands' do
317
317
  expect(client.gets).to eql("150 Listing status ok, about to open data connection\r\n")
318
318
  data = data_client.read(1024)
319
319
  data_client.close
320
- expect(data).to eql("some_file\nanother_file")
320
+ expect(data).to eql("some_file\nanother_file\n")
321
+ expect(client.gets).to eql("226 List information transferred\r\n")
322
+ end
323
+
324
+ it "accepts an NLST command with wildcard arguments" do
325
+ files = ['test.jpg', 'test.txt', 'test2.jpg']
326
+ files.each do |file|
327
+ server.add_file(file, '1234567890')
328
+ end
329
+
330
+ client.puts "NLST *.jpg"
331
+
332
+ expect(client.gets).to eql("150 Listing status ok, about to open data connection\r\n")
333
+ data = data_client.read(1024)
334
+ data_client.close
335
+
336
+ expect(data).to eql("test.jpg\ntest2.jpg\n")
321
337
  expect(client.gets).to eql("226 List information transferred\r\n")
322
338
  end
323
339
 
@@ -459,7 +475,7 @@ describe FakeFtp::Server, 'commands' do
459
475
  data = @server_client.read(1024)
460
476
  @server_client.close
461
477
 
462
- expect(data).to eql("some_file\nanother_file")
478
+ expect(data).to eql("some_file\nanother_file\n")
463
479
  expect(client.gets).to eql("226 List information transferred\r\n")
464
480
  end
465
481
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_ftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin Shield
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-18 00:00:00.000000000 Z
12
+ date: 2017-07-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Testing FTP? Use this!
15
15
  email:
@@ -23,7 +23,6 @@ files:
23
23
  - ".travis.yml"
24
24
  - CONTRIBUTORS.md
25
25
  - Gemfile
26
- - Gemfile.lock
27
26
  - Guardfile
28
27
  - README.md
29
28
  - Rakefile
@@ -59,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
58
  version: 1.3.6
60
59
  requirements: []
61
60
  rubyforge_project:
62
- rubygems_version: 2.2.0
61
+ rubygems_version: 2.6.11
63
62
  signing_key:
64
63
  specification_version: 4
65
64
  summary: Creates a fake FTP server for use in testing
@@ -71,4 +70,3 @@ test_files:
71
70
  - spec/models/fake_ftp/file_spec.rb
72
71
  - spec/models/fake_ftp/server_spec.rb
73
72
  - spec/spec_helper.rb
74
- has_rdoc:
@@ -1,44 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- fake_ftp (0.1.0)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- coderay (1.0.9)
10
- diff-lcs (1.2.4)
11
- ffi (1.0.11)
12
- guard (1.0.1)
13
- ffi (>= 0.5.0)
14
- thor (~> 0.14.6)
15
- guard-rspec (0.6.0)
16
- guard (>= 0.10.0)
17
- method_source (0.8.2)
18
- pry (0.9.12.2)
19
- coderay (~> 1.0.5)
20
- method_source (~> 0.8)
21
- slop (~> 3.4)
22
- pry-nav (0.2.3)
23
- pry (~> 0.9.10)
24
- rake (0.9.2.2)
25
- rspec (2.14.1)
26
- rspec-core (~> 2.14.0)
27
- rspec-expectations (~> 2.14.0)
28
- rspec-mocks (~> 2.14.0)
29
- rspec-core (2.14.5)
30
- rspec-expectations (2.14.3)
31
- diff-lcs (>= 1.1.3, < 2.0)
32
- rspec-mocks (2.14.3)
33
- slop (3.4.6)
34
- thor (0.14.6)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- fake_ftp!
41
- guard-rspec
42
- pry-nav
43
- rake (>= 0.8.7)
44
- rspec (> 2)