Rails 3.1 RC5 Mounting an Engine Using Spork

I was able to get RSpec, Cucumber and Autotest to work against my Rails 3.1 Mountable Engine. Where everything falls, he tries to integrate Spork into the mix. Spork works fine, and my tests use Spork, but the problem I encountered is that Spork will not restart the models unless I remove the Spork server, which is not entirely efficient. I also use factory_girl. I tried various things using Spork.trap_method , but nothing worked.

Here are the gems that I use (although since then I left Spork in my project because of the grief that caused me to do this):

  • rails (3.1.0.rc5)
  • spork (0.9.0.rc9)
  • rspec (2.6.0)
  • rspec-core (2.6.4)
  • rspec-wait (2.6.0)
  • rspec-mocks (2.6.0)
  • rspec-rails (2.6.1)
  • factory_girl (2.0.3)
  • factory_girl_rails (1.1.0)
  • cucumber (1.0.2)
  • cucumber rails (1.0.2)

Thanks,

-Damien

+4
source share
1 answer

I understood my problem. It was Autotest, not Spork. I switched from a mounted engine to a standard engine (plug-in), as it turned out to be better suited for what I need.

Now I am using the released version of Rails 3.1.

In this case, I decided that everything would be simpler, but I ran into the same problem. In any case, this ended up being fixed for testing an engine with no names (mounted), although with a few ways, I believe this will work.

Add the .autotest file to the project root with the following:

Autotest.add_hook :initialize do |at| at.add_mapping %r%^app/models/(.*)\.rb$% do |_, m| "spec/models/#{m[1]}_spec.rb" end at.add_mapping %r%^app/controllers/(.*)\.rb$% do |_, m| ["spec/controllers/#{m[1]}_spec.rb", "spec/functional/#{m[1]}_spec.rb"] end at.add_mapping %r%^app/helpers/(.*)_helper.rb% do |_, m| ["spec/views/#{m[1]}_view_spec.rb", "spec/functional/#{m[1]}_controller_spec.rb"] end at.add_mapping %r%^app/views/(.*)/% do |_, m| ["spec/views/#{m[1]}_view_spec.rb", "spec/functional/#{m[1]}_controller_spec.rb"] end end 

I came up with a solution when I met this answer on another question: how can I tell auto-test to correctly track changes in the application source? as well as other examples found on the Internet.

Hope this helps someone else.

[Change 2011-09-20] The problem with the cucumber / sparkle with "hacking" has been fixed. In the Spork.each_run block, I forcibly reloaded the models and controllers as follows:

  ENGINE_ROOT=File.join(File.dirname(__FILE__), '../../') # Couldn't get spork to reload models, hence the reason for this hack Dir[File.join(ENGINE_ROOT, "app/models/*.rb")].each {|f| load f } # or controllers... Dir[File.join(ENGINE_ROOT, "app/controllers/*.rb")].each {|f| load f } 

There seems to be a better way ...

+2
source

All Articles