Class: HammerCLIForeman::Testing::APIExpectations::BlockMatcher

Inherits:
Mocha::ParameterMatchers::Base
  • Object
show all
Defined in:
lib/hammer_cli_foreman/testing/api_expectations.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource = nil, action = nil, &block) ⇒ BlockMatcher

Returns a new instance of BlockMatcher.



5
6
7
8
9
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 5

def initialize(resource=nil, action=nil, &block)
  @expected_resource = resource
  @expected_action = action
  @block = block if block_given?
end

Instance Method Details

#matches?(actual_parameters) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 11

def matches?(actual_parameters)
  action, params, headers, options = actual_parameters.shift(4)
  action_name = action.name.to_s
  resource_name = action.resource.to_s

  result = true
  result &&= (resource_name == @expected_resource.to_s) unless @expected_resource.nil?
  result &&= (action_name == @expected_action.to_s) unless @expected_action.nil?
  result &&= @block.call(params) if @block
  result
end

#mocha_inspectObject



23
24
25
26
27
28
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 23

def mocha_inspect
  res = @expected_resource.nil? ? 'any_resource' : ":#{@expected_resource}"
  act = @expected_action.nil? ? 'any_action' : ":#{@expected_action}"
  blk = @block ? '&block' : '*any_argument'
  "#{res}, #{act}, #{blk}"
end