File: initialize_spec.rb

package info (click to toggle)
ruby2.5 2.5.5-3%2Bdeb10u4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 101,532 kB
  • sloc: ruby: 732,598; ansic: 669,262; xml: 25,363; yacc: 20,963; javascript: 6,680; sh: 3,610; lisp: 2,627; makefile: 596; python: 198; sed: 76; perl: 62; awk: 36; asm: 35
file content (91 lines) | stat: -rw-r--r-- 2,581 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../spec_helper', __FILE__)

describe "Net::FTP#initialize" do
  before :each do
    @ftp = Net::FTP.allocate
    @ftp.stub!(:connect)
    @port_args = []
    ruby_version_is "2.5" do
      @port_args << 21
    end
  end

  it "is private" do
    Net::FTP.should have_private_instance_method(:initialize)
  end

  it "sets self into binary mode" do
    @ftp.binary.should be_nil
    @ftp.send(:initialize)
    @ftp.binary.should be_true
  end

  it "sets self into active mode" do
    @ftp.passive.should be_nil
    @ftp.send(:initialize)
    @ftp.passive.should be_false
  end

  it "sets self into non-debug mode" do
    @ftp.debug_mode.should be_nil
    @ftp.send(:initialize)
    @ftp.debug_mode.should be_false
  end

  it "sets self to not resume file uploads/downloads" do
    @ftp.resume.should be_nil
    @ftp.send(:initialize)
    @ftp.resume.should be_false
  end

  describe "when passed no arguments" do
    it "does not try to connect" do
      @ftp.should_not_receive(:connect)
      @ftp.send(:initialize)
    end
  end

  describe "when passed host" do
    it "tries to connect to the passed host" do
      @ftp.should_receive(:connect).with("localhost", *@port_args)
      @ftp.send(:initialize, "localhost")
    end
  end

  describe "when passed host, user" do
    it "tries to connect to the passed host" do
      @ftp.should_receive(:connect).with("localhost", *@port_args)
      @ftp.send(:initialize, "localhost")
    end

    it "tries to login with the passed username" do
      @ftp.should_receive(:login).with("rubyspec", nil, nil)
      @ftp.send(:initialize, "localhost", "rubyspec")
    end
  end

  describe "when passed host, user, password" do
    it "tries to connect to the passed host" do
      @ftp.should_receive(:connect).with("localhost", *@port_args)
      @ftp.send(:initialize, "localhost")
    end

    it "tries to login with the passed username and password" do
      @ftp.should_receive(:login).with("rubyspec", "rocks", nil)
      @ftp.send(:initialize, "localhost", "rubyspec", "rocks")
    end
  end

  describe "when passed host, user" do
    it "tries to connect to the passed host" do
      @ftp.should_receive(:connect).with("localhost", *@port_args)
      @ftp.send(:initialize, "localhost")
    end

    it "tries to login with the passed username, password and account" do
      @ftp.should_receive(:login).with("rubyspec", "rocks", "account")
      @ftp.send(:initialize, "localhost", "rubyspec", "rocks", "account")
    end
  end
end