重新生成 rspec 文件

发布于 2024-12-19 11:19:27 字数 365 浏览 0 评论 0原文

如何按需生成 rspec?

问题是我的 rspec 文件已经由“railsgeneratecontroller”命令自动生成。然后我手动删除了这些文件,希望有一个命令可以用来重新生成这些文件。 我该如何重新生成那些已删除的 rspec 文件而不再次触发“rails 生成控制器”?

我尝试了一些博客建议的一些命令:

$ rails generate rspec_controller pages --skip-migration --skip-fixture --skip
Could not find generator rspec_controller.

但它对我不起作用。

任何建议将非常感激!

how can I generate rspec on-demand?

the thing was my rspec files were already automatically generated by the "rails generate controller" command. Then I manually deleted those files in hope that there should be a command which I can use to regenerate those files.
What do I do to regenerate those deleted rspec files without firing "rails generate controller" again?

I have tried some command I was suggested by some blog:

$ rails generate rspec_controller pages --skip-migration --skip-fixture --skip
Could not find generator rspec_controller.

but it didn't work for me.

any advice would be really appreciated!

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

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

发布评论

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

评论(3

坐在坟头思考人生 2024-12-26 11:19:27

在应用程序的根文件夹中:

rails generate controller -h

它将向您显示使用说明。

In the root folder of your app:

rails generate controller -h

It will show you the usage instructions.

得不到的就毁灭 2024-12-26 11:19:27

rspec_controller 已被弃用,取而代之的是 Rails 中的标准 controller 生成器。现在,您可以将 rspec-rails 包含在 Gemfile 中,如下所示:

group :development, :test do
  gem 'rspec-rails'
end

然后将加载 此文件,它自定义 Rails controller 生成器与 这两行

rspec_controller is deprecated in favour of the standard controller generator in Rails. It works now by you including rspec-rails within your Gemfile like this:

group :development, :test do
  gem 'rspec-rails'
end

This then will load this file, which customizes what tools the Rails controller generator uses with these two lines.

一人独醉 2024-12-26 11:19:27

这是一个坏主意,有两个原因:

  • 您通常不应该自动生成规范文件:您需要准确地考虑您想要指定的内容。
  • 通常根本不应该编写控制器规格。使用 Cucumber 场景来代替——它们的痛苦要小得多,并且在测试行为方面要好得多(控制器规格过于依赖于实现)。

This is a bad idea, for two reasons:

  • You normally shouldn't be autogenerating your spec files: you need to think about exactly what you want to specify.
  • Controller specs should normally not be written at all. Use Cucumber scenarios instead -- they're much less painful and much better at testing behavior (controller specs are too dependent on implementation).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文