In Ruby < 1.9, Symbol#downcase doesn't exist!

This commit is contained in:
Rémy Coutable 2011-06-02 00:40:37 +02:00
parent 3d52d51d36
commit cb5843aa47
3 changed files with 20 additions and 3 deletions

View File

@ -1,5 +1,9 @@
## Master ## Master
### Bugs fixes:
- In Ruby < 1.9, Symbol#downcase doesn't exist! ([@rymai](https://github.com/rymai))
### New features: ### New features:
- Pull request [#73](https://github.com/guard/guard/pull/73): Allow DSL's `group` method to accept a Symbol as group name. ([@johnbintz](https://github.com/johnbintz)) - Pull request [#73](https://github.com/guard/guard/pull/73): Allow DSL's `group` method to accept a Symbol as group name. ([@johnbintz](https://github.com/johnbintz))

View File

@ -81,14 +81,14 @@ module Guard
end end
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.to_s.downcase.gsub('-', '') }) self.const_get(self.constants.find { |klass_name| klass_name.to_s.downcase == name.to_s.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
def try_to_load_gem(name) def try_to_load_gem(name)
require "guard/#{name.downcase}" require "guard/#{name.to_s.downcase}"
rescue LoadError rescue LoadError
end end

View File

@ -89,6 +89,19 @@ describe Guard do
end end
end end
describe ".try_to_load_gem" do
class Guard::Classname
end
it "reports an error if the class is not found" do
Guard.get_guard_class('classname').should be_true
end
it "reports an error if the class is not found" do
Guard.get_guard_class(:classname).should be_true
end
end
describe ".locate_guard" do describe ".locate_guard" do
it "returns the path of a Guard gem" do it "returns the path of a Guard gem" do
if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0') if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0')