From 297388877e233da5fd73a9c4c54bbbbceaf6791d Mon Sep 17 00:00:00 2001 From: Jan Lindblom Date: Sat, 1 May 2021 20:37:42 +0300 Subject: [PATCH] Adding tests. --- lib/replit/database/client.rb | 10 ++++++---- replitdb.gemspec | 4 +--- spec/replit_spec.rb | 8 +++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/replit/database/client.rb b/lib/replit/database/client.rb index 448d879..b7398ca 100644 --- a/lib/replit/database/client.rb +++ b/lib/replit/database/client.rb @@ -17,8 +17,8 @@ class Client # @param [String] custom_url optional custom URL # def initialize(custom_url = nil) - @database_url = ENV["REPLIT_DB_URL"] - @database_url = custom_url unless custom_url.nil? + @database_url = ENV["REPLIT_DB_URL"] if ENV["REPLIT_DB_URL"] + @database_url = custom_url if custom_url end # @@ -133,13 +133,15 @@ def delete_multiple(keys = []) private def verify_connection_url - throw Replit::Database::ConfigurationError "Missing database connection url" unless @database_url + error = Replit::Database::ConfigurationError.new "Missing database connection url" + raise error unless @database_url + raise error if @database_url.empty? end def json_parse(string, key) JSON.parse(string, { symbolize_names: true }) rescue JSON::ParserError - throw Replit::Database::SyntaxError "Failed to parse value of #{ + raise Replit::Database::SyntaxError, "Failed to parse value of #{ key }, try passing a raw option to get the raw value" end diff --git a/replitdb.gemspec b/replitdb.gemspec index cf6d3b1..406732a 100644 --- a/replitdb.gemspec +++ b/replitdb.gemspec @@ -19,10 +19,8 @@ Gem::Specification.new do |spec| spec.metadata["source_code_uri"] = "https://github.com/janlindblom/ruby-replitdb" spec.metadata["changelog_uri"] = "https://github.com/janlindblom/ruby-replitdb/blob/main/CHANGELOG.md" - # Specify which files should be added to the gem when it is released. - # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) } + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|.github)/}) } end spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } diff --git a/spec/replit_spec.rb b/spec/replit_spec.rb index 449a2e5..176cda2 100644 --- a/spec/replit_spec.rb +++ b/spec/replit_spec.rb @@ -13,11 +13,13 @@ RSpec.describe Replit::Database::Client do context "without a defined connection URL" do before :all do - @client = Replit::Database::Client.new + @client = Replit::Database::Client.new("") end - it "will not work" do - expect(@client.get("dummy")).to be_nil + it "will raise a ConfigurationError" do + expect { @client.get("dummy") }.to raise_error Replit::Database::ConfigurationError + expect { @client.set("dummy", "value") }.to raise_error Replit::Database::ConfigurationError + expect { @client.delete("dummy") }.to raise_error Replit::Database::ConfigurationError end end end