【问题标题】:Geb DSL Modules unrecognized within IntellijGeb DSL 模块在 Intellij 中无法识别
【发布时间】:2021-01-16 00:12:47
【问题描述】:

Going off the documentation hereModules 和其他 Geb DSL,预计不会在 IntelliJ 的 Spock 规范中被识别?这使得在没有 DSL 参考的情况下使用带有 IntelliJ 的 Geb 有点麻烦。 I noticed from this question 提问者做了一些自定义工作来让 IntelliJ 包装并注意到 Geb DSL。

我的问题是我做错了什么还是这是意料之中的,在让 IntelliJ 识别 Geb DSL 方面有任何进展吗?

如果没有,是否有人对此问题/限制和/或其他识别 Geb DSL 的 IDE 有解决方法?

【问题讨论】:

    标签: intellij-idea spock dsl geb


    【解决方案1】:

    IntelliJ 支持 Geb DSL,我已经使用了多年,there are even tests in IntelliJ's codebase that confirm it's there

    如果您可以分享您的代码的外观以及哪些内容不适合您,那么我们可能会发现您的设置或期望存在问题。最好知道您使用的是社区版还是专业版。

    请注意,您链接到的问题中讨论的问题已由我在 this PR 中修复,并且自 IntelliJ 2018.2 以来不再存在。

    编辑:

    在我的回复下阅读了您的 cmets 后,我现在明白了问题所在。您的期望是 IntelliJ 将能够在运行时确定页面类型并为您提供自动完成功能。恐怕这根本不可能——您需要在代码中跟踪当前页面实例,以便 IntelliJ 能够推断类型。

    注意geb-example-gradle 中的测试是用the very concise, yet dynamic style which means that IntelliJ is not able to infer types 编写的。您需要做的是使用strongly typed style as described in the documentation。文档的该部分可以做一些改进,因为它不精确 - 我创建了 a Github issue to track that

    基本上,如果您将 GebishOrgSpec 从 geb-example-gradle 调整为:

    class GebishOrgSpec extends GebSpec {
    
        def "can get to the current Book of Geb"() {
            when:
            def homePage = to GebishOrgHomePage
    
            and:
            homePage.manualsMenu.open()
    
            then:
            homePage.manualsMenu.links[0].text().startsWith("current")
    
            when:
            homePage.manualsMenu.links[0].click()
    
            then:
            at TheBookOfGebPage
        }
    }
    

    然后 IntelliJ 将为您提供自动补全功能。

    【讨论】:

    • I actually tried to use the geb-example project here with the issue as described。它会识别 spock speck 上的 at,但如果我尝试使用 ModulePage 中的 content 中的任何内容,例如links 在此规范上 here 那么它将无法被 Intellij 识别,并且找不到参考。我不能点链接模块/页面来查看它的内容等等......这是预期的吗?
    • 继续... IntelliJ 似乎无法识别 Spock SpecPagesModules 中的引用,但是 DSL 魔法应该按预期工作吗?根据我收集的信息,我必须手动初始化页面/模块才能点链并查看内容和/或方法中的引用?
    • 我已经编辑了我的回复,希望它现在回答了你的问题
    • 这看起来像答案,我在文档中错过了。感谢您花时间解释和参考解决方案!
    • 不客气!好的、有效的问题值得花时间来提供答案。顺便说一句,您可以通过接受和/或支持我的回答来表达您的感激之情。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2021-11-01
    • 2016-07-08
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    相关资源
    最近更新 更多