From e35f6bb78c45b2c932a96c3f0242a062e9c3d059 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Sun, 15 Jun 2008 13:52:10 -0500 Subject: [PATCH] Creating FSEvents::Event class, mostly to make getting files from the path easier. This is heavily inspired by the Rucola fsevents.rb. --- lib/fsevents/event.rb | 15 +++++++++++++ lib/fsevents/stream.rb | 2 ++ spec/event_spec.rb | 51 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/fsevents/event.rb create mode 100644 spec/event_spec.rb diff --git a/lib/fsevents/event.rb b/lib/fsevents/event.rb new file mode 100644 index 0000000..a8da3c3 --- /dev/null +++ b/lib/fsevents/event.rb @@ -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 \ No newline at end of file diff --git a/lib/fsevents/stream.rb b/lib/fsevents/stream.rb index 7a3de1d..769afe7 100644 --- a/lib/fsevents/stream.rb +++ b/lib/fsevents/stream.rb @@ -1,3 +1,5 @@ +require 'fsevents/event' + module FSEvents class Stream attr_reader :stream diff --git a/spec/event_spec.rb b/spec/event_spec.rb new file mode 100644 index 0000000..716873e --- /dev/null +++ b/spec/event_spec.rb @@ -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