Adds better error for missing provider. Closes #536

This commit is contained in:
Michael Bleigh 2011-11-25 09:03:23 -05:00
parent c98b6e0637
commit 4af02425f8
2 changed files with 13 additions and 1 deletions

View File

@ -19,7 +19,11 @@ module OmniAuth
if klass.is_a?(Class) if klass.is_a?(Class)
middleware = klass middleware = klass
else else
middleware = OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(klass.to_s)}") begin
middleware = OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(klass.to_s)}")
rescue NameError
raise LoadError, "Could not find matching strategy for #{klass.inspect}. You may need to install an additional gem (such as omniauth-#{klass})."
end
end end
use middleware, *args, &block use middleware, *args, &block

View File

@ -16,5 +16,13 @@ describe OmniAuth::Builder do
provider ::ExampleClass provider ::ExampleClass
end }.should_not raise_error end }.should_not raise_error
end end
it "should raise a helpful LoadError messgae if it can't find the class" do
expect {
OmniAuth::Builder.new(nil) do
provider :lorax
end
}.to raise_error(LoadError, "Could not find matching strategy for :lorax. You may need to install an additional gem (such as omniauth-lorax).")
end
end end
end end