LoginSignup
4
1

More than 5 years have passed since last update.

request spec 参考oss

Posted at

概要

今後controller specではなくrequest specを書いた方が良いそうです(参考)。

それはともかく、あまり仕事でrspecを書いた経験も少ない上、一から構築する予定なのでrequest spec の書き方について参考になるものはないかと思ってgithub上のソースを調べました。
minitestを使っているものはなんとなくintegrationテストが近そうなのでそちらを参考にしました。

gitlab

こちら結構しっかり書いてありますね。
apiのrequest specも書いてあり参考になりそうです。

describe API::Deployments do
  describe 'GET /projects/:id/deployments' do
    context 'as member of the project' do
      it 'returns projects deployments sorted by id asc' do
      describe 'ordering' do
        it 'returns the deployments ordered' do

gitlabはcontroller spec残ってますね。

テストの構成

Controller名 -> HTTP Method + path -> 条件 -> 期待値 -> 条件 -> 期待値

discourse

request spec書いてありますが、controller specを移植しただけな印象。
controller specはありません。

spree

結構しっかり書いてあります。
controller#methodと書いているあたりcontroller specのような?

describe 'API V2 Storefront Checkout Spec', type: :request do
  describe 'checkout#next' do
    context 'without line items' do
      it 'cannot transition to address without a line item' do

テストの構成

機能名 -> Controller名 + method名 -> 条件 -> 期待値

subjectではなく、以下のように定義してexampleの中で呼び出しているのが印象的

let(:execute) { patch '/api/v2/storefront/checkout/advance', headers: headers }

redmine

rspecじゃないですね。minitest使ってます。

test "GET /users/current.xml should require authentication" do
  get '/users/current.xml'
  assert_response 401
end
test "GET /users/current.xml should return current user" do
  get '/users/current.xml', :headers => credentials('jsmith')
  assert_select 'user id', :text => '2'
end

シンプルですね。

テストの構成

アクセス先 + 期待値

feedbin

minitest
integrationテストはない

参考

今回参考にしたのはこちら
* http://post.simplie.jp/posts/19
* https://qiita.com/t2kojima/items/ad7a8ade9e7a99fb4384

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