【问题标题】:Shoulda Matchers: undefined method `is_at_least' for :last_name:Symbol应该匹配器:未定义的方法`is_at_least' for :last_name:Symbol
【发布时间】:2015-09-22 16:38:04
【问题描述】:

我正在尝试验证 first_name 的长度:

 it { should ensure_length_of (:first_name).is_at_least(2)}

但得到错误:

应该匹配器:用于 :last_name:Symbol 的未定义方法 `is_at_least'

在这种情况下,我在文档中找不到太多关于正确语法的信息。

【问题讨论】:

  • 错误发生在哪一行?请发布该代码

标签: ruby-on-rails testing shoulda


【解决方案1】:

空格很重要!方法及其参数之间不应有空格。

it { should ensure_length_of(:first_name).is_at_least(2)}

你所拥有的被解释为:

it { should ensure_length_of( (:first_name).is_at_least(2) )}

【讨论】:

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