LoginSignup
1
1

More than 5 years have passed since last update.

puffing-billy が返すレスポンスが途中で切れる時

Posted at

puffing-billy を使うと Capybara を使ったインテグレーションテストで、JS が AJAX で接続する API サーバをモックすることができます。JS 用 webmock のような感じです。

しかし、大きなレスポンスを返そうとすると、データが切れてしまうことがあります。よく調べてみると、自分で Content-Length を設定すれば切れなくなることがわかりました。

body = 'Looooooooong text'
headers = { 'Content-Length' => body.bytesize }
proxy.stub(url).and_return(code: 200, body: body, headers: headers)

勝手に設定してくれると便利なんですけどね。VCR のように実際に外部 API にリクエストした結果を記録する機能があるので、自分でレスポンスを作るケースはあまり重視されてないのかもしれません。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1