gpt4 book ai didi

rspec - Rspec模型关联

转载 作者:行者123 更新时间:2023-12-02 03:57:36 24 4
gpt4 key购买 nike

我无法通过RSpec测试

规格/型号/ticket_spec.rb

describe Ticket do
describe "should have associations" do
it { should belong_to(:location) }

重击
  1) Ticket should have associations 
Failure/Error: it { should belong_to(:location) }
NoMethodError:
undefined method `relations' for #<Class:0x000000076a34a0>
# ./spec/models/ticket_spec.rb:5:in `block (3 levels) in <top (required)>'

型号/ticket.rb
class Ticket < ActiveRecord::Base 
...
belongs_to :location

gem 文件
group :test do
...
gem "shoulda"
gem "shoulda-matchers"
end

最佳答案

如果您正在使用主题功能,则应定义该主题:

before { @ticket = ... }
subject { @ticket }

然后您可以将其用作:
it { should belong_to(:location) }

关于rspec - Rspec模型关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11885314/

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