开发者

Machinist + Cabybara + Test::Unit = blueprints missing

I've run into a very confusing problem...

All my tests pass when i run them in isolation. When I run them like rake test, after my integration tests run, Machinist says that it can't find blueprints anymore.

To get the capybara tests working I have to invoke some magic ...

To get transactional fixtures I'm forcing all activity onto a single transaction like this:

#always use the same connection so updates inside of transactions are visible.
#allows the use of use_transactional_fixtures
ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
  def current_connection_id
    #always fetch the connection for the main thread
    # was Thread.current.object_id
    Thread.main.object_id
  end

  def clear_reloadable_connections!
    #do nothing, when connect开发者_StackOverflow中文版ions are reloaded, otherwise the only connection is severed on each request
  end
end

After issuing something like visit new_user_session_path I have to do this load "#{Rails.root}/test/blueprints.rb" to be able to use my blueprints again.

Any ideas about how Machinist could lose its blueprints after a simple visit?


The issue here has got to do with RackTest driver for Capybara. After processing a request it is calling ActionDispatch::Reloader.cleanup! Looking at the comment on ActionDispatch::Reloader, it is only included when config.cache_classes is false.

So one solution would be to set config.cache_classes to true on environment/test.rb - but this is not the best solution.

Another solution would be to use another driver (I haven't tried this myself), Capybara comes with different drivers.

I've done something similar to Brad - by reloading blueprints on the my spec that uses Capybara visits. On your spec you can add an after block like:

describe "my test" do
    after do
        load_blueprint
    end
end

I put my the reload_blueprint method on a file in spec/support directory ie: spec/support/load_blueprint.rb

This still is a work around though and not a proper solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜