Module: HammerCLIForeman::Testing::APIExpectations
- Defined in:
- lib/hammer_cli_foreman/testing/api_expectations.rb
Defined Under Namespace
Modules: ExpectationExtensions Classes: APICallMatcher, APIExpectationsDecorator, FakeApiConnection, TestAuthenticator
Class Method Summary collapse
Instance Method Summary collapse
- #api_calls ⇒ Object
- #api_connection(options = {}, version = FOREMAN_VERSION) ⇒ Object
- #api_expects(resource = nil, action = nil, note = nil, &block) ⇒ Object
- #api_expects_no_call ⇒ Object
- #api_expects_search(resource = nil, search_options = {}, note = nil) ⇒ Object
- #index_response(items, options = {}) ⇒ Object
Class Method Details
.api_calls ⇒ Object
5 6 7 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 5 def self.api_calls @api_calls ||= [] end |
Instance Method Details
#api_calls ⇒ Object
168 169 170 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 168 def api_calls HammerCLIForeman::Testing::APIExpectations.api_calls end |
#api_connection(options = {}, version = FOREMAN_VERSION) ⇒ Object
158 159 160 161 162 163 164 165 166 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 158 def api_connection(={}, version = FOREMAN_VERSION) FakeApiConnection.new({ :uri => 'https://test.org', :apidoc_cache_dir => "test/data/#{version}", :apidoc_cache_name => 'foreman_api', :authenticator => TestAuthenticator.new('admin', 'changeme'), :dry_run => true }.merge()) end |
#api_expects(resource = nil, action = nil, note = nil, &block) ⇒ Object
172 173 174 175 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 172 def api_expects(resource=nil, action=nil, note=nil, &block) api_calls << [resource, action] APIExpectationsDecorator.new.expects_call(resource, action, note, &block) end |
#api_expects_no_call ⇒ Object
177 178 179 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 177 def api_expects_no_call APIExpectationsDecorator.new.expects_no_call end |
#api_expects_search(resource = nil, search_options = {}, note = nil) ⇒ Object
181 182 183 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 181 def api_expects_search(resource=nil, ={}, note=nil) APIExpectationsDecorator.new.expects_search(resource, , note) end |
#index_response(items, options = {}) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/hammer_cli_foreman/testing/api_expectations.rb', line 185 def index_response(items, ={}) cnt = if items.is_a?(Hash) items.keys.count else items.length end { "total" => .fetch(:total, cnt), "subtotal" => .fetch(:subtotal, cnt), "page" => .fetch(:page, 1), "per_page" => .fetch(:per_page, cnt), "search" => "", "sort" => { "by" => nil, "order" => nil }, "results" => items } end |