3

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

宝石文件

group :test do
  ...
  gem "shoulda"
  gem "shoulda-matchers"
end
4

1 回答 1

1

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

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

然后您可以将其用作:

it { should belong_to(:location) }
于 2012-08-09T14:26:19.077 回答