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 21, 2023
1 parent 7b0c15b commit f93d6cb
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions spec/lib/apipie/param_description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,30 @@
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
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 'should not raise an error' do
expect { subject }.not_to raise_error
end
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

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

it 'should not raise an error' do
expect { subject }.not_to raise_error
end
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

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

it 'should raise an error' do
expect { subject }.to raise_error(Apipie::ParamInvalid)
end
end
end
Expand Down Expand Up @@ -226,6 +236,34 @@
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 'should not raise an error' do
expect { subject }.not_to raise_error
end
end

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

it 'should not raise an error' do
expect { subject }.not_to raise_error
end
end

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

it 'should raise an error' do
expect { subject }.to raise_error(Apipie::ParamInvalid)
end
end
end

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

Expand Down

0 comments on commit f93d6cb

Please sign in to comment.