Sha256: 254a0bb393f60a709c3c9b2b534d6a8d180ce50e03c772e0616fe90d8fad2eea

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

#!/usr/bin/env ruby
# encoding: UTF-8

require File.expand_path('../test_helper', __FILE__)

class AbstractPrinterTest < TestCase
  def setup
    @result = {}
    @printer = RubyProf::AbstractPrinter.new(@result)
    @options = {}
    @printer.setup_options(@options)
  end

  def test_editor_uri
    env = {}

    with_const_stubbed('ENV', env) do
      @options[:editor_uri] = 'nvim'

      env['RUBY_PROF_EDITOR_URI'] = 'atm'
      assert_equal('atm', @printer.editor_uri)

      env['RUBY_PROF_EDITOR_URI'] = nil
      assert_equal(false, @printer.editor_uri)

      env.delete('RUBY_PROF_EDITOR_URI')
      assert_equal('nvim', @printer.editor_uri)

      with_const_stubbed('RUBY_PLATFORM', 'x86_64-darwin18') do
        assert_equal('nvim', @printer.editor_uri)

        @options.delete(:editor_uri)
        assert_equal('txmt', @printer.editor_uri)
      end
      with_const_stubbed('RUBY_PLATFORM', 'windows') do
        assert_equal(false, @printer.editor_uri)
      end
    end
  end

  private

  def with_const_stubbed(name, value)
    old_verbose, $VERBOSE = $VERBOSE, nil
    old_value = Object.const_get(name)

    Object.const_set(name, value)
    yield
    Object.const_set(name, old_value)

    $VERBOSE = old_verbose
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/ruby-prof-0.18.0/test/abstract_printer_test.rb
ruby-prof-0.18.0-x64-mingw32 test/abstract_printer_test.rb
ruby-prof-0.18.0 test/abstract_printer_test.rb