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 end
def get_guard_class(name) 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 }) 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 rescue LoadError
UI.error "Could not find gem 'guard-#{name}', please add it in your Gemfile."
end end
def locate_guard(name) def locate_guard(name)

View File

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