如何从现有的 Rails 4 项目中删除 rspec 并恢复到 minitest 默认值? [英] How can I remove rspec from existing Rails 4 project and revert to minitest default?
问题描述
我正在向现有的 Rails 4 项目添加一些 API 测试,该项目的 Gemfile 中包含 rspec.
I'm adding some API tests to an existing Rails 4 project which has rspec in it's Gemfile.
由于现有项目没有任何测试,而且我在 minitest 中有我想要使用的测试,我想知道如何从此项目中删除 rspec 并恢复到 Rails 4 minitest 设置.
Since the existing project did not have any tests, and I have tests in minitest that I want to use, I'd like to know how to remove rspec from this project and revert to the Rails 4 minitest setup.
我已经从 Gemfile 中删除了 rspec gem 并进行了捆绑.我尝试手动创建 Test 文件夹和子文件夹,然后运行测试.当我运行 'rake' 时,我得到:
I've removed the rspec gem from the Gemfile and bundled. I tried to manually create the Test folder and subfolders manually then run tests. When I run 'rake' I get:
不知道如何构建任务默认"
我怀疑我可以将 test-unit 和 minitest gem 添加到 Gemfile 中,但我希望有一种方法可以简单地告诉 Rails '如果我以前没有 rspec,你会使用什么.'
I suspect I can add the test-unit and minitest gems into the Gemfile but I was hoping there was a way I could simply tell Rails 'use what you would have used if I didn't have rspec previously.'
推荐答案
该项目最初可能是使用 --skip-test-unit
标志生成的.这会导致测试单元代码没有被加载,这就解释了为什么 rake
没有调用它.
It is possible that the project was originally generated with the --skip-test-unit
flag. This results in the test unit code not being loaded, which would explain why rake
does not invoke it.
检查config/application.rb
.如果它看起来像这样:
Check config/application.rb
. If it looks like this:
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
然后取消注释 rails/test_unit/railtie
行以确保加载了测试单元.
Then uncomment the rails/test_unit/railtie
line to ensure test unit is loaded.
或者,您可以将整个部分替换为:
Alternatively, you can replace the whole section with:
require "rails/all"
这篇关于如何从现有的 Rails 4 项目中删除 rspec 并恢复到 minitest 默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!