Skip to content

Commit

Permalink
Add validator initial params tests
Browse files Browse the repository at this point in the history
  • Loading branch information
18bitmood committed Sep 13, 2021
1 parent c34d754 commit d97beab
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/blockfrostruby/validator.rb
Expand Up @@ -162,7 +162,7 @@ def validate_is_integer(param, param_name)
end

def validate_is_boolean(param, param_name)
unless param.is_a?(True) || param.is_a?(False)
unless param.is_a?(TrueClass) || param.is_a?(FalseClass)
raise ArgumentError,
"\"#{param_name}\" is not a true or a false"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/blockfrostruby_spec.rb
Expand Up @@ -3,7 +3,7 @@
require_relative '../lib/blockfrostruby.rb'
require_relative '../lib/blockfrostruby/constants.rb'

RSpec.describe Blockfrostruby do
RSpec.describe Blockfrostruby::VERSION do
it 'has a version number' do
expect(Blockfrostruby::VERSION).not_to be nil
end
Expand Down
66 changes: 66 additions & 0 deletions spec/validator_spec.rb
@@ -0,0 +1,66 @@
# frozen_string_literal: true

require_relative '../lib/blockfrostruby.rb'
require_relative '../lib/blockfrostruby/validator.rb'
require_relative '../lib/blockfrostruby/constants.rb'

RSpec.describe Validator do
context 'when creating a Blockfrost object' do
context 'with invalid use_asc_order_as_default' do
it 'raises an ArgumentError' do
expect { Blockfrostruby::CardanoMainNet.new('project_id', { use_asc_order_as_default: 1 })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { use_asc_order_as_default: 'a' })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { use_asc_order_as_default: :symbol })}
.to raise_error(ArgumentError)
# expect { Blockfrostruby::CardanoMainNet.new('project_id', { use_asc_order_as_default: nil })}
# .to raise_error(ArgumentError)
end
end

context 'with invalid parallel_requests' do
it 'raises an ArgumentError' do
expect { Blockfrostruby::CardanoMainNet.new('project_id', { parallel_requests: MAX_NUMBER_OF_PARALLEL_REQUESTS + 1 })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { parallel_requests: 'a' })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { parallel_requests: -1 })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { parallel_requests: :symbol })}
.to raise_error(ArgumentError)
end
end

context 'with invalid default_count_per_page' do
it 'raises an ArgumentError' do
expect { Blockfrostruby::CardanoMainNet.new('project_id', { default_count_per_page: MAX_COUNT_PER_PAGE + 1 })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { default_count_per_page: 'a' })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { default_count_per_page: -1 })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { default_count_per_page: :symbol })}
.to raise_error(ArgumentError)
end
end

context 'with invalid sleep_between_retries_ms' do
it 'raises an ArgumentError' do
expect { Blockfrostruby::CardanoMainNet.new('project_id', { sleep_between_retries_ms: 'a' })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { sleep_between_retries_ms: -1 })}
.to raise_error(ArgumentError)
expect { Blockfrostruby::CardanoMainNet.new('project_id', { sleep_between_retries_ms: :symbol })}
.to raise_error(ArgumentError)
end
end

# context 'with all valid params' do
# end
end

# context 'when specifying params for requests' do
# end
end

0 comments on commit d97beab

Please sign in to comment.