Gem: Factory Girl

2017-04-24  本文已影响42人  bookinstock_

intro

config in rails

lazy attributes

play in rails console

  1. add factory_girl_rails gem in development and test env.
  2. rails console test --sandbox # go in console test env sandbox mode.
  3. include FactoryGirl::Syntax::Methods # call methods without FactoryGirl.
  4. user = build(:user) # initialize user instance from user factory.

check validation

  1. FactoryGirl.factories get all 'FactoryGirl::Factory' instances
  2. FactoryGirl.factories.each { |f| puts f.name } # show all factory names
  3. target_factories = FactoryGirl.factories.select { |f| f.name =~ /^user_/ }
  4. FactoryGirl.lint target_factories; # FactoryGirl.lint check all factories

Resources:

上一篇下一篇

猜你喜欢

热点阅读