Class: Gimme::GivesClassMethods

Inherits:
BlankSlate show all
Defined in:
lib/gimme/gives_class_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cls) ⇒ GivesClassMethods

Returns a new instance of GivesClassMethods.



5
6
7
8
# File 'lib/gimme/gives_class_methods.rb', line 5

def initialize(cls)
  @cls = cls
  @raises_no_method_error = true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gimme/gives_class_methods.rb', line 10

def method_missing(method, *args, &block)
  cls = @cls
  meta_class = (class << cls; self; end)
  method = ResolvesMethods.new(meta_class,method,args).resolve(@raises_no_method_error)

  Gimme.class_methods.set(cls, method)
  Gimme.stubbings.set(cls, method, args, block)

  #TODO this will be redundantly overwritten
  meta_class.instance_eval do
    define_method method do |*actual_args|
      InvokesSatisfiedStubbing.new(cls).invoke(method, actual_args)
    end
  end

  EnsuresClassMethodRestoration.new(@cls).ensure(method)
end

Instance Attribute Details

#raises_no_method_errorObject

Returns the value of attribute raises_no_method_error.



4
5
6
# File 'lib/gimme/gives_class_methods.rb', line 4

def raises_no_method_error
  @raises_no_method_error
end