I have a very simple grape-powered API. Lets say that it looks like this:
class MyApi < Grape::API
params do
requires :name, type: String
requires :id, type: Integer, positive_value: true
end
get '/' do
# whatever...
end
end
I have custom PositiveValue validator, which works just fine for id.
I would like to create spec that makes sure that my params has correct options passed. I would like to avoid making full request specs, but instead of that I'd like to check if name param has type: String, and make sure it's required:
# my_api_spec.rb
describe 'params' do
let(:params) { described_class.new.router.map['GET'].first.options[:params] }
specify do
expect(params['name']).to include(type: 'String') # this one works fine
expect(params['id']].to include(type: 'Integer', positive_value: true) # this one fails
end
end
It turns out that this params have {:required=>true, :type=>"Integer"} hash. How can I test and make sure that my custom validators are being used for given param?
Thanks for help in advance.