Using Factories defined in another Gem (Rails Engine)

107 views
Skip to first unread message

nat...@nathansamson.be

unread,
Nov 15, 2013, 10:14:45 AM11/15/13
to factor...@googlegroups.com
Hi,

I have the following layout

I have a Gem that is a Rails Engine (lets call it EngineA).

EngineA defines some models (call them ModelA), and some factories for them.
In EngineA I sucessfully use them in my tests.


Now I have ApplicationB that requires EngineA, and ModelA.
Obviously I want to write tests for ApplicationB, and they will use ModelA.

Now I am looking into reusing the existing factories from ModelA.

What I am wondering:
  • Has someone tried this approach yet?
  • Is it possible (I think it is using
    FactoryGirl.definition_file_paths = %w(custom_factories_directory)
    FactoryGirl.find_definitions)
    but I didn't try it yet.
  • Is it a good idea?

Reason I am asking the question is that I see myself some disadvantages.

The main disadvantage is that the factories become essentially public API.
ANother issue is Name Clashes
Last but not least, needing a custom Factory in ApplicationB needs or a change for the Engine or they still need
to be defined in ApplicationB leading probably quite quickly to factory duplication Anyway.


Note that I am the author of Both applications. At this moment EngineA is only used in ApplicationB, but this might change very soon.


Regards,

Nathan

Reply all
Reply to author
Forward
0 new messages