0

Suppose I have an endpoint like so:

get "/foo" do
    request.body.rewind
    data = request.body.read
    # some logic goes here
end

How do I test this in Sinatra?

If I try:

it "gets /foo" do
    payload = {:bar => "baz"}
    get "/foo", payload
end

the payload gets sent as get parameters and not as request.body.

I am not able to change the endpoint to accept params instead of request.body at this point.

user650654
  • 5,630
  • 3
  • 41
  • 44

1 Answers1

0

Looking at the code, you can specify it in env with key :input, like so:

get "/foo", {}, {:input => JSON.generate(payload)}

assuming that the input is in json.

user650654
  • 5,630
  • 3
  • 41
  • 44