fake_ftp 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +16 -0
  3. data/.gitignore +1 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +27 -0
  6. data/.rubocop_todo.yml +7 -0
  7. data/.simplecov +6 -0
  8. data/.travis.yml +27 -2
  9. data/CHANGELOG.md +136 -0
  10. data/Gemfile +9 -7
  11. data/Guardfile +5 -4
  12. data/LICENSE.md +20 -0
  13. data/README.md +30 -63
  14. data/Rakefile +12 -7
  15. data/fake_ftp.gemspec +16 -17
  16. data/lib/fake_ftp.rb +3 -2
  17. data/lib/fake_ftp/file.rb +11 -5
  18. data/lib/fake_ftp/server.rb +138 -261
  19. data/lib/fake_ftp/server_commands.rb +6 -0
  20. data/lib/fake_ftp/server_commands/acct.rb +11 -0
  21. data/lib/fake_ftp/server_commands/cdup.rb +11 -0
  22. data/lib/fake_ftp/server_commands/cwd.rb +13 -0
  23. data/lib/fake_ftp/server_commands/dele.rb +25 -0
  24. data/lib/fake_ftp/server_commands/list.rb +39 -0
  25. data/lib/fake_ftp/server_commands/mdtm.rb +17 -0
  26. data/lib/fake_ftp/server_commands/mkd.rb +11 -0
  27. data/lib/fake_ftp/server_commands/nlst.rb +32 -0
  28. data/lib/fake_ftp/server_commands/pass.rb +11 -0
  29. data/lib/fake_ftp/server_commands/pasv.rb +15 -0
  30. data/lib/fake_ftp/server_commands/port.rb +23 -0
  31. data/lib/fake_ftp/server_commands/pwd.rb +11 -0
  32. data/lib/fake_ftp/server_commands/quit.rb +13 -0
  33. data/lib/fake_ftp/server_commands/retr.rb +32 -0
  34. data/lib/fake_ftp/server_commands/rnfr.rb +18 -0
  35. data/lib/fake_ftp/server_commands/rnto.rb +22 -0
  36. data/lib/fake_ftp/server_commands/site.rb +11 -0
  37. data/lib/fake_ftp/server_commands/size.rb +11 -0
  38. data/lib/fake_ftp/server_commands/stor.rb +30 -0
  39. data/lib/fake_ftp/server_commands/type.rb +18 -0
  40. data/lib/fake_ftp/server_commands/user.rb +12 -0
  41. data/lib/fake_ftp/server_commands/wat.rb +33 -0
  42. data/lib/fake_ftp/version.rb +3 -1
  43. data/spec/functional/server_spec.rb +459 -358
  44. data/spec/integration/server_spec.rb +39 -29
  45. data/spec/models/fake_ftp/file_spec.rb +22 -21
  46. data/spec/models/fake_ftp/server_spec.rb +33 -32
  47. data/spec/spec_helper.rb +98 -14
  48. metadata +32 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16d22a49aeec88b087647080ff78af2cba62258f
4
- data.tar.gz: 1fc101ff74542713e759abd3f7e96a223c7ed4ec
3
+ metadata.gz: 7a8165d49d247b14c5a9c6dddde8ebf348b54a97
4
+ data.tar.gz: f57a69068555bf2911e54008695a7a72b1d51baf
5
5
  SHA512:
6
- metadata.gz: a00eb184ceb029f516e92d8d0b01438156565f5ec9fd09ee3746b4755440f25d64d2dbe47533f00a88d2fec3f6b870d4cb67c3703a2a6111e2b030df98646d84
7
- data.tar.gz: a27f8e3aa33522b31b04fc6cd1cf2cba529f5fba9f8b516e8c916741a7b82e71993f658b4d994feb6db8707d0883a8635a5903d02cf357fcae3d6aa0404b8fe7
6
+ metadata.gz: 357a8a7b06d3c6eb7ece24592724e30357859299ca3718cd42a54e90da48b69b95f320010d7c773527fc0dd1dc402ce14a0ca58d97c3fd35f80f0c81e4f44e13
7
+ data.tar.gz: e539dfca9312bd701c72e0e71ae6e3b6a08e7bf6abcaab69da55047c1cbf86f6db5c768c44f68fc9600d34913643d670524afa8ecfc409e0d9c74e39030600be
@@ -0,0 +1,16 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ fixme:
9
+ enabled: true
10
+ rubocop:
11
+ enabled: false
12
+ ratings:
13
+ paths:
14
+ - "**.rb"
15
+ exclude_paths:
16
+ - spec/
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ pkg/*
6
6
  .rbenv-version
7
7
  .rbenv-gemsets
8
8
  /Gemfile.lock
9
+ /coverage/
data/.rspec CHANGED
@@ -1,2 +1,4 @@
1
1
  --color
2
2
  --format documentation
3
+ --order rand
4
+ --require spec_helper
@@ -0,0 +1,27 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: '2.4'
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Metrics/AbcSize:
10
+ Max: 40
11
+
12
+ Metrics/CyclomaticComplexity:
13
+ Max: 15
14
+
15
+ Metrics/MethodLength:
16
+ Max: 45
17
+
18
+ Metrics/PerceivedComplexity:
19
+ Max: 15
20
+
21
+ Metrics/BlockLength:
22
+ Exclude:
23
+ - 'spec/**/*'
24
+ Max: 40
25
+
26
+ Metrics/ClassLength:
27
+ Max: 200
@@ -0,0 +1,7 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-08-01 12:55:33 -0400 using RuboCop version 0.49.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
@@ -0,0 +1,6 @@
1
+ if ENV['COVERAGE'] == '1'
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ minimum_coverage 90
5
+ end
6
+ end
@@ -1,8 +1,33 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  dist: trusty
4
- cache: bundler
4
+ cache:
5
+ bundler: true
6
+ directories:
7
+ - ~/.local/bin
5
8
  rvm:
6
9
  - 2.4.1
7
10
  - 2.3.4
8
- - 2.2.7
11
+ env:
12
+ matrix:
13
+ - COVERAGE=0 FUNCTIONAL_SPECS=0 INTEGRATION_SPECS=0
14
+ - COVERAGE=1 FUNCTIONAL_SPECS=1 INTEGRATION_SPECS=1
15
+ global:
16
+ - PATH="$HOME/.local/bin:$PATH"
17
+ before_install:
18
+ - if ! cc-test-reporter --version; then
19
+ mkdir -p ~/.local/bin;
20
+ curl -sSL
21
+ -o ~/.local/bin/cc-test-reporter
22
+ https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64;
23
+ chmod +x ~/.local/bin/cc-test-reporter;
24
+ fi
25
+ - cc-test-reporter before-build
26
+ after_script:
27
+ - if [[ "${TRAVIS_PULL_REQUEST}" == "false" &&
28
+ "${COVERAGE}" == "1" &&
29
+ "${FUNCTIONAL_SPECS}" == "1" &&
30
+ "${INTEGRATION_SPECS}" == "1" &&
31
+ "${TRAVIS_RUBY_VERSION}" == "2.4.1" ]]; then
32
+ cc-test-reporter after-build --exit-code "${TRAVIS_TEST_RESULT}";
33
+ fi
@@ -0,0 +1,136 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+
11
+ ### Changed
12
+
13
+ ### Deprecated
14
+
15
+ ### Removed
16
+
17
+ ### Fixed
18
+
19
+ ### Security
20
+
21
+ ## [0.3.0] - 2017-08-01
22
+ ### Added
23
+ - integration with Code Climate + simplecov
24
+ - RuboCop with auto-fixes
25
+ - this changelog
26
+ - server: more debugging
27
+
28
+ ### Changed
29
+ - server:
30
+ - command dispatch via class
31
+ - store files as a set
32
+
33
+ ### Removed
34
+ - tests: running against ruby 2.2.7
35
+
36
+ ## [0.2.0] - 2017-07-26
37
+ ### Added
38
+ - server: `size` command implementation
39
+
40
+ ### Changed
41
+ - tests: updated ruby versions tested via Travis CI
42
+
43
+ ## [0.1.1] - 2014-04-17
44
+ ### Added
45
+ - documentation: more, plus a contributors doc
46
+
47
+ ### Changed
48
+ - server:
49
+ - fail to initialize if control or passive ports are invalid
50
+ - reset port from initial server address
51
+
52
+ ## [0.1.0] - 2013-09-30
53
+ ### Added
54
+ - tests: integration with Travis CI
55
+ - documentation: GitHub-flavored markdown changes
56
+ - file: `last_modified_time`
57
+ - server:
58
+ - wildcard support in `list` command
59
+ - `mdtm` command implementation
60
+ - `rnfr` command implementation
61
+ - `rnto` command implementation
62
+ - `dele` command implementation
63
+ - `mkd` command implementation
64
+
65
+ ### Changed
66
+ - server: real implementation of `cwd` command
67
+
68
+ ## [0.0.9] - 2011-11-21
69
+ ### Changed
70
+ - server: initial respond code `220`
71
+
72
+ ## [0.0.8] - 2011-11-21
73
+ ### Changed
74
+ - server: detect running state via `TCPSocket` instead of `lsof`
75
+
76
+ ## [0.0.7] - 2011-10-07
77
+ ### Added
78
+ - server: `reset` command to clear stored files
79
+
80
+ ## [0.0.6] - 2011-06-12
81
+ ### Changed
82
+ - server: pass args to commands via splat
83
+
84
+ ## [0.0.5] - 2011-05-12
85
+ ### Added
86
+ - file: accessors for data and created fields
87
+ - server:
88
+ - `add_file` method for direct file addition
89
+ - `retr` command implementation
90
+ - `list` command implementation
91
+ - `nlst` command implementation
92
+
93
+ ## [0.0.4] - 2011-03-06
94
+ ### Added
95
+ - docs: show how to test active upload
96
+
97
+ ### Changed
98
+ - file: accept active/passive type at initialization
99
+
100
+ ## [0.0.3] - 2011-03-06
101
+ ### Added
102
+ - server:
103
+ - initial active mode implementation
104
+ - `port` command
105
+
106
+ ### Changed
107
+ - server:
108
+ - `stor` behavior depending on active/passive mode
109
+
110
+ ## [0.0.2] - 2011-03-05
111
+ ### Added
112
+ - file: initial implementation for in-memory store
113
+ - server:
114
+ - `#files` method for fetching all stored file names
115
+ - `#file` method for fetching rich file object by name
116
+
117
+ ### Changed
118
+ - server: use in-memory store instead of local scratch directory
119
+
120
+ ## 0.0.1 - 2011-02-28
121
+
122
+ ### Added
123
+ - initial release with basic usage and docs
124
+
125
+ [Unreleased]: https://github.com/livinginthepast/fake_ftp/compare/v0.2.0...HEAD
126
+ [0.2.0]: https://github.com/livinginthepast/fake_ftp/compare/v0.1.1...v0.2.0
127
+ [0.1.1]: https://github.com/livinginthepast/fake_ftp/compare/v0.1.0...v0.1.1
128
+ [0.1.0]: https://github.com/livinginthepast/fake_ftp/compare/v0.0.9...v0.1.0
129
+ [0.0.9]: https://github.com/livinginthepast/fake_ftp/compare/v0.0.8...v0.0.9
130
+ [0.0.8]: https://github.com/livinginthepast/fake_ftp/compare/v0.0.7...v0.0.8
131
+ [0.0.7]: https://github.com/livinginthepast/fake_ftp/compare/v0.0.6...v0.0.7
132
+ [0.0.6]: https://github.com/livinginthepast/fake_ftp/compare/v0.0.5...v0.0.6
133
+ [0.0.5]: https://github.com/livinginthepast/fake_ftp/compare/v0.0.4...v0.0.5
134
+ [0.0.4]: https://github.com/livinginthepast/fake_ftp/compare/v0.0.3...v0.0.4
135
+ [0.0.3]: https://github.com/livinginthepast/fake_ftp/compare/v0.0.2...v0.0.3
136
+ [0.0.2]: https://github.com/livinginthepast/fake_ftp/compare/v0.0.1...v0.0.2
data/Gemfile CHANGED
@@ -1,12 +1,14 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
2
4
 
3
- # Specify your gem's dependencies in fake_ftp.gemspec
4
5
  gemspec
5
6
 
6
7
  group :test do
7
- gem "rspec", '~> 2.14.0'
8
- gem "rake", '~> 0.9.2.2'
9
-
10
- gem "guard-rspec", '~> 0.6.0'
11
- gem 'pry-nav', '~> 0.2.3'
8
+ gem 'guard-rspec', '~> 4.7.3'
9
+ gem 'pry-nav', '~> 0.2.4'
10
+ gem 'rake', '~> 12.0.0'
11
+ gem 'rspec', '~> 3.6.0'
12
+ gem 'rubocop', '~> 0.49.1'
13
+ gem 'simplecov', '~> 0.14.1', require: false
12
14
  end
data/Guardfile CHANGED
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A sample Guardfile
2
4
  # More info at https://github.com/guard/guard#readme
3
5
 
4
- guard 'rspec', :version => 2 do
6
+ guard 'rspec', version: 2 do
5
7
  watch(%r{^spec/.+_spec\.rb$})
6
8
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
9
+ watch('spec/spec_helper.rb') { 'spec' }
10
+ watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
9
11
  end
10
-
@@ -0,0 +1,20 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2017 Eric Saxby
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,25 +1,21 @@
1
- FakeFtp
2
- =======
1
+ # FakeFtp
3
2
 
4
- [![Build status](https://secure.travis-ci.org/livinginthepast/fake_ftp.svg)](http://travis-ci.org/livinginthepast/fake_ftp)
5
-
6
- This is a gem that allows you to test FTP implementations in ruby. It is
7
- a minimal single-client FTP server that can be bound to any arbitrary
8
- port on localhost.
3
+ [![Build status](https://api.travis-ci.org/livinginthepast/fake_ftp.svg?branch=master)](http://travis-ci.org/livinginthepast/fake_ftp)
9
4
 
5
+ This is a gem that allows you to test FTP implementations in ruby. It is a
6
+ minimal single-client FTP server that can be bound to any arbitrary port on
7
+ localhost.
10
8
 
11
9
  ## Why?
12
10
 
13
- We want to ensure that our code works, in a way that is agnostic to the
11
+ We want to ensure that our code works, in a way that is agnostic to the
14
12
  implementation used (unlike with stubs or mocks).
15
13
 
16
-
17
14
  ## How
18
15
 
19
- FakeFtp is a simple FTP server that fakes out enough of the protocol to
20
- get us by, allowing us to test that files get to their intended destination
21
- rather than testing how our code does so.
22
-
16
+ FakeFtp is a simple FTP server that fakes out enough of the protocol to get us
17
+ by, allowing us to test that files get to their intended destination rather than
18
+ testing how our code does so.
23
19
 
24
20
  ## Usage
25
21
 
@@ -40,10 +36,10 @@ ftp.passive = true
40
36
  ftp.put('some_file.txt')
41
37
  ftp.close
42
38
 
43
- server.files.should include('some_file.txt')
44
- server.file('some_file.txt').bytes.should == 25
45
- server.file('some_file.txt').should be_passive
46
- server.file('some_file.txt').should_not be_active
39
+ expect(server.files).to include('some_file.txt')
40
+ expect(server.file('some_file.txt').bytes).to eq 25
41
+ expect(server.file('some_file.txt')).to be_passive
42
+ expect(server.file('some_file.txt')).not_not be_active
47
43
 
48
44
  server.stop
49
45
  ```
@@ -62,73 +58,44 @@ ftp.passive = false
62
58
  ftp.put('some_file.txt')
63
59
  ftp.close
64
60
 
65
- server.files.should include('some_file.txt')
66
- server.file('some_file.txt').bytes.should == 25
67
- server.file('some_file.txt').should be_active
68
- server.file('some_file.txt').should_not be_passive
61
+ expect(server.files).to include('some_file.txt')
62
+ expect(server.file('some_file.txt').bytes).to eq 25
63
+ expect(server.file('some_file.txt')).to be_active
64
+ expect(server.file('some_file.txt')).to_not be_passive
69
65
 
70
66
  server.stop
71
67
  ```
72
68
 
73
69
  Note that many FTP clients default to active, unless specified otherwise.
74
70
 
75
-
76
71
  ## Caveats
77
72
 
78
- This is *not* a real FTP server and should not be treated as one. The goal
79
- of this gem is not to create a thread-safe multi-client implementation.
80
- It is best used to unit test models that generate files and transfer
81
- them to an FTP server.
73
+ This is *not* a real FTP server and should not be treated as one. The goal of
74
+ this gem is not to create a thread-safe multi-client implementation. It is best
75
+ used to unit test code that generates files and transfers them to an FTP server.
82
76
 
83
77
  As such, there are some things that won't be accepted upstream from pull
84
78
  requests:
85
79
  * simultaneous multi-client code
86
- * support for long term file persistence
80
+ * persistence support
87
81
  * binding to arbitrary IPs
88
82
  * global state beyond that required to pass the minimum required to
89
83
  generate passing tests
90
84
 
91
-
92
85
  ## Recommendations for testing patterns
93
86
 
94
- *Separate configuration from code.* Do not hard code the IP address,
95
- FQDN or port of an FTP server in your classes. It introduces fragility
96
- into your tests. Also, the default FTP port of 21 is a privileged port,
97
- and should be avoided.
98
-
99
- *Separate the code that generates files from the code that uploads
100
- files.* You tests will run much more quickly if you only try to upload
101
- small files. If you have tests showing that you generate correct files
102
- from your data, then you can trust that. Why do you need to upload a 20M
103
- file in your tests if you can stub out your file generation method and
104
- test file upload against 10 bytes? Fast fast fast.
87
+ *Separate configuration from code.* Do not hard code the IP address, FQDN or
88
+ port of an FTP server in your code. It introduces fragility into your tests.
89
+ Also, the default FTP port of 21 is a privileged port, and should be avoided.
105
90
 
91
+ *Separate the code that generates files from the code that uploads files.* You
92
+ tests will run much more quickly if you only try to upload small files. If you
93
+ have tests showing that you generate correct files from your data, then you can
94
+ trust that. Why do you need to upload a 20M file in your tests if you can stub
95
+ out your file generation method and test file upload against 10 bytes? Fast fast
96
+ fast.
106
97
 
107
98
  ## References
108
99
 
109
100
  * http://rubyforge.org/projects/ftpd/ - a simple ftp daemon written by Chris Wanstrath
110
101
  * http://ruby-doc.org/stdlib/libdoc/gserver/rdoc/index.html - a generic server in the Ruby standard library, by John W Small
111
-
112
- ## License
113
-
114
- The MIT License
115
-
116
- Copyright (c) 2011 Eric Saxby
117
-
118
- Permission is hereby granted, free of charge, to any person obtaining a copy
119
- of this software and associated documentation files (the "Software"), to deal
120
- in the Software without restriction, including without limitation the rights
121
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
122
- copies of the Software, and to permit persons to whom the Software is
123
- furnished to do so, subject to the following conditions:
124
-
125
- The above copyright notice and this permission notice shall be included in
126
- all copies or substantial portions of the Software.
127
-
128
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
129
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
130
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
131
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
132
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
133
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
134
- THE SOFTWARE.