应该是rspec匹配ensure_inclusion_of

时间:2013-03-23 21:28:39

标签: ruby-on-rails-3 testing rspec shoulda

我使用了由于我不理解的原因而失败的测试。知道这个解决方案是什么吗?我为了测试目的对数组进行了硬编码。

我所有其他基于匹配的测试都运行正常。

验证

validates_inclusion_of :status, :in => ["Active", "Closed"]

测试:

it { should ensure_inclusion_of(:status).in_array(["Active", "Closed"]) }

失败

Failure/Error: it { should ensure_inclusion_of(:status).in_array(["Active", "Closed"]) }
   ["Active", "Closed"] doesn't match array in validation

1 个答案:

答案 0 :(得分:3)

查看该匹配器的源代码:

https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb#L88

您是否有其他验证可以阻止:status

的空值或空值?