5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[rails] http ステータスコードのsymbol一覧確認方法メモ

Posted at

rspecでレスポンス結果200のhttp statusである、という場合は下記のように書ける

expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)

下の:okといったsymbolのステータスコードを指定する場合、どんな値が定義されているか分からず都度調べたりしていたが、下記の定数に定義されているらしい

[5] pry(main)> Rack::Utils::SYMBOL_TO_STATUS_CODE
=> {:continue=>100,
 :switching_protocols=>101,
 :processing=>102,
 :ok=>200,
 :created=>201,

そもそもドキュメントの頭に書いてあったし、Railsでも使っているよね。。。

参考
https://relishapp.com/rspec/rspec-rails/docs/matchers/have-http-status-matcher

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?