gpt4 book ai didi

ruby - 单元测试中应该父类(super class)不匹配

转载 作者:数据小太阳 更新时间:2023-10-29 07:31:01 25 4
gpt4 key购买 nike

尝试使用 shoulda 和 rails 3 编写一个简单的单元测试。

test/unit/user_test.rb

class UserTest < Test::Unit::TestCase
should validate_presence_of(:password, :on => :create)
should validate_presence_of(:handle, :email)
should validate_confirmation_of(:password)
should validate_length_of(:handle, :within => 6..15)
should validate_uniqueness_of(:handle)
should validate_format_of(:handle, :with => /\A\w+\z/i)
should validate_length_of(:email, :within => 6..100)
end

Gemfile的相关部分

group :test do
gem 'shoulda'
gem 'rspec-rails', '2.0.0.beta.12'
end

当我尝试使用 rake test --trace 运行它时,我收到以下错误:

** Execute test:units
/Users/removed/removed/removed/app_name/test/unit/user_test.rb:5: superclass mismatch for class UserTest (TypeError)
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:227:in `load_dependency'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:239:in `require'
from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:9
from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:9:in `each'
from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:9
from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:5:in `each'
from /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/rake_test_loader.rb:5

我理解这个错误,我只是不知道在哪里定义了另一个 UserTest 类,这给了我这个问题。有什么想法吗?

迈克

最佳答案

检查 find 的输出。 | xargs grep -l UserTest 防止意外重复使用类名。

关于ruby - 单元测试中应该父类(super class)不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6497260/

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