0
0

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 1 year has passed since last update.

【RSpec】APIのリクエストテストでgemはあまり使われていないらしい

Posted at

APIのリクエストテストをやる際、
jsonが期待通りに取れているかをもっとわかりやすく書けないかと思ったときにいくつかgemを発見した。

最後のコミットが何年も前だったこと、starの数もあまり多くなかったこと、実際に使ってみて使いづらかったことを踏まえてgemは使わずやることにした。

gemを使ったAPIのリクエストテストの方法をあまり記事で見かけなかったので、みんなそもそもgemを使わないのかなーとも思った。

spec.rb
...
it '自分の本の情報が昇順に返ること' do
  json = JSON.parse(response.body)
  expect(response.status).to eq 200
  expect(json['books']).to eq([
    {"id"=>book.id, "type"=>"mystery", "date"=>"2021-01-01", "punched_at"=>1609459200},
    {"id"=>book2.id, "type"=>"love", "date"=>"2021-01-05", "punched_at"=>1609804800},
    {"id"=>book1.id, "type"=>"mystery", "date"=>"2021-01-11", "punched_at"=>1610323200}
  ])
end
...
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?