C83 / THP_2.0

0 stars 0 forks source link

Add factories #4

Closed C83 closed 6 years ago

C83 commented 6 years ago

Why ?

It's really bothersome to create instance of model all the time in our tests. Factory bot (used with faker) will help us to create randomized model instance created in DB for our tests. It will also creates associated models and allows us to just override what we need to test.

Nobody wants to type @my_model = MyModel.create(name: 'important', description: 'xxx', short_description: 'owi', age: 23, array_attribute: [1,2,3] …) over and over in their test. Using create(:my_model, name: 'important') is way more easier.

Must have

Reading List

C83 commented 6 years ago
  1. gem "factory_bot_rails", "~> 4.0"
  2. Add the below text in a new file spec/support/factory_bot.rb :
    RSpec.configure do |config|
    config.include FactoryBot::Syntax::Methods
    end 
  3. gem install faker To use faker : require 'faker'