Class: Lemon::CoverUnit

Inherits:
Object
  • Object
show all
Defined in:
lib/lemon/coverage/cover_unit.rb

Overview

Unit of coverage, ecapsulates a method, it’s characteristics and a flag as to whether it has been covered or not.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, method, props = {}) ⇒ CoverUnit

Returns a new instance of CoverUnit.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lemon/coverage/cover_unit.rb', line 14

def initialize(target, method, props={})
  @target    = target
  @method    = method.to_sym
  @covered   = props[:covered]
  @singleton = props[:singleton] ? true : false

  if @singleton
    @private = !@target.public_methods.find{ |m| m.to_sym == @method }
  else
    @private = !@target.public_instance_methods.find{ |m| m.to_sym == @method }
  end
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/lemon/coverage/cover_unit.rb', line 9

def method
  @method
end

#singletonObject (readonly)

Returns the value of attribute singleton.



11
12
13
# File 'lib/lemon/coverage/cover_unit.rb', line 11

def singleton
  @singleton
end

#targetObject (readonly)

Returns the value of attribute target.



7
8
9
# File 'lib/lemon/coverage/cover_unit.rb', line 7

def target
  @target
end

Instance Method Details

#<=>(other) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/lemon/coverage/cover_unit.rb', line 90

def <=>(other)
  c = (target.name <=> other.target.name)
  return c unless c == 0
  return -1 if singleton  && !other.singleton
  return  1 if !singleton && other.singleton
  method.to_s <=> other.method.to_s
end

#covered?Boolean

Marked as covered?

Returns:

  • (Boolean)


37
38
39
# File 'lib/lemon/coverage/cover_unit.rb', line 37

def covered?
  @covered
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
78
# File 'lib/lemon/coverage/cover_unit.rb', line 72

def eql?(other)
  return false unless Unit === other
  return false unless target == other.target
  return false unless method == other.method
  return false unless singleton == other.singleton
  return true
end

#hashObject



53
54
55
# File 'lib/lemon/coverage/cover_unit.rb', line 53

def hash
  @target.hash ^ @method.hash ^ singleton.hash
end

#inspectObject



83
84
85
# File 'lib/lemon/coverage/cover_unit.rb', line 83

def inspect
  "#{target}#{singleton? ? '.' : '#'}#{method}"
end

#private?Boolean

Method access is private or protected?

Returns:

  • (Boolean)


30
31
32
# File 'lib/lemon/coverage/cover_unit.rb', line 30

def private?
  @private
end

#singleton?Boolean Also known as: class_method?

Returns:

  • (Boolean)


44
45
46
# File 'lib/lemon/coverage/cover_unit.rb', line 44

def singleton?
  @singleton
end

#to_sObject Also known as: to_str



60
61
62
63
64
65
66
# File 'lib/lemon/coverage/cover_unit.rb', line 60

def to_s
  if singleton?
    "#{@target}.#{@method}"
  else
    "#{@target}##{@method}"
  end
end