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 connections 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 onActionDispatch::Reloader, it is only included whenconfig.cache_classesis false.So one solution would be to set
config.cache_classesto true onenvironment/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:
I put my the reload_blueprint method on a file in spec/support directory ie:
spec/support/load_blueprint.rbThis still is a work around though and not a proper solution.