停止 Rails 为视图和助手生成规范测试? [英] Stop Rails generating spec tests for views and helpers?

查看:27
本文介绍了停止 Rails 为视图和助手生成规范测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 application.rb 做到这一点?

Is there a way to do this from the application.rb?

推荐答案

简答置顶

如果您想在每次运行生成器时都这样做,您确实可以在 application.rb 文件中对其进行自定义.将此代码放在 Application 类定义内的文件中.

If you want to do this for every time you run the generators, you do indeed customize it within your application.rb file. Put this code in the file inside the Application class definition.

config.generators do |g|
  g.view_specs false
  g.helper_specs false
end

您也可以通过向生成器命令传递一些选项来完成此操作.这个 Railscast 更详细地介绍了这个过程,但基本思想是很简单.

You can also accomplish this by passing some options into the generator command. This Railscast goes over the process in more detail, but the basic idea is pretty simple.

Rails 生成器可以有多种选择.您可以通过运行 rails g controller -h 来查看控制器生成器的选项.假设您已经设置了 Rspec,如果您查看输出,您会注意到Rspec 选项"部分.它看起来像这样:

Rails generators can take several options. You can see the options for the controller generator by running rails g controller -h. Assuming you have Rspec set up already, if you look at the output, you notice a section that says "Rspec options". It looks like this:

Rspec options:
  [--controller-specs]  # Indicates when to generate controller specs
                        # Default: true
  [--view-specs]        # Indicates when to generate view specs
                        # Default: true

要否定这些布尔值,只需在名称前加上no"即可.因此,如果您想要一个没有视图规格的控制器,您可以这样称呼它:

To negate these boolean values, just pass them in with a "no" in front of the name. So if you wanted a controller with no specs for your view, you would call it like this:

rails g controller Foobar index show new create --no-view-specs

你会得到一个控制器,它为你创建了正确的视图和动作,但没有你的视图规范.

And you would get a controller with the correct views and actions created for you, but no specs for your views.

如果您使用 scaffold 生成器,则同样适用.有一个 --helper-specs 选项,所以如果你不想要视图或辅助规范,你可以运行:

The same thing applies if you are using the scaffold generator. There is a --helper-specs option, so if you wanted no view or helper specs you would run:

rails g scaffold Foobar name:string --no-helper-specs --no-view-specs

这篇关于停止 Rails 为视图和助手生成规范测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆