Class: HammerCLIForeman::Testing::APIExpectations::APICallMatcher
- Inherits:
-
Mocha::ParameterMatchers::Base
- Object
- Mocha::ParameterMatchers::Base
- HammerCLIForeman::Testing::APIExpectations::APICallMatcher
- Defined in:
- lib/hammer_cli_foreman/testing/api_expectations.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#expected_action ⇒ Object
Returns the value of attribute expected_action.
-
#expected_params ⇒ Object
Returns the value of attribute expected_params.
-
#expected_resource ⇒ Object
Returns the value of attribute expected_resource.
Instance Method Summary collapse
-
#initialize(resource = nil, action = nil, &block) ⇒ APICallMatcher
constructor
A new instance of APICallMatcher.
- #matches?(actual_parameters) ⇒ Boolean
- #mocha_inspect ⇒ Object
Constructor Details
#initialize(resource = nil, action = nil, &block) ⇒ APICallMatcher
Returns a new instance of APICallMatcher.
7 8 9 10 11 12 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 7 def initialize(resource=nil, action=nil, &block) @expected_resource = resource @expected_action = action @block = block if block_given? @expected_params = {} end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
5 6 7 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 5 def block @block end |
#expected_action ⇒ Object
Returns the value of attribute expected_action.
5 6 7 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 5 def expected_action @expected_action end |
#expected_params ⇒ Object
Returns the value of attribute expected_params.
5 6 7 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 5 def expected_params @expected_params end |
#expected_resource ⇒ Object
Returns the value of attribute expected_resource.
5 6 7 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 5 def expected_resource @expected_resource end |
Instance Method Details
#matches?(actual_parameters) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 14 def matches?(actual_parameters) action, params, headers, = 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 &&= assert_params(params) result end |
#mocha_inspect ⇒ Object
27 28 29 30 31 32 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 27 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 |