我无法通过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/