Programming Journal

学習したことの整理用です。

【RSpec】gem Seed Fu

gem Seed Fu

Seed Fu is an attempt to once and for all solve the problem of inserting and maintaining seed data in a database. It uses a variety of techniques gathered from various places around the web and combines them to create what is hopefully the most robust seed data system around.
GitHub - mbleigh/seed-fu: Advanced seed data handling for Rails, combining the best practices of several methods together.

シードを挿入してくれるgem

テスト環境にシードデータを投入するのに、以下のコマンドを実行していました。

rails db:seed_fu RAILS_ENV=test

こっちでもいい

RSpec.configure do |config|
(略)
  config.before :suite do
    SeedFu.seed
  end
end

before(:suite)はテスト実行前に実行される。
(『everydayRails』p42,171)

SeedFu.seed ってどういう意味??と思ったら、公式READ.MEの中に、以下の一文があった。

You can also do a similar thing in your code by calling SeedFu.seed(fixture_paths, filter).

参考

railsで初期データを入れる(seed-fuの使い方) - Qiita

SeedFu.seedのコードリーディングはこちらを参考にした。
seed-fuコードリーディング