Sha256: 90288c8859c953bc90a49a069ad53ebc84766197063f0a6657c6e0852a002bce

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

require "spec_helper"

class SpecExampleError < StandardError; end

describe GraphQL::Schema::RescueMiddleware do
  let(:error_middleware) { ->(next_middleware) { raise(error_class) } }

  let(:rescue_middleware) do
    middleware = GraphQL::Schema::RescueMiddleware.new
    middleware.rescue_from(SpecExampleError) { |err| "there was an example error: #{err.class.name}" }
    middleware
  end

  let(:steps) { [rescue_middleware, error_middleware] }

  let(:middleware_chain) { GraphQL::Schema::MiddlewareChain.new(steps: steps, arguments: [])}

  describe "known errors" do
    let(:error_class) { SpecExampleError }
    it "handles them as execution errors" do
      result = middleware_chain.call
      assert_equal("there was an example error: SpecExampleError", result.message)
      assert_equal(GraphQL::ExecutionError, result.class)
    end
  end

  describe "unknown errors" do
    let(:error_class) { RuntimeError }
    it "re-raises them" do
      assert_raises(RuntimeError) { middleware_chain.call }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
graphql-1.2.6 spec/graphql/schema/rescue_middleware_spec.rb
graphql-1.2.5 spec/graphql/schema/rescue_middleware_spec.rb
graphql-1.2.4 spec/graphql/schema/rescue_middleware_spec.rb
graphql-1.2.3 spec/graphql/schema/rescue_middleware_spec.rb
graphql-1.2.2 spec/graphql/schema/rescue_middleware_spec.rb
graphql-1.2.1 spec/graphql/schema/rescue_middleware_spec.rb
graphql-1.2.0 spec/graphql/schema/rescue_middleware_spec.rb
graphql-1.1.0 spec/graphql/schema/rescue_middleware_spec.rb
graphql-1.0.0 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.19.4 spec/graphql/schema/rescue_middleware_spec.rb