在哪里放置萝卜步骤定义的配置(where to put config for turnip step definitions)

编程入门 行业动态 更新时间:2024-10-10 17:31:24
在哪里放置萝卜步骤定义的配置(where to put config for turnip step definitions)

我正在尝试为我的rails应用程序构建测试功能。 我正在使用萝卜来编写功能测试。 在github页面中,据说将步骤定义放在模块“您现在可以在RSpec中包含此模块”之后。 但目前尚不清楚推荐的RSpec在哪里。 它是文件夹还是文件,它在哪里?

有人可以澄清一下吗?

谢谢。

I am trying to build testing capability for my rails application. I am using turnip to write feature test. In the github page, it is said that after putting the step definitions in a module "You can now include this module in RSpec". But it is not clear where the referred RSpec is. Is it a folder or a file and where it is?

Could anyone please clarify on this?

Thanks.

最满意答案

萝卜文档中提到的RSpec.configure块可以在spec/spec_helper.rb和/或spec/rails_helper.rb 。 您可能只有一个文件。 在那里,你可以包括你的步骤:

RSpec.configure do |config| config.include MonsterSteps # other settings... end

两者之间的区别在于,前者仅加载最少量的代码以使库规范更快,而后者加载整个Rails堆栈。 您需要自己决定需要助手的位置。 如果您不确定,请将其放在spec/spec_helper.rb因为这将使其适用于所有规格。

如果您根本没有rspec文件夹,则需要将rspec-rails添加到Gemfile:

gem 'rspec-rails', group: [:development, :test]

然后运行

bundle install

最后生成基本的RSpec文件

rails generate rspec:install

The RSpec.configure block mentioned in the turnip documentation can be found in spec/spec_helper.rb and/or spec/rails_helper.rb. It is possible that you have only one of the files. There, you can include your steps:

RSpec.configure do |config| config.include MonsterSteps # other settings... end

The difference between the two is that the former loads only a minimal amount of code to make library specs faster, and the latter one loads the entire Rails stack. You need to decide on your own where you need the helpers. If you are not sure, put it in spec/spec_helper.rb as this will make it available to all specs.

If you don't have a rspec folder at all, you need to add rspec-rails to your Gemfile:

gem 'rspec-rails', group: [:development, :test]

then run

bundle install

and finally generate the basic RSpec files with

rails generate rspec:install

更多推荐

本文发布于:2023-08-07 18:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465328.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:萝卜   步骤   定义   put   definitions

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!