- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将我的 rails 应用程序迁移到 RSpec。但我收到错误 uninitialized constant ActiveRecord::Relation
运行规范时。它说它在 application.rb 的第 10 行,即 Bundler.require(:default, Rails.env) if defined?(Bundler)
错误信息
An error occurred while loading rails_helper.
Failure/Error: require File.expand_path('../config/environment', __dir__)
NameError:
uninitialized constant ActiveRecord::Base
# ./config/application.rb:12:in `<top (required)>'
# ./config/environment.rb:4:in `require'
# ./config/environment.rb:4:in `<top (required)>'
# ./spec/rails_helper.rb:11:in `require'
# ./spec/rails_helper.rb:11:in `<top (required)>'
# ------------------
# --- Caused by: ---
# NameError:
# uninitialized constant ActiveRecord::Base
# ./config/application.rb:12:in `<top (required)>'
require 'rails_helper'
RSpec.describe Api::V1::CertificateRequestsController, type: :controller do
describe '#create_v1_4' do
it 'worked' do
expect(true).to eq(true)
end
end
end
# frozen_string_literal: true
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
# have no way to turn it off -- the option exists only for backwards
# compatibility in RSpec 3). It causes shared context metadata to be
# inherited by the metadata hash of host groups and examples, rather than
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups
end
# frozen_string_literal: true
# This file is copied to spec/ when you run 'rails generate rspec:install'
puts "Your env: #{ENV.fetch('RAILS_ENV', 'test')}"
require 'spec_helper'
require 'database_cleaner'
require 'pry'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
# binding.pry
# Prevent database truncation if the environment is production
if Rails.env.production?
abort('The Rails environment is running in production mode!')
end
require 'rspec/rails'
# include Warden::Test::Helpers
# Warden.test_mode!
# 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.
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
puts e.to_s.strip
exit 1
end
RSpec.configure do |config|
# 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 = true
# 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`.
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
end
# frozen_string_literal: true
require File.expand_path('boot', __dir__)
require 'oauth/rack/oauth_filter'
require 'rack/ssl-enforcer'
require 'rails/all'
require './lib/middleware/catch_json_parse_errors'
Bundler.setup
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
CLIENT_OPTIONS = ['aswesome.com', 'aswementer'].freeze
DEPLOYMENT_CLIENT = CLIENT_OPTIONS[0]
Struct.new('Expiring', :before, :after, :cert)
Struct.new('Notification', :before, :after, :domain, :expire, :reminder_type, :scanned_certificate_id)
Struct.new('Reminding', :year, :cert)
module AwesomeApp
class Application < Rails::Application
# set environment variables
config.before_configuration do
env_file = File.join(Rails.root, 'config', 'local_env.yml')
YAML.safe_load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value
end
end
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W[#{config.root}/lib]
Bundler.require(*Rails.groups)
# Config::Integration::Rails::Railtie.preload
# Add additional load paths for your own custom dirs
%w[observers mailers middleware serializers].each do |dir|
config.autoload_paths << "#{config.root}/app/#{dir}"
end
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# 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 += %i[password password_confirmation]
# config.action_mailer.default_url_options = { :host => Settings.actionmailer_host }
# machinist generator
# config.generators do |g|
# g.fixture_replacement :machinist
# end
# Rails Api
config.api_only = false
# turn off strong parameters
config.action_controller.permit_all_parameters = true
config.generators do |g|
g.test_framework :minitest, spec: true, fixture: false
g.jbuilder false
end
# config.middleware.use OAuth::Rack::OAuthFilter
config.middleware.insert_before ActionDispatch::ParamsParser, 'CatchJsonParseErrors'
# Delayed Job
config.active_job.queue_adapter = :delayed_job
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '/certificate/*',
headers: :any,
methods: %i[get post delete put options head],
max_age: 0
end
end
# Enable the asset pipeline
config.assets.enabled = true
config.sass.preferred_syntax = :sass
config.sass.line_comments = false
config.sass.cache = false
config.action_mailer.default_url_options = { host: 'secure.ssl.com', protocol: 'https' }
if DEPLOYMENT_CLIENT =~ /certassure/i && Rails.root.to_s =~ /Development/
paths['config/database'] = 'config/client/certassure/database.yml'
end
end
end
require "#{Rails.root}/lib/base.rb"
require "#{Rails.root}/lib/asset_tag_helper.rb"
require "#{Rails.root}/lib/array.rb"
require "#{Rails.root}/lib/range.rb"
require "#{Rails.root}/lib/in_words.rb"
require "#{Rails.root}/lib/kernel.rb"
require "#{Rails.root}/lib/money.rb"
# require "#{Rails.root}/lib/subdomain-fu.rb"
require "#{Rails.root}/lib/domain_constraint.rb"
require "#{Rails.root}/lib/preferences.rb"
require "#{Rails.root}/lib/active_record.rb"
require "#{Rails.root}/lib/active_record_base.rb"
require "#{Rails.root}/lib/hash.rb"
require 'will_paginate'
# try to figure this out for heroku and rails 3
# class Fixnum; include InWords; end
# class Bignum; include InWords; end
DB_STRING_MAX_LENGTH = 255
DB_TEXT_MAX_LENGTH = 40_000
HTML_TEXT_FIELD_SIZE = 20
AMOUNT_FIELD_SIZE = 10
ADDRESS_FIELD_SIZE = 30
SERVER_SIDE_CART = false
# SQL_LIKE = Rails.configuration.database_configuration[Rails.env]['adapter'].
# downcase=='postgresql' ? 'ilike' : 'like'
db_env = Rails.configuration.database_configuration[Rails.env]
db_adapter = db_env['adapter'].downcase if db_env.present?
SQL_LIKE = db_adapter == 'postgresql' ? 'ilike' : 'like'
# uncomment to track down bugs on heroku production
# ApplicationRecord.logger.level = 0 # at any time
ActiveMerchant::Billing::CreditCard.require_verification_value = false
PublicSuffix::List.default =
PublicSuffix::List.parse(File.read(PublicSuffix::List::DEFAULT_LIST_PATH), private_domains: false)
# frozen_string_literal: true
source 'http://rubygems.org'
gem 'activemerchant'
gem 'acts_as_publishable'
gem 'authlogic'
gem 'awesome_print'
gem 'aws-sdk', '~> 2.0'
gem 'bootsnap', require: false
gem 'declarative_authorization', git: 'https://github.com/xymist/declarative_authorization.git', branch: 'allow_rails_5'
gem 'dynamic_form'
gem 'easy_roles'
gem 'haml', '>= 3.1.alpha.50'
gem 'json' # , '~> 1.8.6'
gem 'money', '2.1.0'
gem 'mysql2'
gem 'paperclip', '~> 5.3.0'
gem 'protected_attributes'
gem 'pry-rails'
gem 'rabl', '0.14.1'
gem 'rack-ssl-enforcer'
gem 'rails', '~> 4.2.11.1'
gem 'rb-inotify', require: false
gem 'responders', '~> 2.0'
gem 'savon', '~> 2.0'
gem 'sprockets'
gem 'squeel'
gem 'will_paginate'
gem 'workflow', '~> 1.2'
gem 'xml-simple'
gem 'yui-compressor'
gem 'zip-zip'
# Commented out while converting to pipeline
# gem 'jammit'
gem 'config'
gem 'oauth-plugin', '>= 0.4.0.pre1'
gem 'openssl-extensions', require: 'openssl-extensions/all'
gem 'radix62'
gem 'simpleidn'
gem 'uuidtools'
gem 'whenever', require: false
# gem "therubyracer", '~> 0.12.3', platform: :ruby
gem 'actionpack-action_caching', '~> 1.1', '>= 1.1.1'
gem 'airbrake', '~> 9.5' # https://airbrake.io/docs/ruby/upgrading-your-notifier/
gem 'api-pagination'
gem 'attr_encrypted', '>= 3.0.3'
gem 'bootstrap'
gem 'cancan'
gem 'coffee-rails'
gem 'compass-rails'
gem 'daemons'
gem 'dalli'
gem 'dalli-elasticache'
gem 'delayed-web'
gem 'delayed_job_active_record'
gem 'delayed_job_groups_plugin'
gem 'jbuilder'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'json-schema'
gem 'jsonapi-serializers'
gem 'libv8'
gem 'mini_racer', platforms: :ruby
gem 'nokogiri', '>= 1.10.4'
gem 'popper_js', '~> 1.11.1'
gem 'public_suffix', '>= 4.0.0'
gem 'rack-cors', '>= 0.4.1', require: 'rack/cors'
gem 'rails-api'
gem 'rails-observers'
gem 'request_exception_handler'
gem 'rubyzip', '>= 1.3.0'
gem 'rvm-capistrano'
gem 'sass-rails'
gem 'sdoc', group: :doc
gem 'select2-rails'
gem 'stripe'
gem 'turbolinks'
gem 'unscoped_associations'
# gem 'wkhtmltopdf-binary' see config/initializers/wicked_pdf.rb for installation instructions
gem 'duo_web', '~> 1.0'
gem 'u2f'
gem 'wicked_pdf'
# gem 'simple_captcha2', require: 'simple_captcha'
gem 'acts_as_tree'
gem 'font-awesome-rails'
gem 'recaptcha', require: 'recaptcha/rails'
gem 'where-or'
gem 'whois', '~> 4.0'
gem 'whois-parser'
# gem "skylight"
gem 'authy'
gem 'mailboxer'
gem 'memoist'
# gem 'countries'
gem 'bootstrap-datepicker-rails'
gem 'timezone', '~> 1.0'
# required by sws-a1
gem 'activerecord-import'
gem 'date'
gem 'etc'
gem 'fileutils', '~> 1.1.0'
gem 'forwardable'
gem 'scout_apm'
gem 'stringio'
gem 'strscan'
gem 'zlib'
group :development do
gem 'annotate'
gem 'better_errors'
gem 'binding_of_caller'
gem 'bullet'
gem 'dotenv-rails'
gem 'letter_opener_web', '~> 1.0'
gem 'memory_profiler'
gem 'meta_request'
gem 'spring'
gem 'spring-commands-testunit'
gem 'web-console', '~> 2.0'
# Linting
gem 'rubocop', require: false
gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'solargraph', require: false
end
group :development, :test do
gem 'builder'
gem 'byebug'
gem 'factory_bot_rails'
gem 'pry-byebug'
gem 'pry-remote'
gem 'ruby-odbc'
gem 'ruby_parser'
gem 'rspec-rails'
end
group :test do
gem 'database_cleaner'
gem 'faker'
gem 'mocha'
gem 'simplecov', require: false
gem 'vcr'
gem 'webmock'
end
gem 'foreman'
gem 'httparty'
gem 'swagger-blocks'
gem 'swagger-docs'
gem 'uglifier', '4.1.8'
gem 'rswag-ui'
gem 'bcrypt_pbkdf', '~> 1'
gem 'ed25519', '~> 1.2'
SslCom::Application.configure do
MIGRATING_FROM_LEGACY = false
# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = {host: 'localhost:3000'}
config.after_initialize do
Rails.application.routes.default_url_options = {host: 'localhost:3000'}
end
config.force_ssl = false
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Sort the order test cases are executed.
config.active_support.test_order = :sorted
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
ActiveMerchant::Billing::Base.mode = :test
config.eager_load=false
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
#config.log_level = Logger::INFO
GATEWAY_TEST_CODE=1.0
# END ActiveMerchant configuration
end
#require "#{Rails.root}/lib/firewatir_url.rb"
最佳答案
我的猜测是 RAILS_ENV
环境变量设置为除 test
以外的其他值当您运行 rspec
时命令。我以前在一些具有 RAILS_ENV
的机器上遇到过这种情况。环境变量显式设置为 development
或其他完全不同的东西(就像其他人提到的那样会导致您看到的问题,因为该值缺少环境文件)。
在您的 rails_helper.rb
文件,尝试更改这一行:
ENV['RAILS_ENV'] ||= 'test'
ENV['RAILS_ENV'] = 'test'
RAILS_ENV
的位置。手动设置(通常在 shell 配置文件中)并删除它,或复制您的
config/environments/test.rb
文件到新文件以匹配任何内容
RAILS_ENV
被设定为。
关于ruby-on-rails - 将 MiniTest 迁移到 RSpec 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59182426/
我最近开始从事一个 Sails 项目。它目前在迁移表下具有以下格式的迁移。 20160826122004-create_users_table.js 'use strict'; module.expo
当我尝试迁移时 doctrine:migrations:migrate ,我收到此异常:“元数据存储不是最新的,请运行 sync-metadata-storage 命令来解决此问题。”。这仅在尝试在生
我在 ec2 linux 7 上有一个 MarkLogic 服务器。我想将它迁移到 linux 6。我将 ebs 移动到新的 linux 6 并将其安装在 /var/opt/MarkLogic . 我
我对 OpenID 很好奇。虽然我同意统一凭证的想法很棒,但我有一些保留意见。什么是防止 OpenID 提供商发疯并持有他们拥有的 OpenID 帐户直到您支付 n 美元?如果我决定不喜欢这个提供商,
使用 SQL 很容易做到这一点,但我需要编写一个我不熟悉的 Knex 迁移脚本。以下代码在 order 表中行的末尾添加了 order_id 列。我想在 id 之后添加 order_id。我该怎么做?
使用 SQL 很容易做到这一点,但我需要编写一个我不熟悉的 Knex 迁移脚本。以下代码在 order 表中行的末尾添加了 order_id 列。我想在 id 之后添加 order_id。我该怎么做?
我想通过在 Yii2 中的迁移添加一个新列,使用以下代码: public function up() { $this->addColumn('news', 'priority', $this-
我正在尝试在 SQLDelight 的表中添加更多列。我做了一个迁移文件 1.sqm .在迁移文件中,它给出了找不到表的错误。 我的 build.gradle.kts: sqldelight {
我有一个与 Flyway DB 迁移相关的问题。通常如何管理处理相同 DB 模式的多个项目(微服务)。每个项目中的 Flyway 迁移脚本如果被其他项目修改,则不允许启动。他们是否有任何文档或最佳实践
我是 Laravel 的新手。我做了一份待办事项申请作为一项学校作业。我们必须使用迁移来创建我们的数据库。 我使用迁移创建了 2 个表。我的问题是:如果你第一次在你的电脑上运行这个项目,有没有办法自动
我正在尝试在 Laravel 中创建外键,但是当我使用 artisan 迁移表时,出现以下错误: [Illuminate\Database\QueryException] SQLSTATE[HY000
我从 Django 1.7 升级到 Django 1.9。我有多次迁移。升级后我无法再创建新的数据库。 问题是“django manage.py migrate”运行检查。检查导入应用程序 URL。这
我在创建数据迁移方面遇到了困难。我的应用程序使用两个数据库。我在 settings.py 中配置了数据库,并创建了一个像 Django docs 中一样的路由器. # settings.py DB_H
我有一个像这样的sql结构: CREATE TABLE resources ( id SERIAL PRIMARY KEY, title TEXT NOT NULL, created_at
我正在尝试使用模式构建器向表添加枚举选项(不丢失当前数据集)。 我真正能够找到的关于列更改的唯一信息是 http://www.flipflops.org/2013/05/25/modify-an-ex
我尝试转移到一些 CMake 程序中,并且有一个从 xml 生成头文件的函数。 生成文件.am adaptor_glue.hpp: dbus_introspect.xml $(DBUSXX_X
我想将文件移至我的 iOS 应用程序的 CoreData 存储 ../Library/Application Support/MyApp/ 至 ../Documents/Stores/ 我可以使用 N
有没有人对数据迁移进出 NetSuite 有丰富的经验?我必须将 DB2 表导出到 MySQL,处理数据,然后导出到一个 CSV 文件中。然后获取帐户的 CSV 文件并再次操作数据以使帐户从我们的旧系
我正在尝试在 Django 上建立一个博客。我已经走到了创建模型的地步。他们在这里: from django.db import models import uuid class Users(mode
我最近使用 bluehost 上的 AutoSSL 工具将网站迁移到 HTTPS。我在内容中看到一些失真,例如缺少背景颜色、表格位移、缺少_logos 等。 有谁知道 HTTPS 迁移效果如何影响样式
我是一名优秀的程序员,十分优秀!