rubysl-net-ftp 1.0.0

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.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/lib/net/ftp.rb +1 -0
  9. data/lib/net/ftptls.rb +1 -0
  10. data/lib/rubysl/net/ftp.rb +2 -0
  11. data/lib/rubysl/net/ftp/ftp.rb +926 -0
  12. data/lib/rubysl/net/ftp/version.rb +7 -0
  13. data/rubysl-net-ftp.gemspec +23 -0
  14. data/spec/FTPError_spec.rb +7 -0
  15. data/spec/FTPPermError_spec.rb +11 -0
  16. data/spec/FTPProtoError_spec.rb +11 -0
  17. data/spec/FTPReplyError_spec.rb +11 -0
  18. data/spec/FTPTempError_spec.rb +11 -0
  19. data/spec/abort_spec.rb +61 -0
  20. data/spec/acct_spec.rb +57 -0
  21. data/spec/binary_spec.rb +23 -0
  22. data/spec/chdir_spec.rb +100 -0
  23. data/spec/close_spec.rb +29 -0
  24. data/spec/closed_spec.rb +20 -0
  25. data/spec/connect_spec.rb +48 -0
  26. data/spec/debug_mode_spec.rb +22 -0
  27. data/spec/delete_spec.rb +58 -0
  28. data/spec/dir_spec.rb +7 -0
  29. data/spec/fixtures/putbinaryfile +3 -0
  30. data/spec/fixtures/puttextfile +3 -0
  31. data/spec/fixtures/server.rb +265 -0
  32. data/spec/get_spec.rb +20 -0
  33. data/spec/getbinaryfile_spec.rb +7 -0
  34. data/spec/getdir_spec.rb +6 -0
  35. data/spec/gettextfile_spec.rb +7 -0
  36. data/spec/help_spec.rb +65 -0
  37. data/spec/initialize_spec.rb +86 -0
  38. data/spec/last_response_code_spec.rb +7 -0
  39. data/spec/last_response_spec.rb +24 -0
  40. data/spec/lastresp_spec.rb +7 -0
  41. data/spec/list_spec.rb +7 -0
  42. data/spec/login_spec.rb +215 -0
  43. data/spec/ls_spec.rb +7 -0
  44. data/spec/mdtm_spec.rb +37 -0
  45. data/spec/mkdir_spec.rb +60 -0
  46. data/spec/mtime_spec.rb +49 -0
  47. data/spec/nlst_spec.rb +120 -0
  48. data/spec/noop_spec.rb +37 -0
  49. data/spec/open_spec.rb +54 -0
  50. data/spec/passive_spec.rb +23 -0
  51. data/spec/put_spec.rb +20 -0
  52. data/spec/putbinaryfile_spec.rb +7 -0
  53. data/spec/puttextfile_spec.rb +7 -0
  54. data/spec/pwd_spec.rb +52 -0
  55. data/spec/quit_spec.rb +32 -0
  56. data/spec/rename_spec.rb +93 -0
  57. data/spec/resume_spec.rb +22 -0
  58. data/spec/retrbinary_spec.rb +29 -0
  59. data/spec/retrlines_spec.rb +33 -0
  60. data/spec/return_code_spec.rb +23 -0
  61. data/spec/rmdir_spec.rb +57 -0
  62. data/spec/sendcmd_spec.rb +53 -0
  63. data/spec/set_socket_spec.rb +7 -0
  64. data/spec/shared/getbinaryfile.rb +179 -0
  65. data/spec/shared/gettextfile.rb +129 -0
  66. data/spec/shared/last_response_code.rb +25 -0
  67. data/spec/shared/list.rb +133 -0
  68. data/spec/shared/putbinaryfile.rb +232 -0
  69. data/spec/shared/puttextfile.rb +149 -0
  70. data/spec/shared/pwd.rb +3 -0
  71. data/spec/site_spec.rb +52 -0
  72. data/spec/size_spec.rb +47 -0
  73. data/spec/status_spec.rb +62 -0
  74. data/spec/storbinary_spec.rb +47 -0
  75. data/spec/storlines_spec.rb +42 -0
  76. data/spec/system_spec.rb +47 -0
  77. data/spec/voidcmd_spec.rb +53 -0
  78. data/spec/welcome_spec.rb +24 -0
  79. metadata +243 -0
@@ -0,0 +1,22 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTP#resume" do
4
+ it "returns true when self is set to resume uploads/downloads" do
5
+ ftp = Net::FTP.new
6
+ ftp.resume.should be_false
7
+
8
+ ftp.resume = true
9
+ ftp.resume.should be_true
10
+ end
11
+ end
12
+
13
+ describe "Net::FTP#resume=" do
14
+ it "sets self to resume uploads/downloads when set to true" do
15
+ ftp = Net::FTP.new
16
+ ftp.resume = true
17
+ ftp.resume.should be_true
18
+
19
+ ftp.resume = false
20
+ ftp.resume.should be_false
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#retrbinary" do
5
+ before(:each) do
6
+ @server = NetFTPSpecs::DummyFTP.new
7
+ @server.serve_once
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ end
12
+
13
+ after(:each) do
14
+ @ftp.quit rescue nil
15
+ @ftp.close
16
+ @server.stop
17
+ end
18
+
19
+ it "sends the passed command to the server" do
20
+ @ftp.retrbinary("RETR test", 4096) {}
21
+ @ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
22
+ end
23
+
24
+ it "yields the received content as binary blocks of the passed size" do
25
+ res = []
26
+ @ftp.retrbinary("RETR test", 10) { |bin| res << bin }
27
+ res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ]
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#retrlines" do
5
+ before(:each) do
6
+ @server = NetFTPSpecs::DummyFTP.new
7
+ @server.serve_once
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ end
12
+
13
+ after(:each) do
14
+ @ftp.quit rescue nil
15
+ @ftp.close
16
+ @server.stop
17
+ end
18
+
19
+ it "sends the passed command over the socket" do
20
+ @ftp.retrlines("LIST test.dir") {}
21
+ @ftp.last_response.should == "226 transfer complete (LIST test.dir)\n"
22
+ end
23
+
24
+ it "yields each received line to the passed block" do
25
+ res = []
26
+ @ftp.retrlines("LIST test.dir") { |x| res << x }
27
+ res.should == [
28
+ "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
29
+ "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
30
+ "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
31
+ ]
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTP#return_code" do
4
+ before(:each) do
5
+ @ftp = Net::FTP.new
6
+ end
7
+
8
+ it "outputs a warning and returns a newline" do
9
+ lambda do
10
+ @ftp.return_code.should == "\n"
11
+ end.should complain("warning: Net::FTP#return_code is obsolete and do nothing\n")
12
+ end
13
+ end
14
+
15
+ describe "Net::FTP#return_code=" do
16
+ before(:each) do
17
+ @ftp = Net::FTP.new
18
+ end
19
+
20
+ it "outputs a warning" do
21
+ lambda { @ftp.return_code = 123 }.should complain("warning: Net::FTP#return_code= is obsolete and do nothing\n")
22
+ end
23
+ end
@@ -0,0 +1,57 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#rmdir" do
5
+ before(:each) do
6
+ @server = NetFTPSpecs::DummyFTP.new
7
+ @server.serve_once
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ end
12
+
13
+ after(:each) do
14
+ @ftp.quit rescue nil
15
+ @ftp.close
16
+ @server.stop
17
+ end
18
+
19
+ it "sends the RMD command with the passed pathname to the server" do
20
+ @ftp.rmdir("test.folder")
21
+ @ftp.last_response.should == "250 Requested file action okay, completed. (RMD test.folder)\n"
22
+ end
23
+
24
+ it "returns nil" do
25
+ @ftp.rmdir("test.folder").should be_nil
26
+ end
27
+
28
+ it "raises a Net::FTPPermError when the response code is 500" do
29
+ @server.should_receive(:rmd).and_respond("500 Syntax error, command unrecognized.")
30
+ lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
31
+ end
32
+
33
+ it "raises a Net::FTPPermError when the response code is 501" do
34
+ @server.should_receive(:rmd).and_respond("501 Syntax error in parameters or arguments.")
35
+ lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
36
+ end
37
+
38
+ it "raises a Net::FTPPermError when the response code is 502" do
39
+ @server.should_receive(:rmd).and_respond("502 Command not implemented.")
40
+ lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
41
+ end
42
+
43
+ it "raises a Net::FTPTempError when the response code is 421" do
44
+ @server.should_receive(:rmd).and_respond("421 Service not available, closing control connection.")
45
+ lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPTempError)
46
+ end
47
+
48
+ it "raises a Net::FTPPermError when the response code is 530" do
49
+ @server.should_receive(:rmd).and_respond("530 Not logged in.")
50
+ lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
51
+ end
52
+
53
+ it "raises a Net::FTPPermError when the response code is 550" do
54
+ @server.should_receive(:rmd).and_respond("550 Requested action not taken.")
55
+ lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
56
+ end
57
+ end
@@ -0,0 +1,53 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#sendcmd" do
5
+ before(:each) do
6
+ @server = NetFTPSpecs::DummyFTP.new
7
+ @server.serve_once
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ end
12
+
13
+ after(:each) do
14
+ @ftp.quit rescue nil
15
+ @ftp.close
16
+ @server.stop
17
+ end
18
+
19
+ it "sends the passed command to the server" do
20
+ @ftp.sendcmd("HELP")
21
+ @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
22
+ end
23
+
24
+ it "returns the server's response" do
25
+ @ftp.sendcmd("HELP").should == "211 System status, or system help reply. (HELP)\n"
26
+ end
27
+
28
+ it "raises no error when the response code is 1xx, 2xx or 3xx" do
29
+ @server.should_receive(:help).and_respond("120 Service ready in nnn minutes.")
30
+ lambda { @ftp.sendcmd("HELP") }.should_not raise_error
31
+
32
+ @server.should_receive(:help).and_respond("200 Command okay.")
33
+ lambda { @ftp.sendcmd("HELP") }.should_not raise_error
34
+
35
+ @server.should_receive(:help).and_respond("350 Requested file action pending further information.")
36
+ lambda { @ftp.sendcmd("HELP") }.should_not raise_error
37
+ end
38
+
39
+ it "raises a Net::FTPTempError when the response code is 4xx" do
40
+ @server.should_receive(:help).and_respond("421 Service not available, closing control connection.")
41
+ lambda { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPTempError)
42
+ end
43
+
44
+ it "raises a Net::FTPPermError when the response code is 5xx" do
45
+ @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.")
46
+ lambda { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPPermError)
47
+ end
48
+
49
+ it "raises a Net::FTPProtoError when the response code is not between 1xx-5xx" do
50
+ @server.should_receive(:help).and_respond("999 Invalid response.")
51
+ lambda { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPProtoError)
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTP#set_socket" do
4
+ # TODO: I won't spec this method, as it is not used
5
+ # anywhere and it should be private anyway.
6
+ #it "needs to be reviewed for spec completeness"
7
+ end
@@ -0,0 +1,179 @@
1
+ describe :net_ftp_getbinaryfile, :shared => true do
2
+ before(:each) do
3
+ @fixture_file = File.dirname(__FILE__) + "/../fixtures/getbinaryfile"
4
+ @tmp_file = tmp("getbinaryfile")
5
+
6
+ @server = NetFTPSpecs::DummyFTP.new
7
+ @server.serve_once
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ @ftp.binary = @binary_mode
12
+ end
13
+
14
+ after(:each) do
15
+ @ftp.quit rescue nil
16
+ @ftp.close
17
+ @server.stop
18
+
19
+ rm_r @tmp_file
20
+ end
21
+
22
+ it "sends the RETR command to the server" do
23
+ @ftp.send(@method, "test", @tmp_file)
24
+ @ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
25
+ end
26
+
27
+ it "returns nil" do
28
+ @ftp.send(@method, "test", @tmp_file).should be_nil
29
+ end
30
+
31
+ it "saves the contents of the passed remote file to the passed local file" do
32
+ @ftp.send(@method, "test", @tmp_file)
33
+ File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
34
+ end
35
+
36
+ describe "when passed a block" do
37
+ it "yields the received content as binary blocks of the passed size" do
38
+ res = []
39
+ @ftp.send(@method, "test", @tmp_file, 10) { |bin| res << bin }
40
+ res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ]
41
+ end
42
+ end
43
+
44
+ describe "when resuming an existing file" do
45
+ before(:each) do
46
+ @tmp_file = tmp("getbinaryfile_resume")
47
+
48
+ File.open(@tmp_file, "wb") do |f|
49
+ f << "This is the content\n"
50
+ end
51
+
52
+ @ftp.resume = true
53
+ end
54
+
55
+ it "saves the remaining content of the passed remote file to the passed local file" do
56
+ @ftp.send(@method, "test", @tmp_file)
57
+ File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
58
+ end
59
+
60
+ describe "and the REST command fails" do
61
+ it "raises a Net::FTPProtoError when the response code is 550" do
62
+ @server.should_receive(:rest).and_respond("Requested action not taken.")
63
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError)
64
+ end
65
+
66
+ it "raises a Net::FTPPermError when the response code is 500" do
67
+ @server.should_receive(:rest).and_respond("500 Syntax error, command unrecognized.")
68
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
69
+ end
70
+
71
+ it "raises a Net::FTPPermError when the response code is 501" do
72
+ @server.should_receive(:rest).and_respond("501 Syntax error, command unrecognized.")
73
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
74
+ end
75
+
76
+ it "raises a Net::FTPPermError when the response code is 502" do
77
+ @server.should_receive(:rest).and_respond("502 Command not implemented.")
78
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
79
+ end
80
+
81
+ it "raises a Net::FTPTempError when the response code is 421" do
82
+ @server.should_receive(:rest).and_respond("421 Service not available, closing control connection.")
83
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
84
+ end
85
+
86
+ it "raises a Net::FTPPermError when the response code is 530" do
87
+ @server.should_receive(:rest).and_respond("530 Not logged in.")
88
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "when the RETR command fails" do
94
+ it "raises a Net::FTPTempError when the response code is 450" do
95
+ @server.should_receive(:retr).and_respond("450 Requested file action not taken.")
96
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
97
+ end
98
+
99
+ it "raises a Net::FTPProtoError when the response code is 550" do
100
+ @server.should_receive(:retr).and_respond("Requested action not taken.")
101
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError)
102
+ end
103
+
104
+ it "raises a Net::FTPPermError when the response code is 500" do
105
+ @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.")
106
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
107
+ end
108
+
109
+ it "raises a Net::FTPPermError when the response code is 501" do
110
+ @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.")
111
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
112
+ end
113
+
114
+ it "raises a Net::FTPTempError when the response code is 421" do
115
+ @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.")
116
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
117
+ end
118
+
119
+ it "raises a Net::FTPPermError when the response code is 530" do
120
+ @server.should_receive(:retr).and_respond("530 Not logged in.")
121
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
122
+ end
123
+ end
124
+
125
+ ruby_version_is "" ... "1.9" do
126
+ describe "when switching type fails" do
127
+ it "raises a Net::FTPPermError when the response code is 500" do
128
+ @server.should_receive(:type).and_respond("500 Syntax error, command unrecognized.")
129
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
130
+ end
131
+
132
+ it "raises a Net::FTPPermError when the response code is 501" do
133
+ @server.should_receive(:type).and_respond("501 Syntax error in parameters or arguments.")
134
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
135
+ end
136
+
137
+ it "raises a Net::FTPPermError when the response code is 504" do
138
+ @server.should_receive(:type).and_respond("504 Command not implemented for that parameter.")
139
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
140
+ end
141
+
142
+ it "raises a Net::FTPTempError when the response code is 421" do
143
+ @server.should_receive(:type).and_respond("421 Service not available, closing control connection.")
144
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
145
+ end
146
+
147
+ it "raises a Net::FTPPermError when the response code is 530" do
148
+ @server.should_receive(:type).and_respond("530 Not logged in.")
149
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
150
+ end
151
+ end
152
+ end
153
+
154
+ describe "when opening the data port fails" do
155
+ it "raises a Net::FTPPermError when the response code is 500" do
156
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
157
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
158
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
159
+ end
160
+
161
+ it "raises a Net::FTPPermError when the response code is 501" do
162
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
163
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
164
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
165
+ end
166
+
167
+ it "raises a Net::FTPTempError when the response code is 421" do
168
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
169
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
170
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
171
+ end
172
+
173
+ it "raises a Net::FTPPermError when the response code is 530" do
174
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
175
+ @server.should_receive(:port).and_respond("530 Not logged in.")
176
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,129 @@
1
+ describe :net_ftp_gettextfile, :shared => true do
2
+ before(:each) do
3
+ @tmp_file = tmp("gettextfile")
4
+
5
+ @server = NetFTPSpecs::DummyFTP.new
6
+ @server.serve_once
7
+
8
+ @ftp = Net::FTP.new
9
+ @ftp.connect("localhost", 9921)
10
+ @ftp.binary = @binary_mode
11
+ end
12
+
13
+ after(:each) do
14
+ @ftp.quit rescue nil
15
+ @ftp.close
16
+ @server.stop
17
+
18
+ rm_r @tmp_file
19
+ end
20
+
21
+ it "sends the RETR command to the server" do
22
+ @ftp.send(@method, "test", @tmp_file)
23
+ @ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
24
+ end
25
+
26
+ it "returns nil" do
27
+ @ftp.send(@method, "test", @tmp_file).should be_nil
28
+ end
29
+
30
+ it "saves the contents of the passed remote file to the passed local file" do
31
+ @ftp.send(@method, "test", @tmp_file)
32
+ File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
33
+ end
34
+
35
+ describe "when passed a block" do
36
+ it "yields each line of the retrieved file to the passed block" do
37
+ res = []
38
+ @ftp.send(@method, "test", @tmp_file) { |line| res << line }
39
+ res.should == [ "This is the content", "of the file named 'test'."]
40
+ end
41
+ end
42
+
43
+ describe "when the RETR command fails" do
44
+ it "raises a Net::FTPTempError when the response code is 450" do
45
+ @server.should_receive(:retr).and_respond("450 Requested file action not taken.")
46
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
47
+ end
48
+
49
+ it "raises a Net::FTPProtoError when the response code is 550" do
50
+ @server.should_receive(:retr).and_respond("Requested action not taken.")
51
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError)
52
+ end
53
+
54
+ it "raises a Net::FTPPermError when the response code is 500" do
55
+ @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.")
56
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
57
+ end
58
+
59
+ it "raises a Net::FTPPermError when the response code is 501" do
60
+ @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.")
61
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
62
+ end
63
+
64
+ it "raises a Net::FTPTempError when the response code is 421" do
65
+ @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.")
66
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
67
+ end
68
+
69
+ it "raises a Net::FTPPermError when the response code is 530" do
70
+ @server.should_receive(:retr).and_respond("530 Not logged in.")
71
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
72
+ end
73
+ end
74
+
75
+ ruby_version_is "" ... "1.9" do
76
+ describe "when switching type fails" do
77
+ it "raises a Net::FTPPermError when the response code is 500" do
78
+ @server.should_receive(:type).and_respond("500 Syntax error, command unrecognized.")
79
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
80
+ end
81
+
82
+ it "raises a Net::FTPPermError when the response code is 501" do
83
+ @server.should_receive(:type).and_respond("501 Syntax error in parameters or arguments.")
84
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
85
+ end
86
+
87
+ it "raises a Net::FTPPermError when the response code is 504" do
88
+ @server.should_receive(:type).and_respond("504 Command not implemented for that parameter.")
89
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
90
+ end
91
+
92
+ it "raises a Net::FTPTempError when the response code is 421" do
93
+ @server.should_receive(:type).and_respond("421 Service not available, closing control connection.")
94
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
95
+ end
96
+
97
+ it "raises a Net::FTPPermError when the response code is 530" do
98
+ @server.should_receive(:type).and_respond("530 Not logged in.")
99
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
100
+ end
101
+ end
102
+ end
103
+
104
+ describe "when opening the data port fails" do
105
+ it "raises a Net::FTPPermError when the response code is 500" do
106
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
107
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
108
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
109
+ end
110
+
111
+ it "raises a Net::FTPPermError when the response code is 501" do
112
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
113
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
114
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
115
+ end
116
+
117
+ it "raises a Net::FTPTempError when the response code is 421" do
118
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
119
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
120
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
121
+ end
122
+
123
+ it "raises a Net::FTPPermError when the response code is 530" do
124
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
125
+ @server.should_receive(:port).and_respond("530 Not logged in.")
126
+ lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
127
+ end
128
+ end
129
+ end