Sha256: cab49c055ae497fb63220a3d260a8b3f04f83258672d8017e1d4e3682f9859e4

Contents?: true

Size: 1.01 KB

Versions: 33

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

33 entries across 33 versions & 1 rubygems

Version Path
graphql-0.19.3 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.19.2 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.19.1 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.19.0 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.15 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.14 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.13 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.12 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.11 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.10 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.9 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.8 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.7 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.6 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.5 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.4 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.3 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.2 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.1 spec/graphql/schema/rescue_middleware_spec.rb
graphql-0.18.0 spec/graphql/schema/rescue_middleware_spec.rb