Skip to content

Commit

Permalink
Merge pull request #3344 from timoschilling/dependency_error
Browse files Browse the repository at this point in the history
refactor DependencyError
  • Loading branch information
seanlinsley committed Aug 20, 2014
2 parents 1e938ac + 80ad7b3 commit ffa68b3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
13 changes: 5 additions & 8 deletions lib/active_admin/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ module Dependency
# => true
#
# ActiveAdmin::Dependency.rails! '2'
# -> ActiveAdmin::Dependency::Error: You provided rails 3.2.18 but we need: 2.
# -> ActiveAdmin::DependencyError: You provided rails 3.2.18 but we need: 2.
#
# ActiveAdmin::Dependency.devise!
# -> ActiveAdmin::Dependency::Error: To use devise you need to specify it in your Gemfile.
# -> ActiveAdmin::DependencyError: To use devise you need to specify it in your Gemfile.
#
#
# All but the pessimistic operator (~>) can also be run using Ruby's comparison syntax.
Expand Down Expand Up @@ -64,11 +64,11 @@ def match?(*reqs)

def match!(*reqs)
unless @spec
raise Error, "To use #{@name} you need to specify it in your Gemfile."
raise DependencyError, "To use #{@name} you need to specify it in your Gemfile."
end

unless match? reqs
raise Error, "You provided #{@spec.name} #{@spec.version} but we need: #{reqs.join ', '}."
raise DependencyError, "You provided #{@spec.name} #{@spec.version} but we need: #{reqs.join ', '}."
end
end

Expand All @@ -80,7 +80,7 @@ def <=>(other)
else
# you'd otherwise get an unhelpful error message:
# ArgumentError: comparison of ActiveAdmin::Dependency::Matcher with 2 failed
raise Error, "To use #{@name} you need to specify it in your Gemfile."
raise DependencyError, "To use #{@name} you need to specify it in your Gemfile."
end
end

Expand All @@ -89,8 +89,5 @@ def inspect
"<ActiveAdmin::Dependency::Matcher for #{info}>"
end
end

class Error < ::ActiveAdmin::ErrorLoading; end

end
end
4 changes: 4 additions & 0 deletions lib/active_admin/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def self.database_error_classes
end
end

class DependencyError < ErrorLoading
end

class NoMenuError < KeyError
end

end
2 changes: 1 addition & 1 deletion lib/generators/active_admin/devise/devise_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DeviseGenerator < Rails::Generators::NamedBase
def install_devise
begin
Dependency.devise! Dependency::DEVISE
rescue Dependency::Error => e
rescue DependencyError => e
raise Error, "#{e.message} If you don't want to use devise, run the generator with --skip-users."
end

Expand Down
12 changes: 6 additions & 6 deletions spec/unit/dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@

describe '`!`' do
it 'raises an error if requirement not met' do
expect{ k.foo! '5' }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k.foo! '5' }.to raise_error ActiveAdmin::DependencyError,
'You provided foo 1.2.3 but we need: 5.'
end
it 'accepts multiple arguments' do
expect{ k.foo! '> 1', '< 1.2' }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k.foo! '> 1', '< 1.2' }.to raise_error ActiveAdmin::DependencyError,
'You provided foo 1.2.3 but we need: > 1, < 1.2.'
end
it 'raises an error if not provided' do
expect{ k.bar! }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k.bar! }.to raise_error ActiveAdmin::DependencyError,
'To use bar you need to specify it in your Gemfile.'
end
end
Expand Down Expand Up @@ -90,10 +90,10 @@
expect(k['a-b'].match! ).to eq nil
expect(k['a-b'].match! '1.2.3').to eq nil

expect{ k['a-b'].match! '2.5' }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k['a-b'].match! '2.5' }.to raise_error ActiveAdmin::DependencyError,
'You provided a-b 1.2.3 but we need: 2.5.'

expect{ k['b-c'].match! }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k['b-c'].match! }.to raise_error ActiveAdmin::DependencyError,
'To use b-c you need to specify it in your Gemfile.'
end

Expand Down Expand Up @@ -126,7 +126,7 @@
end

it 'throws a custom error if the gem is missing' do
expect{ k['b-c'] < 23 }.to raise_error ActiveAdmin::Dependency::Error,
expect{ k['b-c'] < 23 }.to raise_error ActiveAdmin::DependencyError,
'To use b-c you need to specify it in your Gemfile.'
end
end
Expand Down

0 comments on commit ffa68b3

Please sign in to comment.