Skip to content

Commit

Permalink
Add started? method to adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
Maher4Ever committed May 5, 2012
1 parent 75c811b commit be68aee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/listen/adapter.rb
Expand Up @@ -83,6 +83,14 @@ def stop
@turnstile.signal # ensure no thread is blocked
end

# Returns whether the adapter is statred or not
#
# @return [Boolean] whether the adapter is started or not
#
def started?
@stop.nil? ? false : !@stop
end

# Blocks the main thread until the poll thread
# calls the callback.
#
Expand Down
25 changes: 25 additions & 0 deletions spec/support/adapter_helper.rb
Expand Up @@ -43,6 +43,31 @@ def watch(listener, *paths)
end
end
end

describe '#started?' do
context 'with a new adapter' do
it 'returns false' do
subject.should_not be_started
end
end

context 'with a stopped adapter' do
before { subject.start(false); subject.stop }

it 'returns false' do
subject.should_not be_started
end
end

context 'with a started adapter' do
before { subject.start(false) }
after { subject.start }

it 'returns true' do
subject.should be_started
end
end
end
end

shared_examples_for 'an adapter that call properly listener#on_change' do |*args|
Expand Down

0 comments on commit be68aee

Please sign in to comment.