我遇到了一个非常混乱的问题......
当我单独运行它们时,我的所有测试都通过了。 当我像rake test一样运行它们时,在我的集成测试运行之后,Machinist说它再也找不到蓝图了。
为了让水豚测试工作,我必须调用一些魔法......
为了获得交易固定装置,我将所有活动强制转移到这样的单一交易上:
#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
发出类似的东西之后
visit new_user_session_path
我必须这样做
load "#{Rails.root}/test/blueprints.rb"
能够再次使用我的蓝图。
关于机械师如何在简单visit
之后失去其蓝图的任何想法?
答案 0 :(得分:1)
这里的问题与Capybara的RackTest驱动程序有关。处理完请求后,它正在调用ActionDispatch::Reloader.cleanup
!查看ActionDispatch::Reloader
上的评论,仅在config.cache_classes
为假时才会包含该评论。
因此,一个解决方案是在config.cache_classes
上将environment/test.rb
设置为true - 但这不是最佳解决方案。
另一个解决方案是使用另一个驱动程序(我自己也没试过),Capybara带有不同的驱动程序。
我做了类似于布拉德的事情 - 通过重新加载我使用Capybara访问的规范上的蓝图。在您的规范上,您可以添加一个后块,如:
describe "my test" do
after do
load_blueprint
end
end
我将reload_blueprint方法放在spec / support目录中的文件中,即:spec/support/load_blueprint.rb
这仍然是一种解决方法,而不是一个合适的解决方案。