Refactor Net::SSH spec helpers definition and usages
This commit is contained in:
parent
5d9a5f1f57
commit
cff122432b
@ -2,9 +2,6 @@ require 'spec_helper'
|
|||||||
|
|
||||||
module Producer::Core
|
module Producer::Core
|
||||||
describe Remote do
|
describe Remote do
|
||||||
require 'net/ssh/test'
|
|
||||||
include Net::SSH::Test
|
|
||||||
|
|
||||||
let(:hostname) { 'some_host.example' }
|
let(:hostname) { 'some_host.example' }
|
||||||
subject(:remote) { Remote.new(hostname) }
|
subject(:remote) { Remote.new(hostname) }
|
||||||
|
|
||||||
@ -32,30 +29,12 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#execute' do
|
describe '#execute', type: :ssh do
|
||||||
let(:args) { 'some remote command'}
|
let(:args) { 'some remote command'}
|
||||||
let(:command) { "echo #{args}" }
|
let(:command) { "echo #{args}" }
|
||||||
|
|
||||||
# FIXME: refactor this with helpers, expectations and/or matchers.
|
|
||||||
def with_new_channel_story
|
|
||||||
story do |session|
|
|
||||||
ch = session.opens_channel
|
|
||||||
yield ch
|
|
||||||
ch.gets_close
|
|
||||||
ch.sends_close
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def story_completed?
|
|
||||||
socket.script.events.empty?
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
|
||||||
allow(remote).to receive(:session) { connection }
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'executes the given command in a new channel' do
|
it 'executes the given command in a new channel' do
|
||||||
with_new_channel_story do |ch|
|
story_with_new_channel do |ch|
|
||||||
ch.sends_exec command
|
ch.sends_exec command
|
||||||
ch.gets_data args
|
ch.gets_data args
|
||||||
end
|
end
|
||||||
@ -64,7 +43,7 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the output' do
|
it 'returns the output' do
|
||||||
with_new_channel_story do |ch|
|
story_with_new_channel do |ch|
|
||||||
ch.sends_exec command
|
ch.sends_exec command
|
||||||
ch.gets_data args
|
ch.gets_data args
|
||||||
end
|
end
|
||||||
|
@ -2,3 +2,12 @@ require 'producer/core'
|
|||||||
|
|
||||||
require 'support/exit_helpers'
|
require 'support/exit_helpers'
|
||||||
require 'support/fixtures_helpers'
|
require 'support/fixtures_helpers'
|
||||||
|
require 'support/net_ssh_story_helpers'
|
||||||
|
|
||||||
|
|
||||||
|
RSpec.configure do |c|
|
||||||
|
c.include NetSSHStoryHelpers, type: :ssh
|
||||||
|
c.before(:each, type: :ssh) do
|
||||||
|
allow(remote).to receive(:session) { connection }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
17
spec/support/net_ssh_story_helpers.rb
Normal file
17
spec/support/net_ssh_story_helpers.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
module NetSSHStoryHelpers
|
||||||
|
require 'net/ssh/test'
|
||||||
|
include Net::SSH::Test
|
||||||
|
|
||||||
|
def story_with_new_channel
|
||||||
|
story do |session|
|
||||||
|
ch = session.opens_channel
|
||||||
|
yield ch
|
||||||
|
ch.gets_close
|
||||||
|
ch.sends_close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def story_completed?
|
||||||
|
socket.script.events.empty?
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user