lcg*_*ida 5 ruby rspec ruby-on-rails
我在我的 Rails 应用程序中安装了 rspec 配置。它工作得很好(我们只是在尝试 rspec,所以只有 2 个测试)。
他们工作得很好。现在,当 rspec 要使用数据库执行测试时,它会冻结。
我只是冻结了。我什至不知道要开始查找,因为输出中没有错误。
rspec 是否有详细或调试模式,或者有人遇到过这种情况吗?
我已经尝试过 -b 但它会在出现错误之前冻结。
输出:(Rspec 配置有 --format 文档)
[leandro@machine:~] rspec
User
Run Code Online (Sandbox Code Playgroud)
比,就是这样。它挂了。我必须手动重置计算机两次。
这是 user_spec.rb
require 'spec_helper'
describe User do
let(:user) { User.create({
username: "teste",
email: "teste@teste.com",
name: "Teste",
phone: "123456789",
password: "123456",
notes: "Teste"
}) }
subject { user }
it "is invalid without a username" do
user.username = nil
is_expected.not_to be_valid
end
end
Run Code Online (Sandbox Code Playgroud)
还有我的spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.color = true
config.tty = true
config.formatter = :documentation #:progress, :html, :textmate
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
Run Code Online (Sandbox Code Playgroud)
解决方案
事实证明,delayed_job_active_record宝石是导致悬挂的原因。
我不知道为什么,但作为@Greg Malcolm,我调查了log/teste.logrspec 在创建延迟作业数据库并设置新用户后立即感到惊讶。
我将 gem 限制为仅用于开发和生产环境,并且它有效!
我还没有听说过 rspec 的类似 rake 的详细功能。log/test.log但仔细查看并查看那里显示的内容可能更有用。它显示数据库活动,这是冻结效果的一部分。
您可能还想rails console进行测试并确保您的数据库连接正常工作。
| 归档时间: |
|
| 查看次数: |
9403 次 |
| 最近记录: |