开发者_C百科I ran the below curl command in terminal
curl -d "message" http://localhost:8080/api/validate -u username:password
and is running as expected.
I am writing a functional test for the above in Rails. For doing this I have to call the post
method and pass the arguments whatever I have done for curl
to post
.
post 'validate',:request => "message"
I am able to pass the request paramater successfully. But how do I pass the username and password that I am passing in Curl to the post method in rails. Please advise
The option you are passing to curl
is setting up HTTP Basic Auth, so you need to do that in your test.
Take a look at whats going on in the answer to this question:
Testing HTTP Basic Auth in Rails 2.2+
精彩评论