Sha256: c1dd8d958a4edd19cbaf690f912400197db7e90749b183b5a78d46f92cd8a046

Contents?: true

Size: 907 Bytes

Versions: 3

Compression:

Stored size: 907 Bytes

Contents

require_relative "../../../test_support/captures_stderr.rb"
require_relative "../../../test_support/captures_stdout.rb"

require_relative "temp_dir"

class Example

  include CapturesStderr
  include CapturesStdout

  def initialize(contents, opts = {})
    @contents = contents
    @filename = opts.fetch(:filename, "example.rb")
    @temp_dir = TempDir.new
    create_file
  end

  def run
    @stdout = capture_stdout do
      @stderr = capture_stderr do
        load path
      end
    end
  end

  def stderr
    filter_output(@stderr)
  end

  def stdout
    filter_output(@stdout)
  end

  private

  def create_file
    File.open(path, 'w') do |file|
      file.write @contents
    end
  end

  def path
    File.join(@temp_dir.path, @filename)
  end

  def filter_output(output)
    redact_tmp_path(output)
  end

  def redact_tmp_path(output)
    output.sub(/\/tmp\/.*\//, "/tmp/.../")
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cute_print-0.3.0 features/support/helpers/example.rb
cute_print-0.2.0 features/support/helpers/example.rb
cute_print-0.1.0 features/support/helpers/example.rb