Rails script/generate 默认跳过不必要的文件

发布于 2024-07-22 03:07:08 字数 163 浏览 3 评论 0原文

自从我开始使用 rspec 等以来,脚本/生成变得非常烦人。我不再需要单元测试文件和固定装置,但脚本/生成无论如何都会生成它们。

是否可以将 --skip-fixtures--skip-test 设置为默认系统范围(或至少项目范围)?

Script/generate became very annoying since I started using rspec etc. I dont need unit test files and fixtures anymore, but script/generate makes them anyway.

Is it possible to set --skip-fixtures and --skip-test to be default system-wide (or at least project-wide)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

会傲 2024-07-29 03:07:08

您可以编辑应用程序脚本/生成文件以自动附加选项

#!/usr/bin/env ruby

ARGV << "--skip-fixture" if ["model"].include?(ARGV[0])

require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'

You can edit your applications script/generate file to auto append options

#!/usr/bin/env ruby

ARGV << "--skip-fixture" if ["model"].include?(ARGV[0])

require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
白芷 2024-07-29 03:07:08

好吧,对于初学者来说,

ruby script/generate rspec_model
ruby script/generate rspec_controller

至少这不会生成单元测试,并且它为我提供了规范:)

但是 --skip-fixtures 仍然必须通过。 我刚刚在 .bash_profile 中创建了自己的别名

alias model='ruby script/generate rspec_model $1 --skip-fixture'

然后我就可以这样做

model bar name:string active:boolean

并且一切正常:)

Well, for starters,

ruby script/generate rspec_model
ruby script/generate rspec_controller

At least that doesn't generate unit tests and it gets the specs there for me :)

But --skip-fixtures still has to get passed. I've just made my own aliases in .bash_profile

alias model='ruby script/generate rspec_model $1 --skip-fixture'

Then I can just do

model bar name:string active:boolean

and it all works :)

你是暖光i 2024-07-29 03:07:08

我使用 minitest_rails 作为测试框架,您可以通过 config/application.rb 文件设置一些默认值。

config.generators do |g|
  g.test_framework :mini_test, :spec => true, :fixture => false
end

当您生成模型(和控制器)时,它现在将自动跳过夹具。 此示例还将使用 minitest_spec 格式创建单元测试。

I use minitest_rails as my testing framework, and you can set some defaults via the config/application.rb file.

config.generators do |g|
  g.test_framework :mini_test, :spec => true, :fixture => false
end

When you generate a model (and controller), it will now automatically skip the fixture. This example will also create the Unit Test using the minitest_spec format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文