相关疑难解决方法(0)

为什么不为Rspec + Selenium使用共享的ActiveRecord连接?

似乎最常被接受的处理Selenium和测试的方法是避免使用事务夹具,然后在测试/场景之间使用像database_cleaner这样的东西.我最近遇到了以下文章,建议执行以下操作:

spec_helper.rb

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil

  def self.connection
    @@shared_connection || retrieve_connection
  end
end

# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
Run Code Online (Sandbox Code Playgroud)

对于性能而言,这似乎比替代品更好.有没有人有理由不这样做?

ruby rspec ruby-on-rails capybara

46
推荐指数
2
解决办法
8457
查看次数

标签 统计

capybara ×1

rspec ×1

ruby ×1

ruby-on-rails ×1