Skip to content

Commit

Permalink
Adding FSEvents::Stream.create, which returns a new FSEvents::Stream …
Browse files Browse the repository at this point in the history
…object with the stream created.

I imagine this will be a more popular interface than FSEvents::Stream.new since it removes the step of creating the stream after initialization.
  • Loading branch information
ymendel committed Jun 14, 2008
1 parent 16d7195 commit f1f0f1a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/fsevents/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def startup
start
end

class << self
def create(*args, &block)
stream = new(*args, &block)
stream.create
stream
end
end

def stop
OSX.FSEventStreamStop(stream)
end
Expand Down
51 changes: 50 additions & 1 deletion spec/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe FSEvents::Stream do
before :each do
@path = "/tmp"
@path = '/tmp'
@stream = FSEvents::Stream.new(@path) {}
end

Expand Down Expand Up @@ -267,6 +267,55 @@
end
end

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

describe 'when creating' 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 new, but mocha expecation apparently doesn't support that.
# So instead I stub new for some testing and then have something that actually uses new and sees the callback
# is the expected block.
describe do
before :each do
@stream.stubs(:create)
FSEvents::Stream.stubs(:new).returns(@stream)
end

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

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

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

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

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

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

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

0 comments on commit f1f0f1a

Please sign in to comment.