Sha256: 4c061cb3d85678f46aeb6c3f82eb9fc47dfaa1945558b623549b4e59340b64a0

Contents?: true

Size: 1.84 KB

Versions: 25

Compression:

Stored size: 1.84 KB

Contents

class Nanoc::CLI::ErrorHandlerTest < Nanoc::TestCase
  def setup
    super
    @handler = Nanoc::CLI::ErrorHandler.new
  end

  def test_resolution_for_with_unknown_gem
    error = LoadError.new('no such file to load -- afjlrestjlsgrshter')
    assert_nil @handler.send(:resolution_for, error)
  end

  def test_resolution_for_with_known_gem_without_bundler
    def @handler.using_bundler?
      false
    end
    error = LoadError.new('no such file to load -- kramdown')
    assert_match(/^Install the 'kramdown' gem using `gem install kramdown`./, @handler.send(:resolution_for, error))
  end

  def test_resolution_for_with_known_gem_with_bundler
    def @handler.using_bundler?
      true
    end
    error = LoadError.new('no such file to load -- kramdown')
    assert_match(/^Make sure the gem is added to Gemfile/, @handler.send(:resolution_for, error))
  end

  def test_resolution_for_with_not_load_error
    error = RuntimeError.new('nuclear meltdown detected')
    assert_nil @handler.send(:resolution_for, error)
  end

  def test_write_stack_trace_verbose
    error = new_error(20)

    stream = StringIO.new
    @handler.send(:write_stack_trace, stream, error, verbose: false)
    assert_match(/See full crash log for details./, stream.string)

    stream = StringIO.new
    @handler.send(:write_stack_trace, stream, error, verbose: false)
    assert_match(/See full crash log for details./, stream.string)

    stream = StringIO.new
    @handler.send(:write_stack_trace, stream, error, verbose: true)
    refute_match(/See full crash log for details./, stream.string)
  end

  def new_error(amount_factor)
    backtrace_generator = lambda do |af|
      if af == 0
        raise 'finally!'
      else
        backtrace_generator.call(af - 1)
      end
    end

    begin
      backtrace_generator.call(amount_factor)
    rescue => e
      return e
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
nanoc-4.2.4 test/cli/test_error_handler.rb
nanoc-4.2.3 test/cli/test_error_handler.rb
nanoc-4.2.2 test/cli/test_error_handler.rb
nanoc-4.2.1 test/cli/test_error_handler.rb
nanoc-4.2.0 test/cli/test_error_handler.rb
nanoc-4.1.6 test/cli/test_error_handler.rb
nanoc-4.2.0b1 test/cli/test_error_handler.rb
nanoc-4.1.5 test/cli/test_error_handler.rb
nanoc-4.1.4 test/cli/test_error_handler.rb
nanoc-4.1.3 test/cli/test_error_handler.rb
nanoc-4.1.2 test/cli/test_error_handler.rb
nanoc-4.1.1 test/cli/test_error_handler.rb
nanoc-4.1.0 test/cli/test_error_handler.rb
nanoc-4.1.0rc2 test/cli/test_error_handler.rb
nanoc-4.1.0rc1 test/cli/test_error_handler.rb
nanoc-4.1.0b1 test/cli/test_error_handler.rb
nanoc-4.1.0a1 test/cli/test_error_handler.rb
nanoc-4.0.2 test/cli/test_error_handler.rb
nanoc-4.0.1 test/cli/test_error_handler.rb
nanoc-4.0.0 test/cli/test_error_handler.rb