Module: HammerCLIForeman::Testing::APIExpectations::ExpectationExtensions

Defined in:
lib/hammer_cli_foreman/testing/api_expectations.rb

Instance Method Summary collapse

Instance Method Details

#api_call_matcherObject



103
104
105
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 103

def api_call_matcher
  @api_call_matcher ||= APICallMatcher.new
end

#block_signature(block) ⇒ Object



81
82
83
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 81

def block_signature(block)
  block.source_location.join(':')
end

#method_signatureObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 66

def method_signature
  signature = "#{@note}\n  #{super}"
  if @api_call_matcher && !@api_call_matcher.expected_params.empty?
    signature += "\n  expected params to include: " + params_signature(@api_call_matcher.expected_params)
  end
  if @api_call_matcher && !@api_call_matcher.block.nil?
    signature += "\n  expected params to match block at: " + block_signature(@api_call_matcher.block)
  end
  signature
end

#params_signature(hash) ⇒ Object



77
78
79
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 77

def params_signature(hash)
  JSON.pretty_generate(hash).split("\n").join("\n  ")
end

#set_note(note) ⇒ Object



85
86
87
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 85

def set_note(note)
  @note = note
end

#with_action(resource, action) ⇒ Object



96
97
98
99
100
101
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 96

def with_action(resource, action)
  api_call_matcher.expected_resource = resource
  api_call_matcher.expected_action = action
  self.with(api_call_matcher)
  self
end

#with_params(expected_params = {}, &block) ⇒ Object



89
90
91
92
93
94
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 89

def with_params(expected_params = {}, &block)
  api_call_matcher.expected_params = expected_params
  api_call_matcher.block = block if block_given?
  self.with(api_call_matcher)
  self
end