# frozen_string_literal: true

require "test_helper"

module WebConsole
  class IntegrationTest < ActiveSupport::TestCase
    test "Exception#bindings returns all the bindings of where the error originated" do
      exc = FlatScenario.new.call

      assert_equal 6, SourceLocation.new(exc.bindings.first).lineno
    end

    test "Exception#bindings returns all the bindings for a custom error" do
      exc = CustomErrorScenario.new.call

      assert_equal 8, SourceLocation.new(exc.bindings.first).lineno
    end

    test "Exception#bindings returns all the bindings for a bad custom error" do
      exc = BadCustomErrorScenario.new.call

      assert_equal 13, SourceLocation.new(exc.bindings.first).lineno
    end

    test "Exception#bindings goes down the stack" do
      exc = BasicNestedScenario.new.call

      assert_equal 14, SourceLocation.new(exc.bindings.first).lineno
    end

    test "Exception#bindings inside of an eval" do
      exc = EvalNestedScenario.new.call

      assert_equal 14, SourceLocation.new(exc.bindings.first).lineno
    end

    test "re-raising doesn't lose Exception#bindings information" do
      exc = ReraisedScenario.new.call

      assert_equal 6, SourceLocation.new(exc.bindings.first).lineno
    end

    test "Exception#bindings is empty when exception is still not raised" do
      exc = RuntimeError.new

      assert_equal [], exc.bindings
    end
  end
end
