Skip to content

Commit

Permalink
Add tests when validation type is [true, false]
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosCodes committed Mar 20, 2023
1 parent 54dee51 commit 0cf4c11
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions spec/lib/apipie/param_description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,25 @@
end
end

context 'when the parameter is a string' do
context 'when allow_blank is specified as true' do
it "should throw an exception when passed an empty value" do
expect { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: true).validate('') }.to_not raise_error
end
context 'when validation type is a boolean array' do
let(:validation_type) { [true, false] }

context 'when validation value is false' do
let(:validation_value) { false }

it { is_expected.not_to raise_error }
end
context 'when allow_blank is specified as false' do
it "should throw an exception when passed an empty value" do
expect { Apipie::ParamDescription.new(method_desc, :param, String, allow_blank: false).validate('') }.to_not raise_error
end

context 'when validation value is true' do
let(:validation_value) { true }

it { is_expected.not_to raise_error }
end
context 'when allow_blank is not specified' do
it "should throw an exception when passed an empty value" do
expect { Apipie::ParamDescription.new(method_desc, :param, String).validate('') }.to_not raise_error
end

context 'when validation value is an empty string' do
let(:validation_value) { '' }

it { is_expected.to raise_error(Apipie::ParamInvalid) }
end
end

Expand Down Expand Up @@ -210,6 +214,28 @@
end
end

context 'when validation type is a boolean array' do
let(:validation_type) { [true, false] }

context 'when validation value is false' do
let(:validation_value) { false }

it { is_expected.not_to raise_error }
end

context 'when validation value is true' do
let(:validation_value) { true }

it { is_expected.not_to raise_error }
end

context 'when validation value is an empty string' do
let(:validation_value) { '' }

it { is_expected.to raise_error(Apipie::ParamInvalid) }
end
end

context 'when the validation type is a custom one' do
let(:validation_type) { :custom_bool }

Expand Down

0 comments on commit 0cf4c11

Please sign in to comment.