Skip to content

Commit

Permalink
Use RuntimeError instead of ArgumentError if missing Sequel database …
Browse files Browse the repository at this point in the history
…connection

No argument is being provided, so ArgumentError isn't appropriate.

Make the spec use begin/ensure so that a failure of the new spec
does not make all subsequent specs break.
  • Loading branch information
jeremyevans committed Dec 16, 2022
1 parent e76317d commit fe220e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/rodauth/features/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def open_account?
end

def db
Sequel::DATABASES.first or raise ArgumentError, "Sequel database connection is missing"
Sequel::DATABASES.first or raise "Sequel database connection is missing"
end

def password_field_autocomplete_value
Expand Down
14 changes: 8 additions & 6 deletions spec/rodauth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1232,12 +1232,14 @@ def foo
end

it "should raise error when sequel database is missing" do
database = Sequel::DATABASES.pop

rodauth {}
error = proc { roda {} }.must_raise(ArgumentError)
error.message.must_equal "Sequel database connection is missing"
begin
database = Sequel::DATABASES.pop

Sequel::DATABASES.push database
rodauth {}
error = proc { roda {} }.must_raise(RuntimeError)
error.message.must_equal "Sequel database connection is missing"
ensure
Sequel::DATABASES.push database if database
end
end
end

0 comments on commit fe220e0

Please sign in to comment.