0
我試圖用rspec測試一些關聯。 這是我的測試:Rspec測試與期望更改語法的關聯
1)
it 'creates an incubation with proper associations' do
expect{post :apply_startup, id: incubator.id, startup: {id: startup.id}}
.to change{incubator.pending_startups.count}.from(0).to(1)
end
2)
it 'creates an incubation with proper associations' do
expect{post :apply_startup, id: incubator.id, startup: {id: startup.id}}
.to change{incubator.pending_startups}.from([]).to([startup])
end
這是apply_startup
方法的定義:
def apply_startup
startup = Startup.find_by_id params[:startup][:id]
@incubator.pending_startups << startup if startup
redirect_to incubator_path(@incubator)
end
首先測試通過,但是第二失敗。
編輯#1(失敗規格的輸出)
2) IncubatorsController#apply creates an incubation with proper associations
Failure/Error: expect{post :apply, id: incubator.id, startup: {id: startup.id}}
result should have initially been [], but was [#<Startup id: 665, ********]
有人能解釋一下,爲什麼? Thanx
RSpec關於第二次測試失敗的完整輸出是什麼? –
對不起,剛更新了一個問題。 – RunFor