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?
--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-grape/6690afe0-47ab-4b60-96ad-e0426733f13f%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-grape/6690afe0-47ab-4b60-96ad-e0426733f13f%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-grape/10fc1f4f-3b38-417a-b1ff-6915862f0d52%40googlegroups.com.