Introduced Rspec and Factory Bot as a purchasing agency service

reference

https://qiita.com/Ushinji/items/522ed01c9c14b680222c https://qiita.com/key_it6/items/fb94f229e9e45270c515

What i did

Gemfile


group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]

  gem 'factory_bot_rails' #add to
  gem 'rspec-rails' #add to
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'listen', '>= 3.0.5', '< 3.2'
  gem 'web-console', '>= 3.3.0'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-commands-rspec' #add to
  gem 'spring-watcher-listen', '~> 2.0.0'
end

Terminal


bundle

bin/rails generate rspec:install

spec/rails_helper.rb


abridgement
Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f }
abridgement

spec/support/factory_bot.rb


RSpec.configure do |config|
  config.include FactoryBot::Syntax::Methods
end

result

Terminal


-> % bin/rspec
Running via Spring preloader in process 32344
No examples found.


Finished in 0.00101 seconds (files took 0.49014 seconds to load)
0 examples, 0 failures

Recommended Posts

Introduced Rspec and Factory Bot as a purchasing agency service
[RSpec] Let's master Factory Bot
Notes on creating a many-to-many Factory with Rspec and testing it with SystemSpec [RSpec, FactoryBot]