LoginSignup
8
1

More than 3 years have passed since last update.

[RSpec] FactoryBot 省略の仕方

Posted at

FactoryBotでユーザーを生成する際、
FactoryBot.create(:user)FactoryBot.build(:user)のように書くと思いますが
この「FactoryBot」部分を省略する方法があるので、メモです。

specフォルダの中にあるrails_helper.rbに追記します。

RSpec.configure do |config|
  config.include FactoryBot::Syntax::Methods ##こちらを追記
end

これで、create(:user)build(:user)と書くだけでユーザーの生成ができるようになります!

以上です!

8
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
8
1