我在Rspec寫了一些測試,並試圖通過has_and_belongs_to_many
關聯將carrier
推送到user
。以下是我寫的測試,但是我用箭頭表示的行似乎沒有通過。我意識到我嘲笑了運營商,但不是用戶,我想知道這是否導致HABTM協會的問題。這是問題還是有什麼我失蹤?我是新來的嘲笑和磕頭,但盡我所能!Rspec:我如何測試陣列推送?
describe UsersController do
describe 'get #add_carrier' do
let(:user) { build(:approved_user) }
let(:carrier) { mock_model(Carrier).as_null_object }
before{ Carrier.stub(:find).and_return(carrier) }
it 'associates the Carrier to the User' do
expect(user.carriers).to eq []
user.should_receive(:carriers).and_return([])
--> (user.carriers).should_receive(:push).with(carrier).and_return([carrier])
(user.carriers).push(carrier)
(user.carriers).should include carrier
end
end
end