Skip to content

Commit

Permalink
Add database setup feature spec
Browse files Browse the repository at this point in the history
  • Loading branch information
apexatoll committed Oct 1, 2023
1 parent 707fac3 commit 73d707d
Showing 1 changed file with 97 additions and 0 deletions.
97 changes: 97 additions & 0 deletions spec/features/database_setup_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
RSpec.describe "Setting up a database in a target gem", :with_gem do
context "when no database adaptor is set" do
before do
gem.main_file.write(<<~RUBY)
require "kangaru"
module SomeGem
extend Kangaru::Initialiser
Kangaru.application.configure do |config|
end
end
RUBY
end

it "does not raise any errors" do
expect { gem.load! }.not_to raise_error
end

it "does not setup a database" do
gem.load!
expect(Kangaru.application.database).to be_nil
end
end

context "when an invalid database adaptor is set" do
before do
gem.main_file.write(<<~RUBY)
require "kangaru"
module SomeGem
extend Kangaru::Initialiser
Kangaru.application.configure do |config|
config.database.adaptor = :invalid
end
end
RUBY
end

it "raises an error" do
expect { gem.load! }.to raise_error(
Kangaru::Database::AdaptorError, "invalid adaptor 'invalid'"
)
end
end

context "when adaptor is set to sqlite" do
context "and database path is not set" do
before do
gem.main_file.write(<<~RUBY)
require "kangaru"
module SomeGem
extend Kangaru::Initialiser
Kangaru.application.configure do |config|
config.database.adaptor = :sqlite
end
end
RUBY
end

it "raises an error" do
expect { gem.load! }.to raise_error(
Kangaru::Database::SQLiteError, "path can't be blank"
)
end
end

context "and database path is set" do
before do
gem.main_file.write(<<~RUBY)
require "kangaru"
module SomeGem
extend Kangaru::Initialiser
Kangaru.application.configure do |config|
config.database.adaptor = :sqlite
config.database.path = "#{gem.path.join('database.sqlite3')}"
end
end
RUBY
end

it "does not raise any errors" do
expect { gem.load! }.not_to raise_error
end

it "sets the database instance" do
gem.load!
expect(Kangaru.application.database).to be_a(Kangaru::Database)
end
end
end
end

0 comments on commit 73d707d

Please sign in to comment.