Module: Stubberry

Defined in:
lib/stubberry/active_record.rb,
lib/stubberry.rb,
lib/stubberry/object.rb,
lib/stubberry/version.rb,
lib/stubberry/assertions.rb

Overview

this module provide two methods for active record classes to easily stub any record attributes and methods disregarding the way record was obtained inside the yielding block, you just need an id.

i.e. alternative way of dealing with any record with id could be stub of the specific method like where or find with a given set of params e.t.c. that’s a very error prone approach, with stub_orm_* methods we do not care about the way object was obtained as long as after_find callback was executed

Defined Under Namespace

Modules: ActiveRecord, Assertions, Object Classes: Error

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.__define_method_mimic_replacement(object, method) ⇒ Object



11
12
13
14
15
# File 'lib/stubberry.rb', line 11

def self.__define_method_mimic_replacement(object, method)
  return unless __is_a_method_mimic?(object, method)

  object.define_singleton_method(method) { |*args, **kargs, &block| super(*args, **kargs, &block) }
end

.__is_a_method_mimic?(object, method) ⇒ Boolean

object responds to ‘method’ but, the are no such method among methods, i.e. it’s run through a method_missing

Returns:

  • (Boolean)


19
20
21
# File 'lib/stubberry.rb', line 19

def self.__is_a_method_mimic?(object, method)
  object.respond_to?(method) && !object.methods.map(&:to_s).include?(method.to_s)
end