diff --git a/lib/fsevents/stream.rb b/lib/fsevents/stream.rb index 0dcee51..51e597b 100644 --- a/lib/fsevents/stream.rb +++ b/lib/fsevents/stream.rb @@ -1,11 +1,13 @@ module FSEvents class Stream attr_reader :stream - attr_reader :allocator, :context, :paths, :since, :latency, :flags + attr_reader :allocator, :context, :paths, :since, :latency, :flags, :callback class StreamError < StandardError; end - def initialize(*paths) + def initialize(*paths, &callback) + @callback = callback + options = {} options = paths.pop if paths.last.is_a?(Hash) diff --git a/spec/stream_spec.rb b/spec/stream_spec.rb index 675c172..31651e4 100644 --- a/spec/stream_spec.rb +++ b/spec/stream_spec.rb @@ -16,12 +16,16 @@ OSX.stubs(:FSEventStreamCreate).returns(@stream) end - it 'should accept a path' do - lambda { FSEvents::Stream.new(@path) }.should_not raise_error(ArgumentError) + it 'should accept a path and callback block' do + lambda { FSEvents::Stream.new(@path) {} }.should_not raise_error(ArgumentError) end it 'should not require a path' do - lambda { FSEvents::Stream.new }.should_not raise_error(ArgumentError) + lambda { FSEvents::Stream.new() {} }.should_not raise_error(ArgumentError) + end + + it 'should not require a callback block' do + lambda { FSEvents::Stream.new(@path) }.should_not raise_error(ArgumentError) end it 'should accept a hash of options' do @@ -44,6 +48,11 @@ lambda { FSEvents::Stream.new(@path, '/other/path', :flags => 27) }.should_not raise_error end + it 'should store the callback block' do + callback = lambda {} + FSEvents::Stream.new(@path, &callback).callback.should == callback + end + describe 'handling options' do before :each do @options = {}