0

(提及shoulda是因为我知道它在 Gemfile 中 - 但不知道它如何影响 rspec 测试,没有经验,不知道它是否参与其中)

我有两个 [控制器] 测试:

第一的:

它{应该assign_to(:messages).with(current_user.messages.ordered.decorate)}

第二:

它 { 应该 assign_to( :messages ).with( current_user.messages.order("send_at DESC").decorate ) }

注意: message.rb 定义:

scope :ordered,     order( 'messages.send_at DESC' )

,所以他们正在测试完全相同的东西 - 除了ordered用于按错误字段排序的方法,并且第一个测试总是会通过,预期的集合与实际的集合相同;因此第二个测试明确要求正确的排序顺序。

现在,疯狂:第一次测试通过,第二次测试失败。Rspec 打印:

 Expected action to assign #<DecoratedEnumerableProxy of
 MessageDecorator for [#<Message id: 1, ... >, <Message id: 2, ...>]>,
 but got #<DecoratedEnumerableProxy of MessageDecorator for [#<Message
 id: 1, ... >, <Message id: 2, ...>]>

你猜对了——这里打印的“预期..”和“但得到..”部分完全相同。我已经用 diff 对它们进行了三重检查。如果两个测试都失败了,我不会那么困惑,但是第一个通过,第二个失败。我怀疑第一个测试一定会产生某种副作用,但是不,重新排序或注释掉其中一个测试不会改变任何东西。

有任何想法吗?

4

0 回答 0