producer-core/spec/support/test_env_helpers.rb
Thibault Jouan fcba1a5c0b 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
2014-03-04 23:24:05 +00:00

32 lines
535 B
Ruby

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