You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am write an API using Grape.
Writing my rspec tests, I noticed a problem with a regexp validation of a param.
My Api is :
classMethods < Grape::APIhelpersdodefresults{method: route.route_method,id: params[:id]}endendparamsdorequires:id,regexp: /^\d{5}$/endnamespace:testsdo[:get,:post,:put,:delete].eachdo |method|
desc"Renvoie le parametre Id via #{method}"route(method,method)doresultsendendendend
The Rspec file 👍
describe"Test"doparams=[[nil,'aucun param',:missing],[{:id=>nil},'id is nul',:invalid],[{:id=>''},'id is vide',:invalid],[{:id=>'A'},'id is "A"',:invalid],[{:id=>'54'},'id is "54"',:invalid],[{:id=>78},'id is 78',:invalid],[{:id=>1234},'id is 1234',:invalid],[{:id=>567890},'id is 567890',:invalid],[{:id=>"0000"},'id is "0000"',:invalid],[{:id=>0000},'id is 000',:invalid]]params.eachdo |pp|
it"si #{pp[1]}"doget"/tests/get",pp[0]expect(response.status).toeql(403)expect(response.body).not_tobe_emptyjRes=JSON.parse(response.body,symbolize_names: true)expect(jRes).tohave(1).itemsexpect(jRes).tohave_key(:error)expect(jRes[:error]).tobe_eql("id is #{pp[2]}")endend
The problem is with the test : :id => null
The API returns a 200 and a result :
{"method" : "GET","id" : null}
If I want to test the id is null from a browser, I enter as an URL 👍
http://xxxxxx/test/get?id
I have a the same result, so the require and the regexp are not done...
The text was updated successfully, but these errors were encountered:
Hi
I am write an API using Grape.
Writing my rspec tests, I noticed a problem with a regexp validation of a param.
My Api is :
The Rspec file 👍
The problem is with the test : :id => null
The API returns a 200 and a result :
If I want to test the id is null from a browser, I enter as an URL 👍
http://xxxxxx/test/get?id
I have a the same result, so the require and the regexp are not done...
The text was updated successfully, but these errors were encountered: