Skip to content

Commit

Permalink
add test for custom validation error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Jul 5, 2023
1 parent e56fe47 commit 8d180cf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spec/typed_params/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,17 @@
expect { validator.call(params) }.to_not raise_error
end

it 'should raise with a custom error message for :validate validation' do
schema = TypedParams::Schema.new(type: :hash) { param :foo, type: :string, validate: -> v { raise TypedParams::ValidationError, 'foo' } }
params = TypedParams::Parameterizer.new(schema:).call(value: { foo: 'bar' })
validator = TypedParams::Validator.new(schema:)

expect { validator.call(params) }.to raise_error { |err|
expect(err).to be_a TypedParams::InvalidParameterError
expect(err.message).to eq 'foo'
}
end

it 'should not raise on hash of scalar values' do
schema = TypedParams::Schema.new(type: :hash)
params = TypedParams::Parameterizer.new(schema:).call(value: { a: 1, b: 2, c: 3 })
Expand Down

0 comments on commit 8d180cf

Please sign in to comment.