ruby on rails - FactoryGirls randomly fails with 'Factory not registered', why? -
i've tests randomly fail, approx. 20% of times. means without changing code, each time run tests 1 time out of 5 fail "factory not registered" error. it's weird.. :(
this consone output:
failures: 1) unit#new_from_string returns factor metric conversions failure/error: factorygirl.create :taza argumenterror: factory not registered: taza # ./spec/models/unit_spec.rb:29:in `block (2 levels) in <top (required)>' finished in 0.29619 seconds 4 examples, 1 failure failed examples: rspec ./spec/models/unit_spec.rb:22 # unit#new_from_string returns factor metric conversions randomized seed 61727
and code:
file: "unit_spec.rb"
require 'spec_helper' describe unit, "#new_from_string" "parses string , returns unit object" [some tests...] factorygirl.find_definitions u = factorygirl.create :taza factorygirl.create :tbsp [tests...] end "returns factor metric conversions" [tests not involving factory girl...] # following line 29, fails factorygirl.create :taza [tests...] end end
file "spec/factories/units.rb":
factorygirl.define factory :taza , :class => customunit singular 'taza' plural 'tazas' physical_type unit::volume equivalence_factor 200 equivalence_unit 'ml' end [other factories...] end
i think problem on line
factorygirl.find_definitions
actually there no need line when factories in correct directories(i see is), , put gem factory_girl_rails
in gemfile.
i think, 20% of time, second test run @ first. @ time, there no definition of factory , test failed. other test has such definition , passed. in other time, first test run first definition exists.
my suggestion:
- make sure have
factory_girl_rails
, notfactory_girl
in gemfile. - remove line of definition.
- [optional recommended] put definition in single file
spec/factories
, remove other factory files, if don't have factories. easier manage.
Comments
Post a Comment