Navigation Menu

Skip to content

Commit

Permalink
Adding FSEvents::Stream.watch, which returns a newly created FSEvents…
Browse files Browse the repository at this point in the history
…::Stream object and starts it up.

This should be the main popular interface since it goes directly from path, options, and callback directly to an operating stream.
  • Loading branch information
ymendel committed Jun 14, 2008
1 parent f1f0f1a commit d694451
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/fsevents/stream.rb
Expand Up @@ -57,6 +57,12 @@ def create(*args, &block)
stream.create
stream
end

def watch(*args, &block)
stream = create(*args, &block)
stream.startup
stream
end
end

def stop
Expand Down
49 changes: 49 additions & 0 deletions spec/stream_spec.rb
Expand Up @@ -379,6 +379,55 @@
end
end

it 'should watch' do
FSEvents::Stream.should respond_to(:watch)
end

describe 'when watching' do
before :each do
@other_path = '/other/path'
end

# This is just here for organization and use of the before block.
# I'd like to ensure that the block is passed to create, but mocha expecation apparently doesn't support that.
# So instead I stub create for some testing and then have something that actually uses create and sees the callback
# is the expected block.
describe do
before :each do
@stream.stubs(:startup)
FSEvents::Stream.stubs(:create).returns(@stream)
end

it 'should accept arguments and a block' do
lambda { FSEvents::Stream.watch(@path, @other_path, :flags => 27) {} }.should_not raise_error(ArgumentError)
end

it 'should create a stream object' do
FSEvents::Stream.expects(:create).returns(@stream)
FSEvents::Stream.watch(@path, @other_path, :flags => 27) {}
end

it 'should pass the arguments to the creation' do
FSEvents::Stream.expects(:create).with(@path, @other_path, :flags => 27).returns(@stream)
FSEvents::Stream.watch(@path, @other_path, :flags => 27) {}
end

it 'should start up the resultant stream object' do
@stream.expects(:startup)
FSEvents::Stream.watch(@path, @other_path, :flags => 27) {}
end

it 'should return the stream object' do
FSEvents::Stream.watch.should == @stream
end
end

it 'should pass the callback block' do
callback = lambda {}
FSEvents::Stream.watch(@path, @other_path, :flags => 27, &callback).callback.should == callback
end
end

it 'should stop itself' do
@stream.should respond_to(:stop)
end
Expand Down

0 comments on commit d694451

Please sign in to comment.