Sha256: b32015bf46eafaacc67f4d6dfef2362ab5046d4539ee45fd05d5853bd4bf3889

Contents?: true

Size: 933 Bytes

Versions: 2

Compression:

Stored size: 933 Bytes

Contents

# frozen_string_literal: true

module ProtoPharm
  module RSpec
    class ActionStubBuilder
      attr_accessor :grpc_service, :action_stub_proxy

      delegate :rpc_action, :expectations, to: :action_stub_proxy

      def initialize(grpc_service)
        @grpc_service = grpc_service
      end

      def to(action_stub_proxy)
        @action_stub_proxy = action_stub_proxy

        ProtoPharm.stub_registry.register_request_stub(action_stub)
      end

      private

      def action_stub
        @action_stub ||= ActionStub.new(grpc_service, rpc_action).tap do |stub|
          expectations.each do |ex|
            if ex.kwargs.blank?
              stub.public_send(ex.method, *ex.args)
            elsif ex.args.blank?
              stub.public_send(ex.method, **ex.kwargs)
            else
              stub.public_send(ex.method, *ex.args, **ex.kwargs)
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proto_pharm-0.7.0 lib/proto_pharm/rspec/action_stub_builder.rb
proto_pharm-0.6.0 lib/proto_pharm/rspec/action_stub_builder.rb