简体   繁体   English

水豚是否会忽略before(:all)块中的代码? 我该怎么办?

[英]Does capybara ignore code in a before(:all) block? What can I do about this?

I completely understand why you should use before(:each) and make all expectations independent of each other, but I'm just interested into why this would happen: 我完全理解为什么您应该使用before(:each)并使所有期望彼此独立,但是我只是想知道为什么会这样:

before(:each) { visit "/" } # Selenium visits the root path of my app
before(:all) { visit "/" } # Selenium doesn't even open firefox. 

Nothing happens with the background(:all) , but if I raise an exception in the same context, Selenium does open firefox and visits this weird empty file. background(:all)没有任何反应,但是如果我在相同的上下文中引发异常,Selenium确实会打开Firefox并访问此奇怪的空文件。

file:///home/starkers/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.2.0/lib/capybara/empty.html

So does anyone know if Capybara actively ignores code in a before block(:all), and if so, how can I get it to not ignore code in a before(:all)? 那么,有谁知道Capybara是否主动忽略before块(:all)中的代码?

This isn't really serious project, but I was thinking about benchmarking with Capybara, so it would be nice if someone showed me a way to get Capybara working with a before(:all). 这不是一个很认真的项目,但是我正在考虑与Capybara进行基准测试,因此如果有人向我展示一种使Capybara与before(:all)一起工作的方法,那将是很好的。

There is a distinct difference in these two before blocks. 这两个before块有明显的不同。

before(:each) is evaluated before every test. before(:each)每次测试之前评估before(:each)

before(:all) is evaluated before running your tests. before(:all)运行测试之前,对before(:all)进行评估。 Once. 一旦。

You should probably be using before(:each) 您可能应该使用before(:each)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM