Module: CrossStub::ClassMethods

Defined in:
lib/cross-stub.rb

Instance Method Summary collapse

Instance Method Details

#xstub(*args, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/cross-stub.rb', line 63

def xstub(*args, &block)
  if args[-1].is_a?(::Hash) && args[-1][:instance]
    raise ModuleCannotBeInstantiatedError if self.class == Module
    CrossStub.apply(
      :instance,                      # stubbing for instance
      self,                           # the class to action on
      '%s#instance' % self,           # cache key (storing of stubbing info for other process)
      args.size>1 ? args[0..-2] : [], # stubbing arguments
      &block                          # any other more complex stubbing arguments
    )
  else
    CrossStub.apply(
      :class,    # stubbing for class/module
      self,      # the class to action on
      "#{self}", # cache key (storing of stubbing info for other process)
      args,      # stubbing arguments
      &block     # any other more complex stubbing arguments
    )
  end
end