Skip to content
Browse files

Added Event class to hook framework

  • Loading branch information...
1 parent 8ee8b59 commit c079fb5a63ffe29485ac0dee589b1c055725208c @avdi committed Nov 29, 2008
Showing with 25 additions and 0 deletions.
  1. +1 −0 lib/hookr.rb
  2. +24 −0 spec/hookr_spec.rb
View
1 lib/hookr.rb
@@ -184,6 +184,7 @@ def call(source)
# Represents an event triggering callbacks
Event = Struct.new(:source, :name, :arguments) do
+
# Convert to arguments for a callback of the given arity
def to_args(arity)
case arity
View
24 spec/hookr_spec.rb
@@ -334,7 +334,31 @@
@other = Hookr::Callback.new(:cb1, 2)
(@it <=> @other).should == 0
end
+end
+
+describe Hook::BlockCallback do
+ before :each do
+ @handle = :foo
+ @sensor = stub("Sensor")
+ @index = 1
+ @source = stub("Source")
+ @name = :we_get_signal!
+ @arguments = []
+ @event = stub("Event")
+ end
+ describe "with a no-param block" do
+ before :each do
+ @block = stub("Block", :arity => 0, :call => nil)
+ @it = Hookr::BlockCallback.new(@handle, @block, @index)
+ end
+
+ it "should take 0 args from event and call block with no args" do
+ @event.should_receive(:to_args).with(0).and_return([])
+ @block.should_receive(:call).with(nothing)
+ @it.call(@event)
+ end
+ end
end
describe Hookr::Event do

0 comments on commit c079fb5

Please sign in to comment.
Something went wrong with that request. Please try again.