From d97beab59507ad3b31d9799fba74b84e70dfc492 Mon Sep 17 00:00:00 2001 From: Ivan Date: Mon, 13 Sep 2021 21:20:32 +0300 Subject: [PATCH] Add validator initial params tests --- lib/blockfrostruby/validator.rb | 2 +- spec/blockfrostruby_spec.rb | 2 +- spec/validator_spec.rb | 66 +++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 spec/validator_spec.rb diff --git a/lib/blockfrostruby/validator.rb b/lib/blockfrostruby/validator.rb index fda0319..b505b5b 100644 --- a/lib/blockfrostruby/validator.rb +++ b/lib/blockfrostruby/validator.rb @@ -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 diff --git a/spec/blockfrostruby_spec.rb b/spec/blockfrostruby_spec.rb index 1bf0853..37dfbc5 100644 --- a/spec/blockfrostruby_spec.rb +++ b/spec/blockfrostruby_spec.rb @@ -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 diff --git a/spec/validator_spec.rb b/spec/validator_spec.rb new file mode 100644 index 0000000..d2a1c8f --- /dev/null +++ b/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 +