thoughtbot/factory_girl_rails — Issue #49: AssociationTypeMismatch using Capybara-Webkit and Spork
Author: cvincent
Created: 2012-02-12 02:53:05+00:00
State: open

This issue is well-documented at Stack Overflow. The problem arises with this combination of things:

* Using Capybara-Webkit (or maybe even just Capybara) for integration testing.
* Using Spork for faster testing.
* Setting `config.cache_classes` to false in the DRB test environment so that changes to classes are picked up under Spork.
* Using FactoryGirl as a fixture replacement.

`AssociationTypeMismatch` is raised when attempting to use a Factory which sets associated models after classes have been reloaded by Rails. A number of solutions are presented on Stack Overflow which involve manually loading and reloading FactoryGirl in the `Spork.each_run` block in various ways, but I haven't personally seen any such combination of approaches actually work.

I'm not too keen on the class reloading processes of Rails, so my only recourse for now is to restart Spork whenever these errors pop up, or to remove my integration tests from the DRB environment. Neither solution is palatable. I would be interested to know if there is a workaround that actually works, or if there are plans to fix the issue. I'm more than happy to answer any questions about my environment to help with the legwork.