Class: GrpcMock::RequestStub
- Inherits:
-
Object
- Object
- GrpcMock::RequestStub
- Defined in:
- lib/grpc_mock/request_stub.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ RequestStub
constructor
A new instance of RequestStub.
- #match?(path, request) ⇒ Bool
- #response ⇒ Object
- #to_return(*resp) ⇒ Object
- #with(request = nil, &block) ⇒ Object
Constructor Details
#initialize(path) ⇒ RequestStub
Returns a new instance of RequestStub.
10 11 12 13 |
# File 'lib/grpc_mock/request_stub.rb', line 10 def initialize(path) @request_pattern = RequestPattern.new(path) @response_sequence = [] end |
Instance Method Details
#match?(path, request) ⇒ Bool
42 43 44 |
# File 'lib/grpc_mock/request_stub.rb', line 42 def match?(path, request) @request_pattern.match?(path, request) end |
#response ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/grpc_mock/request_stub.rb', line 25 def response if @response_sequence.empty? raise GrpcMock::NoResponseError, 'Must be set some values by using #GrpMock::RequestStub#to_run' elsif @response_sequence.size == 1 @response_sequence.first.next else if @response_sequence.first.end? @response_sequence.shift end @response_sequence.first.next end end |
#to_return(*resp) ⇒ Object
20 21 22 23 |
# File 'lib/grpc_mock/request_stub.rb', line 20 def to_return(*resp) @response_sequence << GrpcMock::ResponsesSequence.new(resp) self end |
#with(request = nil, &block) ⇒ Object
15 16 17 18 |
# File 'lib/grpc_mock/request_stub.rb', line 15 def with(request = nil, &block) @request_pattern.with(request, &block) self end |