Class: Spec::Matchers::Observer

Inherits:
Object
  • Object
show all
Defined in:
lib/appswarm/cross_spectool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, methodName) ⇒ Observer

Returns a new instance of Observer.



85
86
87
88
89
90
# File 'lib/appswarm/cross_spectool.rb', line 85

def initialize(object,methodName)
  @methodName=methodName
  @object=object
  #@ok=false
  @count=0
end

Instance Attribute Details

#countObject

attr_accessor :ok



84
85
86
# File 'lib/appswarm/cross_spectool.rb', line 84

def count
  @count
end

Instance Method Details

#called?(count = 0, sym = :times) ⇒ Boolean

@ok==true

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
# File 'lib/appswarm/cross_spectool.rb', line 116

def called?(count=0,sym=:times)
  case sym
    when :times
      @count>count
    else
      raise "Unknown symbol"
  end
end

#isCalledObject

@ok==false



112
113
114
115
# File 'lib/appswarm/cross_spectool.rb', line 112

def isCalled
  @count>0
  #@ok==true
end

#isNotCalledObject



108
109
110
111
# File 'lib/appswarm/cross_spectool.rb', line 108

def isNotCalled
  @count==0
  # @ok==false
end

#runObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/appswarm/cross_spectool.rb', line 91

def run
  method=@object.method(@methodName)
  this=self
  object=@object
  @object.class.send(:define_method,@methodName) {|*s|
    if self==object
      #this.ok=true
      this.count+=1
      puts "MUH"
    end
    method.call(*s)
  } 
  yield
  @object.class.send(:define_method,@methodName,method)
  #@ok
  called?
end