Class: On::TestHelper::Recorder

Inherits:
Object
  • Object
show all
Defined in:
lib/on/test_helper.rb

Overview

Record callbacks.

Defined Under Namespace

Classes: Callback

Instance Method Summary collapse

Constructor Details

#initializeRecorder

Returns a new instance of Recorder.



59
60
61
62
# File 'lib/on/test_helper.rb', line 59

def initialize
  @block      = false
  @callbacks  = []
end

Instance Method Details

#block_called?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/on/test_helper.rb', line 64

def block_called?
  @block
end

#empty?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/on/test_helper.rb', line 68

def empty?
  @callbacks.empty?
end

#last_recordObject

Pops the last recorded recorded.



73
74
75
# File 'lib/on/test_helper.rb', line 73

def last_record
  @callbacks.pop
end

#record_allObject

Records block and all defined callbacks.



78
79
80
81
82
83
# File 'lib/on/test_helper.rb', line 78

def record_all
  proc do |on|
    record_block
    record_callback(on, *on.callbacks)
  end
end

#record_blockObject

Records a block.

recorder = Recorder.new
On.new(:success) do |callback|
  recorder.record_block
  callback.on :success do
    # assert...
  end
end

assert recorder.block_called?


96
97
98
# File 'lib/on/test_helper.rb', line 96

def record_block
  @block = true
end

#record_callback(on, *names) ⇒ Object

Records a single callback.



101
102
103
104
105
106
107
# File 'lib/on/test_helper.rb', line 101

def record_callback(on, *names)
  names.each do |name|
    on.on name do |*args|
      @callbacks << Callback.new(name, args)
    end
  end
end

#to_procObject

Short-hand for &recorder.record_all.



110
111
112
# File 'lib/on/test_helper.rb', line 110

def to_proc
  record_all
end