简体   繁体   English

我应该在 Rails6 中的什么地方放置 rspec 测试的辅助方法?

[英]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.

相关问题 我应该将 rspec 辅助函数放在哪里? - Where should I place the rspec helper functions? 我无法使用 haml 和 rails6 运行基本的 rspec 测试 - I can't run a basic rspec test with haml and rails6 RSpec:我应该在目录结构中的哪个地方放置覆盖多个类的集成测试? - RSpec: where in the directory structure should I place an integration test covering multiple classes? Rspec,Rails - 如何测试使用params hash的helper方法? - Rspec, Rails - how to test helper method that use params hash? 简化Rails助手的Rspec测试 - Streamline Rspec Test of Rails Helper 如何从Rails中的RSpec测试中调用app helper方法? - How to call an app helper method from an RSpec test in Rails? 我应该如何使用rspec rails测试此代码? - How should I test this code with rspec rails? 在何处放置帮助程序规范(用于测试Rails应用程序中其他内容的规范) - Where to place helper specs (specs that test additional things in a Rails app) 获取未定义的方法“空?” 当我尝试使用 Rails,Rspec 调用 Rails 路径助手 (*_path) 时,我的测试套件中的 nil:NilClass - Gettting undefined method `empty?' for nil:NilClass in my test suite when I try to call a Rails path helper (*_path) using Rails, Rspec 非常简单的Rspec rails测试没有通过,它应该在哪里 - Very simple Rspec rails test is not passing, where it should
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM