Class: OSX::NSObject
- Inherits:
-
Object
- Object
- OSX::NSObject
- Defined in:
- lib/rucola/test_helper.rb,
lib/rucola/rucola_support/core_ext/objc/nsobject.rb
Direct Known Subclasses
Class Method Summary collapse
- ._inherited_before_rucola ⇒ Object
-
.during_init {|obj| ... } ⇒ Object
A Mocha helper method which allocs an instance, yields it and then calls init.
-
.expects_alloc_init_returns(mock) ⇒ Object
A Mocha helper method which allows to stub alloc.init and return a mock.
- .inherited(subclass) ⇒ Object
Class Method Details
._inherited_before_rucola ⇒ Object
5 |
# File 'lib/rucola/rucola_support/core_ext/objc/nsobject.rb', line 5 alias_method :_inherited_before_rucola, :inherited |
.during_init {|obj| ... } ⇒ Object
A Mocha helper method which allocs an instance, yields it and then calls init.
class Monkey < OSX::NSObject
def init
if super_init
self.foo
self.
return self
end
end
end
it "should alloc, yield and return an instance" do
obj = OSX::Monkey.during_init do |instance|
instance.expects(:foo)
instance.expects(:bar)
end
p obj # => #<Monkey:0x1a7566 class='Monkey' id=0x1b30a70>
end
Results in: 1 tests, 2 assertions, 0 failures, 0 errors
49 50 51 52 53 54 55 |
# File 'lib/rucola/test_helper.rb', line 49 def self.during_init(&block) obj = self.alloc yield obj res = obj.init warn " warning: #{self.class.name}#init did not return an instance." if res.nil? res end |
.expects_alloc_init_returns(mock) ⇒ Object
A Mocha helper method which allows to stub alloc.init and return a mock.
it "should init and return an instance" do
obj_mock = mock("NSObject mock")
OSX::NSObject.expects_alloc_init_returns(obj_mock) # performs 2 assertions
OSX::NSObject.alloc.init.should == obj_mock
end
Results in: 1 tests, 3 assertions, 0 failures, 0 errors
22 23 24 25 |
# File 'lib/rucola/test_helper.rb', line 22 def self.expects_alloc_init_returns(mock) mock.expects(:init).returns(mock) self.expects(:alloc).returns(mock) end |
.inherited(subclass) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rucola/rucola_support/core_ext/objc/nsobject.rb', line 7 def inherited(subclass) # First let RubyCocoa do it's magic! _inherited_before_rucola(subclass) # We only want to mixin modules into subclasses of classes # that start with 'Rucola::RC'. class_prefix = subclass.superclass.name.to_s[0..9] if class_prefix == 'Rucola::RC' subclass.class_eval do include Rucola::InitializeHooks include Rucola::Notifications end end end |