There is a Company
class that has_many
QuarterValue
, and I have a RSpec test for it.
let(:company) { Company.create }
describe 'company has many quarter values' do
before do
10.times { create(:quarter_value, company: company) }
end
it 'has 10 quarter values' do
expect(company.quarter_values.count).to eq(10)
end
end
The test passes. My question is when I put binding.pry
just above the expect
matcher I can't access company.quarter_values
, that returns empty array []
.
How can I access has_many
models object in RSpec
test by using binding.pry
?
spec/factories.rb
FactoryGirl.define do
factory :company do
sequence(:code) { |n| n + 1000 }
end
factory :quarter_value do
company
end
end
company.reload
? – Institutivecompany.quarter_values
it returns all 10 records ... not an empty array. which is expected but doesn't jive with what you're saying. – Arthromere