【问题标题】:Shoulda rspec matchers ensure_inclusion_of应该 rspec 匹配器 ensure_inclusion_of
【发布时间】:2013-03-23 21:28:39
【问题描述】:

我有一个使用 shoulda 的测试,但由于我不明白的原因而失败。知道解决方法是什么吗?出于测试目的,我对数组进行了硬编码。

我所有其他基于 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

【问题讨论】:

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


    【解决方案1】:

    查看该匹配器的源代码:

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

    您是否还有其他验证可以防止 :status 出现 nil 或空白值?

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多