Class: Dilation::TestSupport::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/dilation/test_support/handler.rb

Overview

A handler that can be used in tests to confirm that events are hooked up

Examples:

Rspec example

describe "Example" do
  let(:handler) { Dilation::TestSupport::Handler.new }
  subject { MyCoreBasedClass.new }

  it "triggers handler" do
    subject.listen_for :tick, handler
    subject.tick
    handler.should be_triggered
  end
end

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHandler

Returns a new instance of Handler.



22
23
24
# File 'lib/dilation/test_support/handler.rb', line 22

def initialize
  @count = 0
end

Instance Attribute Details

#countNumber (readonly)

Returns the number of times triggered.

Returns:

  • (Number)

    the number of times triggered



20
21
22
# File 'lib/dilation/test_support/handler.rb', line 20

def count
  @count
end

Instance Method Details

#callNumber

Note:

increments the counter

Trigger this handler

Returns:

  • (Number)

    the new count



30
31
32
# File 'lib/dilation/test_support/handler.rb', line 30

def call
  @count += 1
end

#triggered?Boolean

Returns true if this handler has been called.

Returns:

  • (Boolean)

    true if this handler has been called



35
36
37
# File 'lib/dilation/test_support/handler.rb', line 35

def triggered?
  @count > 0
end