Testing Validation Exception Handling in ruby-grape/grape
This test suite focuses on validating the Grape::Exceptions::Validation class behavior in the Ruby Grape framework. It verifies exception handling for parameter validation, message handling, and error conditions. The tests ensure proper error management for both symbolic and string-based validation messages.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
ruby-grape/grape
spec/grape/exceptions/validation_spec.rb
# frozen_string_literal: true
describe Grape::Exceptions::Validation do
it 'fails when params are missing' do
expect { described_class.new(message: 'presence') }.to raise_error(ArgumentError, /missing keyword:.+?params/)
end
context 'when message is a symbol' do
it 'stores message_key' do
expect(described_class.new(params: ['id'], message: :presence).message_key).to eq(:presence)
end
end
context 'when message is a String' do
it 'does not store the message_key' do
expect(described_class.new(params: ['id'], message: 'presence').message_key).to be_nil
end
end
end