adding support for inline classes

This commit is contained in:
Jeff Sacks 2011-04-21 16:39:46 -05:00
parent d329e4e3b0
commit a0b6ecacdb
2 changed files with 28 additions and 8 deletions

View File

@ -83,10 +83,15 @@ module Guard
end
def get_guard_class(name)
require "guard/#{name.downcase}"
try_to_load_gem name
self.const_get(self.constants.find{|klass_name| klass_name.to_s.downcase == name.downcase })
rescue TypeError
UI.error "Could not find load find gem 'guard-#{name}' or find class Guard::#{name}"
end
def try_to_load_gem(name)
Kernel.require "guard/#{name.downcase}"
rescue LoadError
UI.error "Could not find gem 'guard-#{name}', please add it in your Gemfile."
end
def locate_guard(name)

View File

@ -30,15 +30,30 @@ describe Guard do
end
describe ".get_guard_class" do
it "should return Guard::RSpec" do
Guard.get_guard_class('rspec').should == Guard::RSpec
it "should report an error if the class is not found" do
::Guard::UI.should_receive(:error)
Guard.get_guard_class('notAGuardClass')
end
context 'loaded some nested classes' do
it "should return Guard::RSpec" do
require 'guard/rspec'
Guard::RSpec.class_eval('class NotGuardClass; end')
Guard.get_guard_class('rspec').should == Guard::RSpec
it "should find and return loaded class" do
Kernel.should_receive(:require) { |file_name|
file_name.should == 'guard/classname'
class Guard::Classname
end
}
Guard.get_guard_class('classname').should == Guard::Classname
end
end
context 'loaded some inline classes ' do
it 'should return inline class' do
module Guard
class Inline < Guard
end
end
Guard.get_guard_class('inline').should == Guard::Inline
end
end
end