Skip to content

Commit

Permalink
Creating FSEvents::Event class, mostly to make getting files from the…
Browse files Browse the repository at this point in the history
… path easier.

This is heavily inspired by the Rucola fsevents.rb.
  • Loading branch information
ymendel committed Jun 15, 2008
1 parent 591e5bd commit e35f6bb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/fsevents/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module FSEvents
class Event
attr_reader :id, :path, :stream

def initialize(id, path, stream)
@id = id
@path = path
@stream = stream
end

def files
Dir["#{path}/*"]
end
end
end
2 changes: 2 additions & 0 deletions lib/fsevents/stream.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'fsevents/event'

module FSEvents
class Stream
attr_reader :stream
Expand Down
51 changes: 51 additions & 0 deletions spec/event_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require File.dirname(__FILE__) + '/spec_helper.rb'

describe FSEvents::Event do
before :each do
@id = stub('id')
@path = '.'
@stream = stub('stream')

@event = FSEvents::Event.new(@id, @path, @stream)
end

describe 'when initialized' do
it 'should accept an id, path, and stream' do
lambda { FSEvents::Event.new(@id, @path, @stream) }.should_not raise_error(ArgumentError)
end

it 'should require a stream' do
lambda { FSEvents::Event.new(@id, @path) }.should raise_error(ArgumentError)
end

it 'should require a path' do
lambda { FSEvents::Event.new(@id) }.should raise_error(ArgumentError)
end

it 'should require an id' do
lambda { FSEvents::Event.new }.should raise_error(ArgumentError)
end

it 'should store the id' do
FSEvents::Event.new(@id, @path, @stream).id.should == @id
end

it 'should store the path' do
FSEvents::Event.new(@id, @path, @stream).path.should == @path
end

it 'should store the stream' do
FSEvents::Event.new(@id, @path, @stream).stream.should == @stream
end
end

it 'should list files' do
@event.should respond_to(:files)
end

describe 'listing files' do
it 'should get files from the path' do
@event.files.sort.should == Dir["#{@path}/*"].sort
end
end
end

0 comments on commit e35f6bb

Please sign in to comment.