gpt4 book ai didi

ruby-on-rails - 无法运行 Minitest - 在 MiniTest::Unit::TestCase 中获取未定义的类变量

转载 作者:行者123 更新时间:2023-12-02 03:40:33 26 4
gpt4 key购买 nike

我正在尝试启动并运行我的模型测试,但我的终端出现错误

rake aborted!
uninitialized class variable @@current in MiniTest::Unit::TestCase

这是我的 gem :

gem 'faker'

group :development, :test do
gem 'byebug'
gem 'minitest-spec-rails'
gem 'minitest-rails'
gem 'minitest-rails-capybara'
gem 'minitest-colorize'
gem 'minitest-focus'
gem 'fabrication'
gem 'capybara'
gem 'rspec-rails', '~> 2.0'
end

这里是我的 user_test.rb 文件:

require "test_helper"

class UserTest < ActiveSupport::TestCase

it "should create a user" do
@user = User.create!(:email => "user@gmail.com", :password => "xxxxxxxx", :password_confirmation => "xxxxxxxx")
end

describe "should have a unique username" do
@user1 = Fabricate(:user, username: "bficho")
@user2 = Fabricate.build(:user, username: "bficho")
@user2.valid?.must_equal false
end

end

这让我抓狂,因为在我的测试工作之前我不能做太多事情!还有其他人看到这个吗??

最佳答案

像这样更改您的测试:(根据 this )

require "test_helper"
require 'minitest/autorun'

describe MiniTest::Spec
it "should create a user" do
@user = User.create!(:email => "user@gmail.com", :password => "xxxxxxxx", :password_confirmation => "xxxxxxxx")
end

it "should have a unique username" do
@user1 = Fabricate(:user, username: "bficho")
@user2 = Fabricate.build(:user, username: "bficho")
@user2.valid?.must_equal false
end
end

我认为在您的情况下,将第二个测试用例从 describe 更改为 it 可能有效

describe "should have a unique username" do

应该改为

it "should have a unique username" do

关于ruby-on-rails - 无法运行 Minitest - 在 MiniTest::Unit::TestCase 中获取未定义的类变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20362189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com