summaryrefslogtreecommitdiff
path: root/spec/unit/util/network_device/transport/base_spec.rb
blob: 24354d4ba6008ccf8057d4d756bb3592faa6b34b (plain)
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
#! /usr/bin/env ruby
require 'spec_helper'

require 'puppet/util/network_device/transport/base'

describe Puppet::Util::NetworkDevice::Transport::Base do
  class TestTransport < Puppet::Util::NetworkDevice::Transport::Base
  end

  before(:each) do
    @transport = TestTransport.new
  end

  describe "when sending commands" do
    it "should send the command to the telnet session" do
      @transport.expects(:send).with("line")
      @transport.command("line")
    end

    it "should expect an output matching the given prompt" do
      @transport.expects(:expect).with(/prompt/)
      @transport.command("line", :prompt => /prompt/)
    end

    it "should expect an output matching the default prompt" do
      @transport.default_prompt = /defprompt/
      @transport.expects(:expect).with(/defprompt/)
      @transport.command("line")
    end

    it "should yield telnet output to the given block" do
      @transport.expects(:expect).yields("output")
      @transport.command("line") { |out| out.should == "output" }
    end

    it "should return telnet output to the caller" do
      @transport.expects(:expect).returns("output")
      @transport.command("line").should == "output"
    end
  end
end