RubyMine 中的 Capybara 代码完成

发布于 2024-10-28 16:32:02 字数 754 浏览 7 评论 0原文

Cucumber 的步骤定义中使用 Capybara 时,是否可以从 RubyMine 的代码完成中获得一些帮助?我是Capybara的新手,所以不必一直检查参考站点会非常有帮助。

目前我能得到的最好方法是显式调用 Session.new,如下所示:

session = Capybara::Session.new(:rack_test, my_app)

这样 Ctrl+Space after session. 向我展示来自 Capybara::Session 的方法(仅限),所以至少我知道它可以以某种方式访问​​。但这并不是我在步骤定义中真正使用 Capybara 的方式。我认为通过手动注释 page 来帮助类型推断引擎可以解决问题,但我认为所有这些 DSL 魔法都难以处理。

所以基本上,是否有可能

page.<Ctrl+Space>

以某种方式弹出所有公开的 DSL 方法? RubyMine API 可能吗?或者,作为替代方案,有其他方法可以使参考文档更接近(我认为 RubyMine 还不支持 IDE 中的外部文档)?

Is there a way to get some help from RubyMine's code completion when using Capybara in Cucumber's step definitions? I'm new to Capybara, so not having to check the reference site all the time would be really helpful.

The best I can get at the moment is by explicitly calling Session.new, something like:

session = Capybara::Session.new(:rack_test, my_app)

This way Ctrl+Space after session. shows me methods from Capybara::Session (only) so at least I know it's somehow reachable. But that's not how I really use Capybara in my step definitions. I thought that helping the type inference engine by manually annotating page could do the trick, but I suppose all this DSL magic is too much to handle.

So basically, is it somehow possible to have

page.<Ctrl+Space>

pop up with all the exposed DSL methods? RubyMine API maybe? Or, as an alternative, some other way to bring the reference docs closer (I don't think RubyMine supports external docs in the IDE yet)?

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

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

发布评论

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

评论(2

口干舌燥 2024-11-04 16:32:02

最后找到了解决办法。

我将 Cucumber 与 Capybara 一起使用,并且在 /features/support/spec/spec_helper.rb 中包含了我想要完整编码的所有匹配器。 Cucumber 自动加载该文件中的所有内容。我敢打赌,如果您不使用黄瓜,您还可以在其他地方包含这些语句。

# Needed for RubyMine code completion
include Capybara::Node::DocumentMatchers
include Capybara::Node::Matchers
include Capybara::SessionMatchers
include Capybara::RSpecMatchers
include Capybara::RSpecMatcherProxies

输入图片此处描述

对于您的具体情况:
包含 Capybara::DSL

然后

在此处输入图像描述

Finally, found a solution.

I am using Cucumber with Capybara and I included all the matchers I wanted to code complete in /features/support/spec/spec_helper.rb. Cucumber auto-loads everything in this file. I bet there are other places you can include these statements if you aren't using cucumber.

# Needed for RubyMine code completion
include Capybara::Node::DocumentMatchers
include Capybara::Node::Matchers
include Capybara::SessionMatchers
include Capybara::RSpecMatchers
include Capybara::RSpecMatcherProxies

enter image description here

For your specific case:
include Capybara::DSL

Then

enter image description here

甜点 2024-11-04 16:32:02

从 RubyMine 8.0.3 开始,答案是否定的,RubyMine 不会在 Cucumber 步骤定义中完成 page. 之后的 Capybara 方法,至少当 Capybara 通过 cucumber-rails gem 包含在 Cucumber 中时不会。 我在 RubyMine 问题跟踪器中没有看到功能请求;如果有人愿意,可以添加一个。

请注意,cucumber-rails 至少在 Cucumber 世界中包含了 Capybara DSL,因此您无需在 Capybara 方法前面键入 page.。您可以将 visitfill_in 等作为 self 方法调用。我不想仅仅为了 RubyMine 的完成而在我的步骤定义中添加不必要的 page.

不幸的是,当您在键入任何内容之前在步骤定义中调用完成时,RubyMine 也不将 Capybara 方法包含在它完成的名称列表中。当您两次调用完成时(所有可用代码中的所有名称),它确实将 Capybara 方法包含在它完成的名称列表中,但由于该列表太长,只有当您已经知道您想要的方法,或者至少知道一个方法时,它才有用。正确的前缀。

As of RubyMine 8.0.3 the answer is no, RubyMine does not complete Capybara methods following page. in Cucumber step definitions, at least not when Capybara is included in Cucumber via the cucumber-rails gem. I don't see a feature request in the RubyMine issue tracker; someone could add one if they like.

Note that cucumber-rails, at least, includes the Capybara DSL in the Cucumber world, so you don't need to type page. in front of Capybara methods. You can just call visit, fill_in, etc. as self methods. I wouldn't want unnecessary page. in my step definitions just for the sake of RubyMine completion.

Unfortunately, RubyMine also doesn't include Capybara methods in the list of names it completes when you invoke completion in a step definition before you type anything. It does include Capybara methods in the list of names it completes when you invoke completion twice (all names in all available code), but since that list is so long it's only helpful if you already know the method you want already, or at least a correct prefix.

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