- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 database-cleaner
为我的 rails 4 应用程序配置,
每次运行测试时,我发现我的数据库在 test
中都被清除了。和 development
环境。
我的配置在 rails_helper
如下:
ENV["RAILS_ENV"] ||= 'test'
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'database_cleaner'
Rails.env = "test"
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = false
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, :js => true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.mock_with :rspec
config.before(:all) do
ActiveRecord::Base.skip_callbacks = true
end
config.after(:all) do
ActiveRecord::Base.skip_callbacks = false
end
end
test environment
中的数据库不碰我的
development
?
database.yml
如下:
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
<<: *default
database: directory-service_development
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
#username: directory-service
# The password associated with the postgres role (username).
#password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: directory-service_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: directory-service_production
username: directory-service
password: <%= ENV['DIRECTORY-SERVICE_DATABASE_PASSWORD'] %>
最佳答案
我建议改变
ENV["RAILS_ENV"] ||= 'test'
ENV["RAILS_ENV"] = 'test'
Rails.env = 'test'
关于ruby-on-rails-4 - database_cleaner 正在删除我的开发数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30784955/
我们有一个邮箱模型,它使用另一个邮件应用程序也连接到的辅助数据库。这称为使用 establish_connection :mail_database 现在,我想我可以尝试将它包装在 if 语句中,以便
我有 database-cleaner为我的 rails 4 应用程序配置, 每次运行测试时,我发现我的数据库在 test 中都被清除了。和 development环境。 我的配置在 rails_he
我使用 Mongoid 作为我的数据库,并按照其他 Stackoverflow 问题的说明配置了我的 spec_helper.rb 文件,但是我仍然收到错误消息,指出该对象在后续测试中存在。因此,da
我遇到了一个非常奇怪的案例。我有这种情况,有时它会过去。有时它没有。事实上,每一步都是绿色的,但是在这一步之后它会产生这个垃圾堆栈跟踪,它不会告诉我关于我的应用程序的任何信息。 我在这里没有做任何复杂
我正在使用 Turnip和 Ruby on Rails。我有使用和不使用 javascript 的场景。我想对非 javascript 场景使用 transaction DatabaseCleaner
在我们使用 MySql 的 Rails 4.0 应用程序中,我们使用 rspec 和配置了策略的 database_cleaner gem :transaction 来为每个测试用例清理我们的数据库。
我正在使用 Rspec 和 Capybara 运行集成规范,并使用 Database Cleaner 清除规范之间的记录。如果重要的话,我会使用 Guard 和 Spork 自动运行我的规范。 不知何
database_cleaner 在大部分情况下都有效,但在某些情况下,我希望在每次测试后清除 user_id 之类的东西,但它不会。因此,user_id 将自始至终递增而不是清除,并且用户 id 可
database_cleaner 在大部分情况下都有效,但在某些情况下,我希望在每次测试后清除 user_id 之类的东西,但它不会。因此,user_id 将自始至终递增而不是清除,并且用户 id 可
我的 Rails 3.1 应用程序中有以下 spec_helper.rb 文件。我正在使用 Spork 更快地加载环境以进行测试。在将 Spork 添加到混合物中之前,我的所有测试都有效。添加 spo
我正在尝试让 database_cleaner 与我的测试套件一起工作,但我在网上找不到关于此错误的任何信息: 错误无法找到 id=1 的用户 在我添加 database_cleaner 之前,测试运
我正在构建一个 Rails 应用程序,该应用程序将 MySQL 用于某些模型,将 MongoDB 用于其他模型(通过 mongo_mapper gem)。 我们已经开始为该应用程序构建 cucumbe
我正在尝试将 rspec 与 mongoid、devise、database_cleaner 一起使用,但出现此错误 Failure/Error: Unable to find matching l
我有一个使用 mongoid、database_cleaner 和 rspec 的现有项目。我尝试使用 active_admin patches available 添加 active_admin .
当尝试按照 database_cleaner 的 GitHub page 上的示例进行操作时,我遇到了 RSpec 的以下错误: ActiveRecord::StatementInvalid:
我有一个旧的 Rails 应用程序升级到 3.2.11 版,它有很多使用 capybara 1.0.1 版编写并使用 selenium 驱动程序运行的请求规范。每次测试后使用 database_cle
我想使用 zeus (0.13.3) 为 ruby 2.0.0 上的 rails (3.2.11) 应用程序预加载我的 rails 环境,并使用 database_cleaner (0.9.1)
我是一名优秀的程序员,十分优秀!