Class: OSX::NSObject

Inherits:
Object show all
Defined in:
lib/rucola/test_helper.rb,
lib/rucola/rucola_support/core_ext/objc/nsobject.rb,
lib/rucola/test_case.rb

Direct Known Subclasses

Rucola::PluginRunner, Rucola::RCController

Class Method Summary collapse

Class Method Details

._inherited_before_rucolaObject



5
# File 'lib/rucola/rucola_support/core_ext/objc/nsobject.rb', line 5

alias_method :_inherited_before_rucola, :inherited

.defined_ib_outletsObject

An array of defined ib_outlets.

Only used in test cases.



6
7
8
# File 'lib/rucola/test_case.rb', line 6

def defined_ib_outlets
  @defined_ib_outlets ||= []
end

.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.bar
      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

Yields:

  • (obj)


61
62
63
64
65
66
67
# File 'lib/rucola/test_helper.rb', line 61

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



34
35
36
37
# File 'lib/rucola/test_helper.rb', line 34

def self.expects_alloc_init_returns(mock)
  mock.expects(:init).returns(mock)
  self.expects(:alloc).returns(mock)
end

.ib_outlets(*outlets) ⇒ Object Also known as: ib_outlet

Override ib_outlets so we can store which ones need to be defined.

Only used in test cases.



13
14
15
# File 'lib/rucola/test_case.rb', line 13

def ib_outlets(*outlets)
  defined_ib_outlets.concat(outlets.flatten)
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