Skip to content

Commit

Permalink
Adding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
janlindblom committed May 1, 2021
1 parent 074acbc commit 2973888
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lib/replit/database/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions replitdb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
8 changes: 5 additions & 3 deletions spec/replit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2973888

Please sign in to comment.