Skip to content

Commit

Permalink
adding support for inline classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrsacks committed Apr 21, 2011
1 parent d329e4e commit a0b6eca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
9 changes: 7 additions & 2 deletions lib/guard.rb
Expand Up @@ -83,10 +83,15 @@ def add_guard(name, watchers = [], options = {})
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)
Expand Down
27 changes: 21 additions & 6 deletions spec/guard_spec.rb
Expand Up @@ -30,15 +30,30 @@
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
Expand Down

0 comments on commit a0b6eca

Please sign in to comment.