0

我正在尝试测试与 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, ********]

有人可以解释一下,为什么?谢谢

4

1 回答 1

0

看起来您的数据库没有在每个规范之间重置。你在用database_cleaner吗?

于 2013-05-26T08:11:47.140 回答