Sha256: e8bb0fd1bbe151155e334535a17c27115b95aaa23b03ebfdc8adbe895848784f

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module ActiveMocker
  module MockableMethod
    private

    def __am_raise_not_mocked_error(method:, caller:, type:)
      variable_name, klass, method_type = if is_a?(Relation)
                                            klass = self.class.name.underscore.split("/").first
                                            ["#{klass}_relation", klass.camelize, :scopes]
                                          elsif type == "#"
                                            klass = self.class.name
                                            ["#{klass.underscore}_record", klass, :instance_methods]
                                          else
                                            [name, name, :class_methods]
                                          end

      message = <<-ERROR.strip_heredoc
        Unknown implementation for mock method: #{variable_name}.#{method}
        Stub method to continue.

        RSpec:
          allow(
            #{variable_name}
          ).to receive(:#{method}).and_return(:some_expected_result)

        OR Whitelist the method as safe to copy/run in the context of ActiveMocker (requires mock rebuild)
        # ActiveMocker.safe_methods #{method_type}: [:#{method}]
        class #{klass.gsub("Mock", "")} < ActiveRecord::Base
        end
      ERROR

      raise NotImplementedError, message, caller
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_mocker-2.5.4 lib/active_mocker/mock/mockable_method.rb