How can I define a normal method for use in one of my FactoryGirl factories? For instance:
FactoryGirl.define do
def silly_horse_name
verbs = %w[brunches dribbles haggles meddles]
nouns = %w[landmines hamlets vandals piglets]
"#{verbs.sample} with #{nouns.sample}".titleize
end
factory :racehorse do
name { silly_horse_name } # eg, "Brunches with Landmines"
after_build do |horse, evaluator|
puts "oh boy, I built #{silly_horse_name}!"
end
end
end
Doing it this way does not call silly_horse_name
at all; if it's redefined to raise 'hey!'
, nothing happens.
I'm using FactoryGirl 2.5.2.
FactoryHelpers
module in the factory somehow? Using the above, I seeundefined method silly_horse_name for #<FactoryGirl::SyntaxRunner:0x007fd3b161cd30>
– Brundisium