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?

【Rails】RSpec(Gem)について

Last updated at Posted at 2025-05-03

記事概要

Ruby on RailsのRSpec(Gem)について、まとめる

前提

  • Ruby on Railsでアプリケーションを作成している

RSpecとは

Ruby on Railsのテストコードを書くために用いられるGem

rails_helper.rb

Rspecを用いてRailsの機能をテストするときに、共通の設定を書いておくファイル

各テスト用ファイルでspec/rails_helper.rbを読み込むことで、共通の設定やメソッドを適用できる

Gemのインストール手順

Gemfileの記述

手順(設定)

  1. アプリにRSpecをインストールするため、下記コマンドを実行する
    # アプリのディレクトリに移動
    % cd ~/[アプリ名]
    
    % rails g rspec:install
    
  2. .rspec--format documentationを追記する
    テストコードの結果をターミナル上に可視化するための記述である
    .rspec
    --require spec_helper
    --format documentation
    
  3. RSpecのテスト実行時の標準の言語を英語に指定したい場合、生成されたspec/rails_helper.rbに下記を記述する
    spec/rails_helper.rb
    # RSpec.configure do |config| 〜 end の外に記述
    I18n.locale = "en"
    
    RSpec.configure do |config|
      #省略
    end
    

Ruby on Railsまとめ

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?