64
43

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 5 years have passed since last update.

RSpecAdvent Calendar 2015

Day 9

RSpecで作ったexampleの一覧をテストの実行なしに出力する

Last updated at Posted at 2015-12-08

やりたいこと

RSpecで作ったexampleの一覧をテストの実行なしに出力したい。
(つまりテスト項目一覧がほしい)

コマンド

Rails(Spring)で実行する場合

$ bin/rspec -f d --dry-run --order defined

Bundle execで実行する場合

$ bundle exec rspec -f d --dry-run --order defined

オプションの意味

  • -f d = ドキュメント形式で出力する。--format documentationと書いても良い。
  • --dry-run = テストを実行しない(Dry run)
  • --order defined = 定義されている順に実行する。spec_helper.rb等でランダム実行を指定していなければ省略可。

出力例

$ bin/rspec -f d --dry-run --order defined

ContactsController
  administrator access
    behaves like public access to contacts
      GET #index
        with params[:letter]
          populates an array of contacts starting with the letter
          renders the :index template
        without params[:letter]
          populates an array of all contacts
          renders the :index template
      GET #show
        assigns the requested contact to @contact
        renders the :show template

# 省略...

NewsRelease
  example at ./spec/models/news_release_spec.rb:4
  example at ./spec/models/news_release_spec.rb:5
  example at ./spec/models/news_release_spec.rb:6
  returns the formatted date and title as a string

Phone
  does not allow duplicate phone numbers per contact
  allows two contacts to share a phone number

Finished in 0.00696 seconds (files took 1.66 seconds to load)
82 examples, 0 failures

応用:フィーチャスペックだけを一覧化する

$ bin/rspec spec/features -f d --dry-run --order defined   

About BigCo modal
  toggles display of the modal about display

News releases
  as a user
    adds a news release
  as a guest
    reads a news release

User management
  adds a new user

Finished in 0.00072 seconds (files took 1.71 seconds to load)
4 examples, 0 failures

参考資料

その他

上の実行例で使ったコードは電子書籍「Everyday Rails - RSpecによるRailsテスト入門」で使われているテストコードです。

64
43
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
64
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?