黄瓜:在所有情况下,挂钩只运行一次 [英] Cucumber: Before hook run only once for all scenarios

查看:167
本文介绍了黄瓜:在所有情况下,挂钩只运行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景大纲与多个场景。我想我的挂钩只运行一次,所以我可以引导ActiveRecord对象,我需要运行所有的场景。问题是如果我使用

I have a scenario outline with multiple scenarios. I'd like my Before hook to run only once so I can bootstrap the ActiveRecord objects I need to run against all of the scenarios. The problem is if I use

Before do
    # my code here
end

这将在每个场景之前执行。

This will execute before each Scenario. Is there anyway to run it once for the entire Outline?

推荐答案

我想如果你只是创建一个文件中的对象, em> features / support ,它们将被保留:

I think if you simply create the objects in a file in features/support they will be persisted:

ImportantThing.create(:name => "USEFUL THING")

这是因为在每个场景Cucumber将启动一个数据库事务,然后回滚到其先前的状态,其中应包含您加载的对象。

This is because before every Scenario Cucumber will start a database transaction and then rollback to its prior status, which should contain the objects you've loaded.

这篇关于黄瓜:在所有情况下,挂钩只运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆