0

我遇到了一个非常令人困惑的问题......

当我单独运行它们时,我所有的测试都通过了。当我像 rake 测试一样运行它们时,在我的集成测试运行之后,机械师说它再也找不到蓝图了。

为了让水豚测试正常工作,我必须调用一些魔法......

为了获得事务性装置,我将所有活动强制到单个事务上,如下所示:

#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

4

1 回答 1

1

这里的问题与 Capybara 的 RackTest 驱动程序有关。处理请求后,它正在调用ActionDispatch::Reloader.cleanup!查看对 的评论,仅在为 falseActionDispatch::Reloader时才包含它。config.cache_classes

因此,一种解决方案是设置config.cache_classes为 true on environment/test.rb- 但这不是最佳解决方案。

另一种解决方案是使用另一个驱动程序(我自己没有尝试过),Capybara 带有不同的驱动程序。

我做了一些类似于 Brad 的事情——通过在我的使用 Capybara 访问的规范上重新加载蓝图。在您的规范中,您可以添加一个 after 块,例如:

describe "my test" do
    after do
        load_blueprint
    end
end

我将 reload_blueprint 方法放在 spec/support 目录中的文件上,即:spec/support/load_blueprint.rb

不过,这仍然是一种解决方法,而不是适当的解决方案。

于 2011-12-16T05:43:05.623 回答