Skip to content

Commit

Permalink
Merge pull request #205 from nex3/v1.3
Browse files Browse the repository at this point in the history
Don't load an adapter if it can't be required.
  • Loading branch information
thibaudgg committed Apr 11, 2014
2 parents 3a51540 + 80a8627 commit 59a5cf4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/listen/adapter.rb
Expand Up @@ -206,6 +206,8 @@ def self.load_dependent_adapter
return true if @loaded
require adapter_gem
return @loaded = true
rescue LoadError
false
end

# Runs a tests to determine if the adapter can actually pick up
Expand Down
11 changes: 11 additions & 0 deletions spec/listen/adapter_spec.rb
Expand Up @@ -87,12 +87,23 @@
end

describe '.load_dependend_adapter' do
after(:each) { described_class.instance_variable_set('@loaded', nil) }

it 'returns true (success) even if the adapter_gem has already been required' do
described_class.stub(:adapter_gem => 'already_loaded_gem')
described_class.stub(:require => false)

described_class.load_dependent_adapter.should be_true
end

it 'returns false (failure) if the adapter_gem cannot be required' do
described_class.stub(:adapter_gem => 'unloadable_gem')
described_class.stub(:require) do
raise LoadError.new('no such file to load -- unloadable_gem')
end

described_class.load_dependent_adapter.should be_false
end
end

Listen::Adapter::OPTIMIZED_ADAPTERS.each do |adapter|
Expand Down

0 comments on commit 59a5cf4

Please sign in to comment.