RubyMine 中的 Capybara 代码完成
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后找到了解决办法。
我将 Cucumber 与 Capybara 一起使用,并且在
/features/support/spec/spec_helper.rb
中包含了我想要完整编码的所有匹配器。 Cucumber 自动加载该文件中的所有内容。我敢打赌,如果您不使用黄瓜,您还可以在其他地方包含这些语句。对于您的具体情况:
包含 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.For your specific case:
include Capybara::DSL
Then
从 RubyMine 8.0.3 开始,答案是否定的,RubyMine 不会在 Cucumber 步骤定义中完成
page.
之后的 Capybara 方法,至少当 Capybara 通过 cucumber-rails gem 包含在 Cucumber 中时不会。 我在 RubyMine 问题跟踪器中没有看到功能请求;如果有人愿意,可以添加一个。请注意,cucumber-rails 至少在 Cucumber 世界中包含了 Capybara DSL,因此您无需在 Capybara 方法前面键入
page.
。您可以将visit
、fill_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 callvisit
,fill_in
, etc. as self methods. I wouldn't want unnecessarypage.
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.