Ruby on rails 默认情况下,Minitest Rails规范样式测试

Ruby on rails 默认情况下,Minitest Rails规范样式测试,ruby-on-rails,ruby,minitest,Ruby On Rails,Ruby,Minitest,问题:使用Rails 5和Minitest Rails有没有一种方法可以将新Rails应用默认为规范样式测试 我教TDD,每次我们制作新的应用程序时都要让学生进行转换,这很烦人。您可以创建一个模板.rb文件,配置如下: gem_组:开发:测试 gem“rspec轨道” 结束 你做什么 `轨道g rspec:安装` 结束 然后使用以下命令构建一个新的Rails项目 rails new my_app -T -m /path/to/template.rb 它将构建一个新的Rails应用程序,将Ra

问题:使用Rails 5和Minitest Rails有没有一种方法可以将新Rails应用默认为规范样式测试


我教TDD,每次我们制作新的应用程序时都要让学生进行转换,这很烦人。

您可以创建一个
模板.rb
文件,配置如下:

gem_组:开发:测试
gem“rspec轨道”
结束
你做什么
`轨道g rspec:安装`
结束
然后使用以下命令构建一个新的Rails项目

rails new my_app -T -m /path/to/template.rb
它将构建一个新的Rails应用程序,将Rails RSpec gem添加到它的gem文件中,并执行RSpec的安装步骤

否则,您可以提供一个预构建的Rails Git存储库并在此基础上构建

参考文献:


它看起来像是在
config/application.rb
中,您只需添加:


config.do | g|
g、 测试框架:minitest,规格:true
结束

然而,并没有一种自动的方法使Minitest Rails默认为规范样式测试


我可以去rspec,但我宁愿暂时留在Minitest,因为我们从一开始就教我们的学生Minitest。

好的,所以@sonna有我想要的90%

最后,我得到了帮助,创建了一个
.railsrc
文件

-d postgresql
-m ~/.template.rb
以及包含以下内容的模板:

# .template.rb
# Gems we've talked about in class, but which have absolutely nothing to do
# with setting up spec-style testing.
# Included here for convenience.
gem_group :development do
  # Improve the error message you get in the browser
  gem 'better_errors'

  # Use pry for rails console
  gem 'pry-rails'
end

# Add some extra minitest support
gem_group :test do
  gem 'minitest-rails'
  gem 'minitest-reporters'
end

# Add some code to some files to support spec-style testing
# For these injections, indentation matters!
inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do
  <<-'RUBY'
    # Force new test files to be generated in the minitest-spec style
    config.generators do |g|
      g.test_framework :minitest, spec: true
    end
  RUBY
end

# Things to do after all the gems have been installed
after_bundle do
  # Run rails generate minitest:install
  generate "minitest:install", "--force"

  # Add minitest reporters support. This must be run after
  # rails generate minitest:install, because that command
  # changes test/test_helper.rb
  inject_into_file 'test/test_helper.rb', after: 'require "minitest/rails"' do
    <<-'RUBY'

require "minitest/reporters"  # for Colorized output

#  For colorful output!
Minitest::Reporters.use!(
  Minitest::Reporters::SpecReporter.new,
  ENV,
  Minitest.backtrace_filter
)
    RUBY
  end
end
#.template.rb
#我们在课堂上讨论过的宝石,但它们完全没有什么关系
#设置规范样式测试。
#包括在这里是为了方便。
gem_集团:发展怎么办
#改进浏览器中的错误消息
gem“更好的错误”
#使用撬杆固定控制台导轨
宝石“撬轨”
结束
#添加一些额外的minitest支持
gem_组:testdo
gem“迷你测试轨道”
创业板“微型记者”
结束
#向某些文件添加一些代码以支持规范样式测试
#对于这些注射,压痕很重要!
在“class application看来你已经完成了回答问题的艰苦工作。但是如果你教的是一组固执己见的测试宝石,以及一个改进的TestIHelpR.RB和一个改进的Appultual.Rb,你可能会考虑编写你自己的GEM,你的学生可以将它们添加到GEMFILE中。gem可以将您想要的测试gem作为依赖项,然后它们可以使用以下内容安装所需的一切:

bin/rails生成:安装

这里有一个我写的宝石,你可以叉或修改或只是作为灵感使用

实际上,我偷了上面gem的配置代码,您可以在这里的生成器中看到它的表达式:


lib/generators/installer/install_generator.rb您可以执行
rails new my_app-T
,它将跳过测试,然后将
rspec
添加到GEM文件并运行
rspec init
。我通常就是这么想的recommend@anthony是的,但是我确实想使用Minitest而不是rspec进行测试。使用Ruby-on-Rails应用程序模板是最好的选择,请看一看,谢谢,但是我不想使用rspec,而是Minitest。然而,模板可能是一条路要走。