Ruby on rails 为什么每次运行测试时都会创建数据库?
我是一个使用minitest进行测试的新手,在开始测试时遇到了困难。我想知道为什么每次运行测试时都会重新创建数据库。我看过的示例视频似乎不是这样()。我的设置不正确吗?每次都应该这样吗 每次运行Ruby on rails 为什么每次运行测试时都会创建数据库?,ruby-on-rails,ruby,unit-testing,minitest,Ruby On Rails,Ruby,Unit Testing,Minitest,我是一个使用minitest进行测试的新手,在开始测试时遇到了困难。我想知道为什么每次运行测试时都会重新创建数据库。我看过的示例视频似乎不是这样()。我的设置不正确吗?每次都应该这样吗 每次运行rake minitest:models时,我都会在运行测试之前看到下面的内容(缩短,因为它类似于500行) 测试助手.rb ENV["RAILS_ENV"] = "test" require File.expand_path("../../config/environment", __FILE__) r
rake minitest:models
时,我都会在运行测试之前看到下面的内容(缩短,因为它类似于500行)
测试助手.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require 'minitest/rails'
require 'minitest/focus'
# To add Capybara feature tests add `gem "minitest-rails-capybara"`
# to the test group in the Gemfile and uncomment the following:
require "minitest/rails/capybara"
# Uncomment for awesome colorful output
require "minitest/pride"
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
def self.prepare
# Add code that needs to be executed before test suite start
end
prepare
def setup
# Add code that need to be executed before each test
end
def teardown
# Add code that need to be executed after each test
end
end
require File.expand_path('../boot', __FILE__)
require "active_record/railtie"
require "action_controller/railtie"
require 'rake/testtask'
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
require "minitest/rails/railtie"
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Martinfurniture
class Application < Rails::Application
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Allows for sub-directories in Models
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
config.active_record.whitelist_attributes = true
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config.sass.debug_info = true
config.exceptions_app = self.routes
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
# Devise
config.assets.initialize_on_precompile = false
# Testing
config.generators do |g|
g.test_framework :mini_test
g.helper false
g.assets false
g.view_specs false
end
end
end
应用程序.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require 'minitest/rails'
require 'minitest/focus'
# To add Capybara feature tests add `gem "minitest-rails-capybara"`
# to the test group in the Gemfile and uncomment the following:
require "minitest/rails/capybara"
# Uncomment for awesome colorful output
require "minitest/pride"
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
def self.prepare
# Add code that needs to be executed before test suite start
end
prepare
def setup
# Add code that need to be executed before each test
end
def teardown
# Add code that need to be executed after each test
end
end
require File.expand_path('../boot', __FILE__)
require "active_record/railtie"
require "action_controller/railtie"
require 'rake/testtask'
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
require "minitest/rails/railtie"
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module Martinfurniture
class Application < Rails::Application
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
# Allows for sub-directories in Models
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]
config.active_record.whitelist_attributes = true
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config.sass.debug_info = true
config.exceptions_app = self.routes
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
# Devise
config.assets.initialize_on_precompile = false
# Testing
config.generators do |g|
g.test_framework :mini_test
g.helper false
g.assets false
g.view_specs false
end
end
end
需要文件。展开路径('../boot',文件)
需要“活动记录/轨道连接”
需要“控制器/轨道连接的操作”
需要“rake/testtask”
要求采取“行动”\u邮递员/railtie
需要“活动资源/railtie”
需要“链轮/系杆”
需要“微型测试/轨道/枕木”
如果定义?(捆绑机)
Bundler.require(*Rails.groups(:资产=>%w(开发测试)))
终止
家具模块
类应用程序
您可以关闭所有sql查询的打印,使用ActiveRecord::Base.logger=nil
根据TDD原则,每次运行测试时都应清除可重复的测试数据库。因此,数据库删除似乎是预期的行为。谢谢,有没有办法让它不打印数据库创建(它创建了大量的视觉混乱)?oops,这应该是为了响应:>谢谢,有没有办法让它不打印数据库创建(它创建了大量的视觉混乱)?——6小时前的贪婪