Class: Gimme::ResolvesMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/gimme/resolves_methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(cls, sym, args = []) ⇒ ResolvesMethods

Returns a new instance of ResolvesMethods.



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

def initialize(cls, sym, args=[])
  @cls = cls
  @sym = sym
  @args = args
end

Instance Method Details

#resolve(raises_no_method_error = true) ⇒ Object



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

def resolve(raises_no_method_error=true)
  @sym = @args.shift if @sym == :send
  if @cls && raises_no_method_error
    if @cls.private_method_defined?(named(@sym))
      raise NoMethodError.new("#{@sym} is a private method of your #{@cls} test double, so stubbing/verifying it
        might not be a great idea. If you want to try to stub or verify this method anyway, then you can
        invoke give! or verify! to suppress this error.")
    elsif !@cls.instance_methods.include?(named(@sym))
      raise NoMethodError.new("Your test double of #{@cls} may not know how to respond to the '#{@sym}' method.
        If you're confident that a real #{@cls} will know how to respond to '#{@sym}', then you can
        invoke give! or verify! to suppress this error.")
    end
  end

  @sym
end