Implement rspec TestEnvHelpers:

Allow use of our test environment, with a mocked remote and convenient
methods to write more concise expectations.

  #env, builds and returns a memoized test environment (with mocked
  remote)

  #output, returns env output as a string

  #remote_fs, returns env remote fs

  #expect_execution, setup a remote command execution expectation
This commit is contained in:
Thibault Jouan
2014-02-14 18:24:42 +00:00
parent 85e3bf2eac
commit fcba1a5c0b
11 changed files with 64 additions and 45 deletions

View File

@@ -2,8 +2,7 @@ require 'spec_helper'
module Producer::Core
module Actions
describe Echo do
let(:env) { Env.new(output: StringIO.new) }
describe Echo, :env do
let(:text) { 'hello' }
subject(:echo) { Echo.new(env, text) }
@@ -12,7 +11,7 @@ module Producer::Core
describe '#apply' do
it 'writes the given string to env output with a record separator' do
echo.apply
expect(env.output.string).to eq "hello\n"
expect(output).to eq "hello\n"
end
end
end

View File

@@ -2,8 +2,7 @@ require 'spec_helper'
module Producer::Core
module Actions
describe FileWriter do
let(:env) { Env.new }
describe FileWriter, :env do
let(:path) { 'some_path' }
let(:content) { 'some_content' }
subject(:writer) { FileWriter.new(env, path, content) }
@@ -12,7 +11,7 @@ module Producer::Core
describe '#apply' do
it 'writes content to file on remote filesystem' do
expect(writer.fs).to receive(:file_write).with(path, content)
expect(remote_fs).to receive(:file_write).with(path, content)
writer.apply
end
end

View File

@@ -2,8 +2,7 @@ require 'spec_helper'
module Producer::Core
module Actions
describe Mkdir do
let(:env) { Env.new }
describe Mkdir, :env do
let(:path) { 'some_path' }
subject(:mkdir) { Mkdir.new(env, path) }
@@ -11,7 +10,7 @@ module Producer::Core
describe '#apply' do
it 'creates directory on remote filesystem' do
expect(mkdir.fs).to receive(:mkdir).with(path)
expect(remote_fs).to receive(:mkdir).with(path)
mkdir.apply
end
end

View File

@@ -2,8 +2,7 @@ require 'spec_helper'
module Producer::Core
module Actions
describe ShellCommand do
let(:env) { Env.new(output: StringIO.new) }
describe ShellCommand, :env do
let(:command_args) { 'hello from remote host' }
let(:command) { "echo #{command_args}" }
subject(:sh) { ShellCommand.new(env, command) }
@@ -12,14 +11,13 @@ module Producer::Core
describe '#apply' do
it 'executes the remote command' do
expect(sh.remote).to receive(:execute).with(command)
expect_execution(command)
sh.apply
end
it 'writes the returned output with a record separator' do
allow(sh.remote).to receive(:execute) { command_args }
sh.apply
expect(sh.output.string).to eq "#{command_args}\n"
expect(output).to eq "#{command_args}\n"
end
end
end