Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/caricature/core_ext/object.rb
Instance Method Summary collapse
-
#clr_type? ⇒ Boolean
returns whether this object is a clr_type.
-
#define_cmethod(name, &blk) ⇒ Object
defines a class method on an object.
- #isolate(name = nil, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new, &block) ⇒ Object (also: #when_receiving, #mock, #stub)
-
#pass_block(*ags, &b) ⇒ Object
Sets up arguments for the block that is being passed into the isolated method call.
-
#raise_error(*args) ⇒ Object
tell the expectation it needs to raise an error with the specified arguments.
-
#returns(value = nil, &b) ⇒ Object
tell the expectation it needs to return this value or the value returned by the block you provide to this method.
-
#super_after(&b) ⇒ Object
tell the expectation it needs to call the super after the expecation execution.
-
#super_before(&b) ⇒ Object
tell the expectation it needs to call the super before the expectation exectution.
-
#to_clr_type ⇒ Object
returns the clr type of this object if any.
-
#with(*ags, &b) ⇒ Object
tell the expectation which arguments it needs to respond to there is a magic argument here
anywhich configures the expectation to respond to any arguments.
Instance Method Details
#clr_type? ⇒ Boolean
returns whether this object is a clr_type. if it has a CLR type in one of its ancestors
5 6 7 |
# File 'lib/caricature/core_ext/object.rb', line 5 def clr_type? self.class.clr_type? end |
#define_cmethod(name, &blk) ⇒ Object
defines a class method on an object
15 16 17 18 19 20 |
# File 'lib/caricature/core_ext/object.rb', line 15 def define_cmethod(name, &blk) ( class << self; self; end).instance_eval { define_method name, &blk } end |
#isolate(name = nil, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new, &block) ⇒ Object Also known as: when_receiving, mock, stub
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/caricature/core_ext/object.rb', line 22 def isolate(name=nil, recorder = Caricature::MethodCallRecorder.new, expectations = Caricature::Expectations.new, &block) iso = Caricature::Isolation.for(self, recorder, expectations) return iso unless name if block if block.arity > 0 @expectation = iso.when_receiving(name, &block) else @expectation = iso.when_receiving(name) instance_eval &block end end iso end |
#pass_block(*ags, &b) ⇒ Object
Sets up arguments for the block that is being passed into the isolated method call
55 56 57 58 |
# File 'lib/caricature/core_ext/object.rb', line 55 def pass_block(*ags, &b) @expectation.pass_block(*ags, &b) self end |
#raise_error(*args) ⇒ Object
tell the expectation it needs to raise an error with the specified arguments
61 62 63 64 |
# File 'lib/caricature/core_ext/object.rb', line 61 def raise_error(*args) @expectation.raise(*args) self end |
#returns(value = nil, &b) ⇒ Object
tell the expectation it needs to return this value or the value returned by the block you provide to this method.
49 50 51 52 |
# File 'lib/caricature/core_ext/object.rb', line 49 def returns(value=nil, &b) @expectation.return(value, &b) self end |
#super_after(&b) ⇒ Object
tell the expectation it needs to call the super after the expecation execution
73 74 75 76 |
# File 'lib/caricature/core_ext/object.rb', line 73 def super_after(&b) @expectation.super_after &b self end |
#super_before(&b) ⇒ Object
tell the expectation it needs to call the super before the expectation exectution
67 68 69 70 |
# File 'lib/caricature/core_ext/object.rb', line 67 def super_before(&b) @expectation.super_before(&b) self end |
#to_clr_type ⇒ Object
returns the clr type of this object if any
10 11 12 |
# File 'lib/caricature/core_ext/object.rb', line 10 def to_clr_type self.class.to_clr_type end |
#with(*ags, &b) ⇒ Object
tell the expectation which arguments it needs to respond to there is a magic argument here any which configures the expectation to respond to any arguments
42 43 44 45 |
# File 'lib/caricature/core_ext/object.rb', line 42 def with(*ags, &b) @expectation.with(*ags, &b) self end |