Cucumber:在钩子之前,所有场景仅运行一次
我有一个包含多个场景的场景大纲。我希望 Before 挂钩仅运行一次,以便我可以引导针对所有场景运行所需的 ActiveRecord 对象。问题是如果我使用
Before do
# my code here
end
这将在每个场景之前执行。有没有办法对整个大纲运行一次?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为,如果您只是在 features/support 中的文件中创建对象,它们将被持久化:
这是因为在每个场景 Cucumber 之前都会启动一个数据库事务,然后回滚到其先前的状态,其中应该包含您已加载的对象。
I think if you simply create the objects in a file in features/support they will be persisted:
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.
我遇到了同样的问题,我需要为所有事件日志记录测试创建一次订阅者管理器。如果我只使用 before 挂钩或常规步骤(例如给定),则将在每个场景之前创建管理器。
我的解决方案最终是在我的第一个场景中使用标记的 before 钩子。
为了关闭我的经理,我在最后一个场景中使用了标记的 After 钩子
I had the same problem, where I needed to create a subscriber manager once for all of my event logging tests. If I just used a before hook or a regular step (e.g. a Given), the manager would be created before each scenario.
My solution was ultimately to use a tagged before hook on my first scenario.
To shutdown my manager, I used a tagged After hook with my last scenario