gpt4 book ai didi

ruby-on-rails - RSpec 测试失败,方法未定义 `validate_uniqueness_of'

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

使用 Rails 5 和 RSpec 3.5,我收到以下错误。

  1) User
Failure/Error: it { should validate_uniqueness_of(:auth_token)}

NoMethodError:
undefined method `validate_uniqueness_of' for #<RSpec::ExampleGroups::User:0x007fab919f8cf
8>
# ./spec/models/user_spec.rb:14:in `block (2 levels) in <top (required)>'

我用谷歌搜索了正确的语法,但找不到解决方案。有谁知道在这里使用什么?谢谢

最佳答案

您必须将 gem 添加到 Gemfile 中:

gem 文件

group :test do
gem 'shoulda-matchers'
end

并包含它:

spec/rails_helper.rb

RSpec.configure do |config|
config.include(Shoulda::Matchers::ActiveModel, type: :model)
config.include(Shoulda::Matchers::ActiveRecord, type: :model)
end

关于ruby-on-rails - RSpec 测试失败,方法未定义 `validate_uniqueness_of',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41027391/

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