Home > Net >  How should i create an object with dinamic variable?
How should i create an object with dinamic variable?

Time:01-12

I wanted to create a signature object, always the flag is being false, it should be true or false

i was reading the doc https://github.com/thoughtbot/factory_bot/blob/main/GETTING_STARTED.md#traits

let!(:signature) { FactoryBot.create(:signature, flag: true) }
let!(:signature) { FactoryBot.create(:signature, flag: false) }

this is the factory:

factory :signature do
    flag {}
  end

CodePudding user response:

To make the default flag attribute false:

factory :signature do
  flag false
end

Then you would do something like:

let!(:default_flag_signature) { FactoryBot.create(:signature) } // flag will be false
let!(:true_flag_signature) { FactoryBot.create(:signature, flag: true) } // flag will be true

CodePudding user response:

Try below spec/factories/signature.rb

FactoryBot.define do
  factory :signature do |f|
   f.flag false
  end
end
  • Related