【问题标题】:shoulda gem allow_value method应该 gem allow_value 方法
【发布时间】:2013-04-02 12:16:48
【问题描述】:

old_spec.rb

it { should allow_value(:nil).for(:invoice_type) }
it { should allow_value(:customer_invoice).for(:invoice_type) }
it { should allow_value(:creative_invoice).for(:invoice_type) }
it { should_not allow_value(:other).for(:invoice_type) }

我的规范文件中有这些代码,我将它们转换如下。

new_spec.rb

   it { should ensure_inclusion_of(:invoice_type).in_array(
     [:nil,:customer_invoice,:creative_invoice]) }

我想知道在第二个文件(new_spec.rb)中我是否必须写下这一行。

it { should_not allow_value(:other).for(:invoice_type) }

【问题讨论】:

    标签: ruby-on-rails rspec shoulda


    【解决方案1】:

    根据ensure_inclusion_of 工作原理的描述,您不需要明确阻止其他值。

    当然,你自己检查一下会很容易......

    【讨论】:

      猜你喜欢
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多