Reputation: 3216
I cann't pass rspec test
spec/models/ticket_spec.rb
describe Ticket do
describe "should have associations" do
it { should belong_to(:location) }
bash
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)>'
models/ticket.rb
class Ticket < ActiveRecord::Base
...
belongs_to :location
Gemfile
group :test do
...
gem "shoulda"
gem "shoulda-matchers"
end
Upvotes: 3
Views: 685
Reputation: 21791
If you're using subject feature, you should define that subject:
before { @ticket = ... }
subject { @ticket }
and then you can use it as:
it { should belong_to(:location) }
Upvotes: 1