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:
@@ -1,8 +1,7 @@
|
||||
module Producer::Core
|
||||
shared_examples 'action' do
|
||||
let(:input) { StringIO.new }
|
||||
let(:output) { StringIO.new }
|
||||
let(:env) { Env.new(input: input, output: output) }
|
||||
include TestEnvHelpers
|
||||
|
||||
let(:arguments) { [:some, :arguments] }
|
||||
subject(:action) { described_class.new(env, *arguments) }
|
||||
|
||||
@@ -20,25 +19,25 @@ module Producer::Core
|
||||
|
||||
describe '#input' do
|
||||
it 'returns env input' do
|
||||
expect(action.input).to be input
|
||||
expect(action.input).to be env.input
|
||||
end
|
||||
end
|
||||
|
||||
describe '#output' do
|
||||
it 'returns env output' do
|
||||
expect(action.output).to be output
|
||||
expect(action.output).to be env.output
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remote' do
|
||||
it 'returns env remote' do
|
||||
expect(action.remote).to be action.env.remote
|
||||
expect(action.remote).to be env.remote
|
||||
end
|
||||
end
|
||||
|
||||
describe '#fs' do
|
||||
it 'returns env remote fs' do
|
||||
expect(action.fs).to be action.env.remote.fs
|
||||
expect(action.fs).to be env.remote.fs
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,6 +1,7 @@
|
||||
module Producer::Core
|
||||
shared_examples 'test' do
|
||||
let(:env) { Env.new }
|
||||
include TestEnvHelpers
|
||||
|
||||
let(:arguments) { [:some, :arguments] }
|
||||
subject(:test) { described_class.new(env, *arguments) }
|
||||
|
||||
|
31
spec/support/test_env_helpers.rb
Normal file
31
spec/support/test_env_helpers.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
module TestEnvHelpers
|
||||
require 'producer/core/testing'
|
||||
|
||||
def env
|
||||
@_env ||= build_env
|
||||
end
|
||||
|
||||
def output
|
||||
env.output.string
|
||||
end
|
||||
|
||||
def remote_fs
|
||||
env.remote.fs
|
||||
end
|
||||
|
||||
def expect_execution(command)
|
||||
opts = { expected_from: caller.first }
|
||||
RSpec::Mocks.expect_message(env.remote, :execute, opts).with(command)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def build_env
|
||||
Producer::Core::Env.new(output: StringIO.new, remote: build_remote)
|
||||
end
|
||||
|
||||
def build_remote
|
||||
Producer::Core::Testing::MockRemote.new('some_host.test')
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user