如何创建黄瓜(水豚?)帮手

How to create cucumber (capybara?) helpers

我有一些代码想从我的步骤定义中重构​​出来并将它们放入.. helpers?

哦,还请说明如何包括它们,我真的很难找到任何可靠的信息。

直接来自此处的 rspec 文档:https://www.relishapp.com/rspec/rspec-core/docs/helper-methods/define-helper-methods-in-a-module#include-a-module-in-all-example-groups

在所有示例组中包含一个模块 给定一个名为 "include_module_spec.rb" 的文件:

require './helpers'

RSpec.configure do |c|
  c.include Helpers
end

RSpec.describe "an example group" do
  it "has access to the helper methods defined in the module" do
    expect(help).to be(:available)
  end
end

When
I run rspec include_module_spec.rb
Then
the examples should all pass

您还可以受益于 support/helpers 文件夹或此处介绍得很好的等效文件夹:How to include Rails Helpers on RSpec