本文介绍了使用 RSpec 2 关闭一个规范的事务性装置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 RSpec 2 仅关闭一个规范(或 Steak 场景)的事务性装置?我尝试了一些在网上找到的东西,但没有成功.

这会导致未定义的方法异常.

描述没有事务性装置的 MyClass"做self.use_transactional_fixtures = false...结尾

这根本不做任何事情(事务性夹具仍在运行):

描述没有事务性装置的 MyClass"做RSpec.configure 做 |config|config.use_transactional_fixtures = false结尾...结尾

我还能尝试什么?

解决方案

这曾经是一个错误(参见 ticket #197),但我现在似乎没事了.我只是不知道它是否适用于每个测试基地(可能不是).如果您想这样做,您可以通过将 config.use_transactional_fixtures = false 放在 spec_helper.rb 上并使用 DatabaseCleaner 来设置来全局禁用事务性装置.

在浏览器上使用 javascript 测试页面时,我遇到了类似的问题(这种情况不适用于事务性装置).这是我设法解决它的方法:http://github.com/lailsonbm/contact_manager_app

How do I turn off transactional fixtures for only one spec (or Steak scenario) with RSpec 2?I tried some things found on the web without any success.

This leads to an undefined method exception.

describe "MyClass without transactional fixtures" do
  self.use_transactional_fixtures = false
  ...
end

This simply does nothing (transactional fixture is still on):

describe "MyClass without transactional fixtures" do
  RSpec.configure do |config|
    config.use_transactional_fixtures = false
  end
  ...
end

What else could I try?

解决方案

This used to be a bug (see ticket #197), but I seems to be okay now. I just don't know if it will work on a per test base (probably not). If you want to do this, you can disable transactional fixtures globally by putting config.use_transactional_fixtures = false on the spec_helper.rb and use DatabaseCleaner to set that.

I've had a similar problem when testing pages with javascript on the browser (a scenario that does not work with transactional fixtures). Here's how I managed to work around it: http://github.com/lailsonbm/contact_manager_app

这篇关于使用 RSpec 2 关闭一个规范的事务性装置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 08:22