[英]Where should i place helper method for rspec test in Rails6?
I have helper method for rspec test like this: <bla_bla_helper.rb>我有这样的 rspec 测试辅助方法:<bla_bla_helper.rb>
Module blabla
def bla
end
end
Where should i place this module?我应该把这个模块放在哪里? This module is only for rspec test.本模块仅供rspec测试。
Past version of Rails used spec/support
directory, should i use this directory?过去版本的 Rails 使用spec/support
目录,我应该使用这个目录吗?
I usually place mine inside spec/support/helpers
and include it in the configuration via rails_helper
.我通常将我的放在spec/support/helpers
中,并通过rails_helper
将其包含在配置中。
Here's an example of including the devise API auth helper that I am using for my application.下面是一个包含 devise API 身份验证助手的示例,我正在为我的应用程序使用它。
config.include DeviseApiAuthHelper, type: :controller
Yes you can continue using spec/support directory.是的,您可以继续使用 spec/support 目录。
In RSpec you use spec/support
to place the helpers, matchers, shared contexts etc that your specs need.在 RSpec 中,您使用spec/support
来放置您的规范所需的助手、匹配器、共享上下文等。 This path is added to the load path so you can simply do require 'foo'
in your specs to require spec/support/foo.rb
.此路径已添加到加载路径,因此您可以简单地在您的规范中require 'foo'
以要求spec/support/foo.rb
。
Some projects use a glob in spec/spec_helper.rb
to require all the files in the spec/support
directory.一些项目在spec/spec_helper.rb
中使用 glob 来要求spec/support
目录中的所有文件。
This is just an RSpec convention that has nothing to do with Rails, so the practice isn't going to change with Rails versions.这只是一个与 Rails 无关的 RSpec 约定,因此这种做法不会随 Rails 版本而改变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.