Class: WebMock::Twirp::Matchers::MakeTwirpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/webmock/twirp/matchers/make_twirp_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(*matchers) ⇒ MakeTwirpRequest

Returns a new instance of MakeTwirpRequest.



5
6
7
# File 'lib/webmock/twirp/matchers/make_twirp_request.rb', line 5

def initialize(*matchers)
  @stub = WebMock::Twirp::RequestStub.new(*matchers)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object



9
10
11
12
13
14
# File 'lib/webmock/twirp/matchers/make_twirp_request.rb', line 9

def method_missing(name, *args, **kwargs, &block)
  return super unless respond_to_missing?(name)
  @stub.send(name, *args, **kwargs, &block)

  self
end

Instance Method Details

#failure_messageObject



32
33
34
# File 'lib/webmock/twirp/matchers/make_twirp_request.rb', line 32

def failure_message
  "expected a Twirp request but received none"
end

#failure_message_when_negatedObject



36
37
38
# File 'lib/webmock/twirp/matchers/make_twirp_request.rb', line 36

def failure_message_when_negated
  "did not expect a Twirp request, but received one"
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/webmock/twirp/matchers/make_twirp_request.rb', line 20

def matches?(block)
  unless block.is_a?(Proc)
    raise ArgumentError, "expected block, found: #{block}"
  end

  WebMock::StubRegistry.instance.register_request_stub(@stub)
  block.call
  WebMock::StubRegistry.instance.remove_request_stub(@stub)

  RequestRegistry.instance.times_executed(@stub) > 0
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/webmock/twirp/matchers/make_twirp_request.rb', line 16

def respond_to_missing?(method_name, include_private = false)
  @stub.respond_to?(method_name)
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/webmock/twirp/matchers/make_twirp_request.rb', line 40

def supports_block_expectations?
  true
end