如何制作黄瓜(水豚?)帮手

时间:2015-11-12 07:58:04

标签: ruby-on-rails cucumber

我有一些代码我想从我的步骤定义中重构​​并将它们放在里面..帮助器?

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

1 个答案:

答案 0 :(得分:1)

直接来自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

您也可以从支持/帮助文件夹或同等文件中受益,这里有很好的介绍:How to include Rails Helpers on RSpec