ssh接続をテストするためにrspecを書き込もうとしています。私の仕様ファイルでは、たとえ私が間違ったサーバパスワードを入力したとしても、まだ0 examples, 0 failures
と言います。誰かが私に感謝することができますなぜ私はそれを見ていますが、私は少なくとも1つの失敗メッセージを見ることが期待されています。ssh接続用のRspec
以下は、私のssh_host.rb
とssh_host_spec.rb files
のコードです。
require "java"
require "highline/import"
require 'open-uri'
require 'socket'
require 'rubygems'
require 'net/ssh'
require 'stringio'
require 'net/scp'
require 'colorize'
module SshMod
class SshHost
attr_accessor :hostname, :username, :password
def initialize(host, user, password)
@hostname = host
@username = user
@password = password
@ssh = Net::SSH.start(@hostname, @username, :password => @password)
puts "\t Connection established for #{@hostname}...".blue
end
end
end
RSpecのクラス:
#!/usr/bin/env rspec
require 'spec_helper'
require 'ssh_host.rb'
describe SshMod::SshHost do
before :each do
@ssh = SshMod::SshHost.new "servername", "user", "wrong_password"
end
end
describe "#new" do
it "takes three parameters and returns sshhostobject" do
@ssh.should_be_an_instance_of SshHost
end
end
ssh_mock = double()
expect(SSH).to receive(:start).and_return(ssh_mock)