Sha256: 84f82297543dcd9e872a2b123225592ecb043adca22d63a598639ba44099f829
Contents?: true
Size: 1.13 KB
Versions: 3
Compression:
Stored size: 1.13 KB
Contents
require 'minitest/mock' require 'open3' # Open3::capture3 replacement that reads stdout, stderr and return # values from the filesystem class FakeCapture3 def initialize(basedir, env) @basedir = basedir @env = env @mock_open3 = Minitest::Mock.new @capture3_stub = lambda do |stub_env, stub_command| @mock_open3.capture3(stub_env, stub_command) end end def expect(command) @mock_open3.expect(:capture3, return_values(command), [@env, command]) end def stub Open3.stub :capture3, @capture3_stub do yield if block_given? end @mock_open3.verify end private def return_values(command) filename = command.gsub(' ', '_') command_stdout = File.read("#{@basedir}/#{filename}.stdout") command_stderr = File.read("#{@basedir}/#{filename}.stderr") command_status = File.read("#{@basedir}/#{filename}.return").chomp == '0' [command_stdout, command_stderr, FakeProcessStatus.new(command_status)] end # fake Process::Status replacement class FakeProcessStatus def initialize(success) @success = success end def success? @success end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
wright-0.1.2 | spec/spec_helpers/fake_capture3.rb |
wright-0.1.1 | spec/spec_helpers/fake_capture3.rb |
wright-0.1.0 | spec/spec_helpers/fake_capture3.rb |