Merge pull request #66 from johnbintz/better-class-name-generation

Support for dashes in guard names
This commit is contained in:
Thibaud Guillaume-Gentil 2011-05-24 01:08:29 -07:00
commit ce2a5c5980
2 changed files with 12 additions and 1 deletions

View File

@ -82,7 +82,7 @@ module Guard
def get_guard_class(name) def get_guard_class(name)
try_to_load_gem name try_to_load_gem name
self.const_get(self.constants.find{ |klass_name| klass_name.to_s.downcase == name.downcase }) self.const_get(self.constants.find{ |klass_name| klass_name.to_s.downcase == name.downcase.gsub('-', '') })
rescue TypeError rescue TypeError
UI.error "Could not find load find gem 'guard-#{name}' or find class Guard::#{name}" UI.error "Could not find load find gem 'guard-#{name}' or find class Guard::#{name}"
end end

View File

@ -57,6 +57,17 @@ describe Guard do
end end
end end
context 'with a name with dashes' do
it "returns the Guard class" do
Guard.should_receive(:try_to_load_gem) { |classname|
classname.should == 'dashed-class-name'
class Guard::DashedClassName
end
}
Guard.get_guard_class('dashed-class-name').should == Guard::DashedClassName
end
end
context 'with an inline Guard class' do context 'with an inline Guard class' do
it 'returns the Guard class' do it 'returns the Guard class' do
module Guard module Guard