简体   繁体   English

黄瓜在场景结束之前执行挂钩之后

[英]Cucumber After hook is being executed before scenario ends

I have an After hook in hooks.rb that deletes users created in the last scenario. 我在hooks.rb中有一个After钩子,该钩子会删除在上一个方案中创建的用户。 I started to notice that when tests run at a specific time of the day , this hook is being executed in the middle of a scenario . 我开始注意到,当测试在一天中的特定时间运行 ,此挂钩正在场景的中间执行。 There is a method that executes until a certain line and then the hook executes just before an assert command in that method, which fails because of it. 有一种方法可以执行到特定的一行,然后挂钩在该方法中的assert命令之前执行,因此失败。 The tests are run from a batch file ("ruby file_name.rb"). 从批处理文件(“ ruby​​ file_name.rb”)运行测试。

Does anyone have an idea why this might happen or how to solve it? 有谁知道为什么会发生或如何解决呢?

Thanks! 谢谢!

Don't you run your tests from command line like following? 您不像下面这样从命令行运行测试吗?

$ cucumber

I would suggest to use debugger gem. 我建议使用调试器gem。 You could add debugger statement just before you think is failing and then use some debugger commands 您可以在认为失败之前添加调试器语句,然后使用一些调试器命令

https://github.com/cldwalker/debugger https://github.com/cldwalker/debugger

Perhaps related to: https://github.com/cucumber/cucumber/issues/52 可能与以下内容有关: https : //github.com/cucumber/cucumber/issues/52

Issue 52 is mostly fixed on the master, but I think there are a few remaining tests broken that need to be fixed before release. 问题52主要是在主数据库上解决的,但是我认为还有一些其余的测试需要解决,需要在发布之前进行修复。

Regardless of that, you might instead try using the database_cleaner gem for this purpose in general. 无论如何,您通常可以为此目的尝试使用database_cleaner gem。 We use a clean database before every scenario for testing to ensure we have discrete tests that cannot have false positive/negative results due to results of other tests. 在每种情况下进行测试之前,我们都会使用干净的数据库,以确保我们进行的离散测试不会因其他测试的结果而导致假阳性/阴性结果。 We use the following: 我们使用以下内容:

begin
  # start off entire run with with a full truncation
  DatabaseCleaner.clean_with :truncation
  # continue with the :transaction strategy to be faster while running tests.
  DatabaseCleaner.strategy = :transaction
rescue NameError
  raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

And we load our test seeds before each run: Before do |scenario| 而且,我们在每次运行之前加载测试种子: load Rails.root.join('db/seeds.rb') end 加载Rails.root.join('db / seeds.rb')结束

Note that our seeds.rb checks which environment it is running in to keep it short. 请注意,我们的seed.rb会检查它在哪个环境中运行以使其简短。 A big seeds file run in this manner would significantly increase test run times, so be careful. 以这种方式运行较大的种子文件会大大增加测试运行时间,因此请小心。

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

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