Class: Lebowski::RSpec::Matchers::HasObjectFunction

Inherits:
MatchSupporter show all
Defined in:
lib/lebowski/rspec/matchers/match_supporters/has_object_function.rb

Instance Attribute Summary

Attributes inherited from MatchSupporter

#result

Instance Method Summary collapse

Methods inherited from MatchSupporter

#initialize

Constructor Details

This class inherits a constructor from Lebowski::RSpec::Matchers::MatchSupporter

Instance Method Details

#has_match?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lebowski/rspec/matchers/match_supporters/has_object_function.rb', line 12

def has_match?()
  
  return false if @args.length == 0 
  
  #
  # Note: If the method name is "test" then trying to invoke
  # a method with name "test" on the given object will always
  # fail whenever __send__ is used. There appears to be an
  # actual method called test that belongs to a Ruby object.
  #
  method_name = obj_property(@expected)
  
  ret_val = nil
  invoked_method = false
  
  # Try with arguments
  begin
    args = @args.clone; args.pop
    ret_val = @object.__send__(method_name, *args)
    invoked_method = true
  rescue NoMethodError => nme
  rescue ArgumentError => ae
  end
  
  # Try with no arguments
  begin
    if not invoked_method
      ret_val = @object.__send__(method_name)
      invoked_method = true
    end
  rescue NoMethodError => nme
  rescue ArgumentError => ae
  end
    
  return false if not invoked_method
  
  operator = @args[@args.length - 1]
  if operator.kind_of? Lebowski::RSpec::Operators::Operator
    @result = operator.evaluate(ret_val) 
    return true
  end
  
  @result = Lebowski::RSpec::Util.match?(@args[@args.length - 1], ret_val)
  
  return true
  
end