3
require File.dirname(__FILE__) + '/../../../../spec_helper'
5
require 'puppet/util/network_device/transport/telnet'
7
describe Puppet::Util::NetworkDevice::Transport::Telnet do
10
@transport = Puppet::Util::NetworkDevice::Transport::Telnet.new()
13
it "should not handle login through the transport" do
14
@transport.should_not be_handles_login
17
it "should connect to the given host and port" do
18
Net::Telnet.expects(:new).with { |args| args["Host"] == "localhost" && args["Port"] == 23 }.returns stub_everything
19
@transport.host = "localhost"
25
it "should connect and specify the default prompt" do
26
@transport.default_prompt = "prompt"
27
Net::Telnet.expects(:new).with { |args| args["Prompt"] == "prompt" }.returns stub_everything
28
@transport.host = "localhost"
34
describe "when connected" do
36
@telnet = stub_everything 'telnet'
37
Net::Telnet.stubs(:new).returns(@telnet)
41
it "should send line to the telnet session" do
42
@telnet.expects(:puts).with("line")
43
@transport.send("line")
46
describe "when expecting output" do
47
it "should waitfor output on the telnet session" do
48
@telnet.expects(:waitfor).with(/regex/)
49
@transport.expect(/regex/)
52
it "should return telnet session output" do
53
@telnet.expects(:waitfor).returns("output")
54
@transport.expect(/regex/).should == "output"
57
it "should yield telnet session output to the given block" do
58
@telnet.expects(:waitfor).yields("output")
59
@transport.expect(/regex/) { |out| out.should == "output" }
64
describe "when closing" do
66
@telnet = stub_everything 'telnet'
67
Net::Telnet.stubs(:new).returns(@telnet)
71
it "should close the telnet session" do
72
@telnet.expects(:close)