class Object
Public Instance Methods
fake_mode_for(model_name)
click to toggle source
:nocov:
# File lib/artirix_data_models/spec_support/fake_mode.rb, line 2 def fake_mode_for(model_name) before(:each) do config = ArtirixDataModels.configuration # fix in case of SimpleConfig (mocking SimpleConfig with rspec explodes if not) if defined?(SimpleConfig) && config.kind_of?(SimpleConfig::Config) SimpleConfig::Config.class_eval { public :singleton_class } end dfm = config.try(:data_fake_mode) || double allow(dfm).to receive(model_name).and_return(true) allow(config).to receive(:data_fake_mode).and_return(dfm) allow(config).to receive(:debug_model_mode_enabled).and_return(true) end end
given_gateway_config(connection_url = nil)
click to toggle source
:nocov:
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 2 def given_gateway_config(connection_url = nil) connection_url ||= 'http://example.com/other' before(:each) do config = ArtirixDataModels.configuration # fix in case of SimpleConfig (mocking SimpleConfig with rspec explodes if not) if defined?(SimpleConfig) && config.kind_of?(SimpleConfig::Config) SimpleConfig::Config.class_eval { public :singleton_class } end dg = config.try(:data_gateway) || double allow(dg).to receive(:url).and_return(connection_url) allow(config).to receive(:data_gateway).and_return(dg) end end
has_presence_methods?(attributes)
click to toggle source
# File lib/artirix_data_models/spec_support/shared_examples/has_attributes.rb, line 29 def has_presence_methods?(attributes) attributes.reject { |at| subject.respond_to? "#{at}?" }.empty? end
has_private_setters?(attributes)
click to toggle source
# File lib/artirix_data_models/spec_support/shared_examples/has_attributes.rb, line 22 def has_private_setters?(attributes) attributes.reject do |at| setter = "#{at}=" subject.respond_to?(setter, true) && !subject.respond_to?(setter) end.empty? end
has_public_getters?(attributes)
click to toggle source
# File lib/artirix_data_models/spec_support/shared_examples/has_attributes.rb, line 18 def has_public_getters?(attributes) attributes.reject { |at| subject.respond_to? at }.empty? end
mock_gateway_delete_not_found_response(**params)
click to toggle source
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 123 def mock_gateway_delete_not_found_response(**params) mock_gateway_not_found_response method: :delete, **params end
mock_gateway_delete_response(**params)
click to toggle source
DELETE
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 119 def mock_gateway_delete_response(**params) mock_gateway_response method: :delete, **params end
mock_gateway_get_not_found_response(**params)
click to toggle source
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 96 def mock_gateway_get_not_found_response(**params) mock_gateway_not_found_response method: :get, **params end
mock_gateway_get_response(**params)
click to toggle source
GET
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 92 def mock_gateway_get_response(**params) mock_gateway_response method: :get, **params end
mock_gateway_not_found_response(method:, path:, body: nil, json_body: true, timeout: nil, authorization_bearer: nil, authorization_token_hash: nil, gateway: nil, headers: nil)
click to toggle source
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 60 def mock_gateway_not_found_response(method:, path:, body: nil, json_body: true, timeout: nil, authorization_bearer: nil, authorization_token_hash: nil, gateway: nil, headers: nil) gateway ||= ArtirixDataModels::DAORegistry.gateway params_hash = { path: path, body: body, json_body: json_body, timeout: timeout, authorization_bearer: authorization_bearer, authorization_token_hash: authorization_token_hash, headers: headers } allow(gateway).to receive(:perform).with(method, params_hash).and_raise ArtirixDataModels::DataGateway::NotFound # check with body already parsed unless body.nil? body = body.kind_of?(String) ? body : body.to_json allow(gateway).to receive(:perform).with(method, params_hash.merge(body: body)).and_raise ArtirixDataModels::DataGateway::NotFound end end
mock_gateway_post_not_found_response(**params)
click to toggle source
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 105 def mock_gateway_post_not_found_response(**params) mock_gateway_not_found_response method: :post, **params end
mock_gateway_post_response(**params)
click to toggle source
POST
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 101 def mock_gateway_post_response(**params) mock_gateway_response method: :post, **params end
mock_gateway_put_not_found_response(**params)
click to toggle source
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 114 def mock_gateway_put_not_found_response(**params) mock_gateway_not_found_response method: :put, **params end
mock_gateway_put_response(**params)
click to toggle source
PUT
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 110 def mock_gateway_put_response(**params) mock_gateway_response method: :put, **params end
mock_gateway_response(response:, method:, path:, body: nil, json_body: true, timeout: nil, authorization_bearer: nil, authorization_token_hash: nil, gateway: nil, headers: nil, expect: false, &block)
click to toggle source
returns the result of ‘expect(gateway).to EXPECTATION` or `allow(gateway).to EXPECTATION` yields EXPECTATION so it can be tuned, for example to add a `at_most` call to the chain
# File lib/artirix_data_models/spec_support/gateway_mock.rb, line 21 def mock_gateway_response(response:, method:, path:, body: nil, json_body: true, timeout: nil, authorization_bearer: nil, authorization_token_hash: nil, gateway: nil, headers: nil, expect: false, &block) gateway ||= ArtirixDataModels::DAORegistry.gateway callable = block_given? ? block : ->(x) { x } unless body.nil? || !json_body body = body.kind_of?(String) ? body : body.to_json end params_hash = { path: path, body: body, json_body: json_body, timeout: timeout, authorization_bearer: authorization_bearer, authorization_token_hash: authorization_token_hash, headers: headers } what_to_allow = callable.call(receive(:perform).with(method, params_hash).and_return(response)) if expect expect(gateway).to what_to_allow else allow(gateway).to what_to_allow end end