Class: Spec::Matchers::Observer
- Inherits:
-
Object
- Object
- Spec::Matchers::Observer
- Defined in:
- lib/appswarm/cross_spectool.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
attr_accessor :ok.
Instance Method Summary collapse
-
#called?(count = 0, sym = :times) ⇒ Boolean
@ok==true.
-
#initialize(object, methodName) ⇒ Observer
constructor
A new instance of Observer.
-
#isCalled ⇒ Object
@ok==false.
- #isNotCalled ⇒ Object
- #run ⇒ Object
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
#count ⇒ Object
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
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 |
#isCalled ⇒ Object
@ok==false
112 113 114 115 |
# File 'lib/appswarm/cross_spectool.rb', line 112 def isCalled @count>0 #@ok==true end |
#isNotCalled ⇒ Object
108 109 110 111 |
# File 'lib/appswarm/cross_spectool.rb', line 108 def isNotCalled @count==0 # @ok==false end |
#run ⇒ Object
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 |