LoginSignup
4
1

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

4
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
4
1