使用模块扩展 Cucumber 并访问 Before/After 挂钩

发布于 2024-08-03 07:25:13 字数 248 浏览 2 评论 0原文

我正在尝试编写一个通用模块来扩展 World 类。我需要从模块内访问 Before 和 After 挂钩。我正在使用扩展方法来执行此操作,但此时“之前/之后”似乎不可用。

module MyWorld
  def MyWorld.extended(obj)
    obj.Before do
      # this doesn't work
    end
  end
end

还有其他方法可以访问这些钩子吗?

I am trying to write a generic module to extend the World class. I need to access the Before and After hooks from within the module. I am doing this by using the extended method but Before/After does not seem to be available at this point.

module MyWorld
  def MyWorld.extended(obj)
    obj.Before do
      # this doesn't work
    end
  end
end

Is there another way to access these hooks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心凉 2024-08-10 07:25:13

发现如何做到这一点:

module MyWorld
  def MyWorld.extended(obj)
    Main.Before do
      # some stuff
    end

    Main.After do
      # some other stuff
    end   
  end
end

Found out how to do it:

module MyWorld
  def MyWorld.extended(obj)
    Main.Before do
      # some stuff
    end

    Main.After do
      # some other stuff
    end   
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文