Rspec测试与expect change语法的关联

Rspec测试与expect change语法的关联,rspec,associations,Rspec,Associations,我正在尝试测试与rspec的一些关联。 这是我的测试: (一) (二) 这是apply\u startup方法的定义: def apply_startup startup = Startup.find_by_id params[:startup][:id] @incubator.pending_startups << startup if startup redirect_to incubator_path(@incubator) end def应用_启动 startu

我正在尝试测试与rspec的一些关联。 这是我的测试:

(一)

(二)

这是
apply\u startup
方法的定义:

def apply_startup
  startup = Startup.find_by_id params[:startup][:id]
  @incubator.pending_startups << startup if startup
  redirect_to incubator_path(@incubator)
end
def应用_启动
startup=startup.find_by_id params[:startup][:id]

@孵化器.pending_startups看起来您的数据库没有在每个规范之间重置。您是否使用
数据库\u cleaner

RSpec关于第二次测试失败的完整输出是什么?抱歉,刚刚更新了一个问题。
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
def apply_startup
  startup = Startup.find_by_id params[:startup][:id]
  @incubator.pending_startups << startup if startup
  redirect_to incubator_path(@incubator)
end
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, ********]